Sha256: 6a47ed6b462997c61cb0962e8ac417f93aeb86fc8f5d35f57aadef9439d51ae7

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require 'faraday'
require 'capgun/core_ext/hash'
require 'capgun/request/gateway'
require 'capgun/response/parse_json'
require 'capgun/response/raise_client_error'
require 'capgun/response/raise_server_error'

module Capgun
  module Connection
  private

    # Returns a Faraday::Connection object
    #
    # @param options [Hash] A hash of options
    # @return [Faraday::Connection]
    def connection(options={})
      default_options = {
        :headers => {
          :accept => 'application/json',
          :user_agent => user_agent,
          :authorization => auth_token,
        },
        :proxy => proxy,
        :ssl => {:verify => false},
        :url => options.fetch(:endpoint, endpoint),
      }
      @connection ||=Faraday.new(default_options.deep_merge(connection_options)) do |builder|
        builder.use Capgun::Request::Gateway, gateway if gateway
        builder.use Capgun::Response::RaiseClientError
        builder.use Capgun::Response::ParseJson
        builder.use Capgun::Response::RaiseServerError
        builder.adapter(adapter)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
capgun-0.2.0 lib/capgun/connection.rb
capgun-0.1.2 lib/capgun/connection.rb
capgun-0.1.1 lib/capgun/connection.rb
capgun-0.1.0 lib/capgun/connection.rb
capgun-0.0.3 lib/capgun/connection.rb