Sha256: bbdf5124ebab028045bf00d9d9fafcadfa865babb4b252156544241be640fa9e

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

require 'faraday_middleware'
require 'faraday/request/gateway'
require 'faraday/response/fullcontact_errors'
require 'faraday/response/add_headers'
require 'faraday/response/rubyize'
require 'faraday_middleware/response/mashify'


module FullContact
  # @private
  module Connection
    private

    def connection(raw=false, faraday_options={})
      options = {
          :headers => {'Accept' => "application/#{format}", 'User-Agent' => user_agent},
          :proxy => proxy,
          :ssl => {:verify => false},
          :url => api_endpoint,
      }.merge(faraday_options)

      Faraday.new(options) do |builder|
        builder.use Faraday::Request::UrlEncoded
        builder.use Faraday::Request::Gateway, gateway if gateway
        builder.use FaradayMiddleware::Mashify unless raw
        builder.use Faraday::Response::AddHeaders if FullContact.include_headers_in_response
        builder.use Faraday::Response::Rubyize unless raw or FullContact.skip_rubyize
        unless raw
          case format.to_s.downcase
            when 'json'
              builder.use Faraday::Response::ParseJson
          end
        end
        builder.use Faraday::Response::FullContactErrors
        builder.adapter Faraday.default_adapter
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
fullcontact-api-ruby-0.1.0 lib/fullcontact/connection.rb
fullcontact-0.18.0 lib/fullcontact/connection.rb
fullcontact-0.17.0 lib/fullcontact/connection.rb
fullcontact-0.16.0 lib/fullcontact/connection.rb
fullcontact-0.15.0 lib/fullcontact/connection.rb
fullcontact-0.14.0 lib/fullcontact/connection.rb
fullcontact-0.13.0 lib/fullcontact/connection.rb
fullcontact-0.12.0 lib/fullcontact/connection.rb