Module: Zaikio::Client

Defined in:
lib/zaikio/client.rb,
lib/zaikio/client/model.rb,
lib/zaikio/client/helpers/version.rb,
lib/zaikio/client/helpers/configuration.rb,
lib/zaikio/client/helpers/locale_middleware.rb,
lib/zaikio/client/helpers/authorization_middleware.rb

Defined Under Namespace

Modules: Helpers Classes: Model

Class Method Summary collapse

Class Method Details

.create_connection(configuration) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zaikio/client.rb', line 19

def create_connection(configuration)
  Faraday.new(url: configuration.host,
                                ssl: { verify: configuration.environment != :test }) do |c|
    c.options.read_timeout = 5
    c.options.open_timeout = 1
    c.request     :json
    c.response    :logger, configuration&.logger, headers: false
    c.use         Zaikio::Client::Helpers::Pagination::FaradayMiddleware
    c.use         Zaikio::Client::Helpers::JSONParser
    c.use         Zaikio::Client::Helpers::AuthorizationMiddleware
    c.use         Zaikio::Client::Helpers::LocaleMiddleware, disable_i18n: configuration.disable_i18n
    c.adapter     Faraday.default_adapter
  end
end

.with_token(token) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/zaikio/client.rb', line 11

def with_token(token)
  original_token = Helpers::AuthorizationMiddleware.token
  Helpers::AuthorizationMiddleware.token = token
  yield
ensure
  Helpers::AuthorizationMiddleware.token = original_token
end