Lokalise APIv2 Ruby SDK

Ruby interface for the Lokalise APIv2 that represents returned data as Ruby objects.

View the Project on GitHub lokalise/ruby-lokalise-api




Customization

Setting Timeouts

Request timeouts may be adjusted during client initialization:

# The same approach will work with the `.oauth2_client` method:

@client = RubyLokaliseApi.client('YOUR_TOKEN', open_timeout: 100, timeout: 500)
@client.open_timeout # => 100
@client.timeout # => 500

Both values are in seconds. They can be adjusted later with simple accessors:

@client.open_timeout = 200
@client.timeout = 600
@client.open_timeout # => 200
@client.timeout # => 600

Customizing JSON parser

By default we are using a built-in JSON module but you may utilize any other parser by overriding the #custom_dump and #custom_load methods inside the RubyLokaliseApi::JsonHandler module.

For example, to use Oj you would do the following:

require 'oj'

module RubyLokaliseApi
  module JsonHandler
    # This method accepts a Ruby object and must return a JSON string
    def custom_dump(obj)
      Oj.dump obj
    end

    # This method accepts JSON and must return Ruby object
    def custom_load(obj)
      Oj.load obj
    end
  end
end

Choosing Network Adapter

This library utilizes Faraday to perform requests. The default adapter is built-in Net::HTTP but you may customize it as needed.

For example, to use Excon:

require 'excon' # somewhere in your code
Faraday.default_adapter = :excon

Please note that since the release of Faraday 2, most adapters have to be added manually. Find all supported adapters on Faraday official website.

Configuring API host

By default, API requests are sent to the https://api.lokalise.com/api2/ URL that acts as a host.

OAuth 2 authentication requests are sent to https://app.lokalise.com.

To override the API host, use the following approach (works for all client types):

@client = RubyLokaliseApi.client('LOKALISE_API_TOKEN', api_host: 'http://example.com/api')

Then use your @client as usual.