Module: Eloquant::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#init_connectionObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/eloquant/concerns/connection.rb', line 15

def init_connection
  Faraday.new(url: @host) do |conn|
    conn.request :multipart
    conn.request :url_encoded

    conn.request :retry, max: 10, interval: 0.05,
      interval_randomness: 0.5, backoff_factor: 2,
      exceptions: [Errno::ETIMEDOUT, "Timeout::Error",
                  ::Faraday::Error::TimeoutError,
                  ::Faraday::ConnectionFailed]

    conn.response :logger, @logger if @debug && @logger
    conn.response :eloquant, 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 Faraday.default_adapter
  end
end

#reload_connectionObject



11
12
13
# File 'lib/eloquant/concerns/connection.rb', line 11

def reload_connection
  @connection = init_connection
end