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