Module: Mrkt::Connection

Included in:
Client
Defined in:
lib/mrkt/concerns/connection.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject


5
6
7
# File 'lib/mrkt/concerns/connection.rb', line 5

def connection
  @connection ||= init_connection
end

#init_connectionObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mrkt/concerns/connection.rb', line 9

def init_connection
  ::Faraday.new(options) do |conn|
    conn.request :multipart
    conn.request :url_encoded

    conn.response :logger, @logger, (@log_options || {}) if @debug
    conn.response :mkto, content_type: /\bjson$/

    conn.options.timeout = @options[:read_timeout] if @options.key?(:read_timeout)
    conn.options.open_timeout = @options[:open_timeout] if @options.key?(:open_timeout)

    conn.adapter @options.fetch(:adapter, ::Faraday.default_adapter)
  end
end

#optionsObject


24
25
26
27
28
29
30
31
# File 'lib/mrkt/concerns/connection.rb', line 24

def options
  {
    url: "https://#{@host}",
    request: {
      params_encoder: Mrkt::Faraday::ParamsEncoder
    }
  }
end