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


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

All supported adapters are listed on Faraday official website.

Setting Timeouts

Request timeouts may be adjusted during client initialization:

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

@client = Lokalise.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 Lokalise::JsonHandler module.

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

require 'oj'

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

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

Enabling compression

Lokalise API supports gzip compression but it’s off by default. If you’re working with large amounts of data it’s a good idea to enable it by setting the enable_compression option to true:

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

client = Lokalise.client('YOUR_TOKEN', enable_compression: true)

Now you can use the client as usual and the API responses will be uncompressed automatically.