Module: LingutestClient::Connection::ClassMethods

Defined in:
lib/lingutest_client/connection.rb

Instance Method Summary collapse

Instance Method Details

#clientObject



8
9
10
# File 'lib/lingutest_client/connection.rb', line 8

def client
  Thread.current[:lingutest_client] ||= connection
end

#connectionObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lingutest_client/connection.rb', line 12

def connection # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  Thread.current[:lingutest_default_connection] ||=
    Faraday.new(url: LingutestClient.config.api_base) do |c|
      c.request :json
      c.response :raise_error
      c.response :json,
                 content_type: /\bjson$/,
                 parser_options: { symbolize_names: true }
      c.headers['X-Api-Token'] =
        format('Token token="%<key>s"',
               key: LingutestClient.config.api_key)
      c.headers[:user_agent] = 'Lingutest Ruby Client'
      c.headers['Content-Type'] = 'application/json'
      c.headers['Accept'] = 'application/json'
      c.adapter Faraday.default_adapter
    end
end