Sha256: 590fc0d4c00e5bc8f95d41014d613d2207885a02fd2540b0fc83d2bd7e02cd34

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'faraday_middleware'
require 'faraday/request/gateway'
require 'faraday/response/fullcontact_errors'
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::Rubyize unless raw
        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

2 entries across 2 versions & 1 rubygems

Version Path
fullcontact-0.10.0 lib/fullcontact/connection.rb
fullcontact-0.9.0 lib/fullcontact/connection.rb