Sha256: fe995260405eabaf55a4fa763dbfba3d843f23fcba95fc8b078b5b21c03dc5d6

Contents?: true

Size: 816 Bytes

Versions: 5

Compression:

Stored size: 816 Bytes

Contents

require 'mrkt/faraday'

module Mrkt
  module Connection
    def connection
      @connection ||= init_connection
    end

    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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mrkt-1.2.1 lib/mrkt/concerns/connection.rb
mrkt-1.2.0 lib/mrkt/concerns/connection.rb
mrkt-1.1.1 lib/mrkt/concerns/connection.rb
mrkt-1.1.0 lib/mrkt/concerns/connection.rb
mrkt-1.0.1 lib/mrkt/concerns/connection.rb