Skip to content

Client customizations

Ilya Krukowski edited this page Apr 10, 2022 · 1 revision

Setting timeouts

@client = RatingChgkV2.client params: {open_timeout: 100, timeout: 500}

Choosing network adapter

We use Faraday to perform requests. The default adapter is built-in Net::HTTP but you can customize it.

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.

Choosing JSON parser

By default we use a standard JSON library, but you can choose any other gem.

For example, to use Oj:

require 'oj'

module RatingChgkV2
  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

Basically, you have to redefine custom_dump and custom_load methods somewhere in your code.

Clone this wiki locally