Sha256: 28a5dfd96b4057dd738a00ca2190164e9e100000ad3e20d934ee434a7a6a8716

Contents?: true

Size: 903 Bytes

Versions: 4

Compression:

Stored size: 903 Bytes

Contents

module FullContact
  # Defines HTTP request methods
  module Request
    # Perform an HTTP GET request
    def get(path, options={}, raw=false, faraday_options={})
      request(:get, path, options, raw, faraday_options)
    end

    private

    # Perform an HTTP request
    def request(method, path, options, raw=false, faraday_options={})
      if FullContact.options[:auth_type] == :query
        options[:apiKey] = FullContact.options[:api_key]
      end

      response = connection(raw, faraday_options).send(method) do |request|
        request.url(formatted_path(path), options)

        if FullContact.options[:auth_type] == :header
          request.headers[FullContact::Configuration::AUTH_HEADER_NAME] = FullContact.options[:api_key]
        end
      end

      raw ? response : response.body
    end

    def formatted_path(path)
      [path, format].compact.join('.')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fullcontact-0.18.0 lib/fullcontact/request.rb
fullcontact-0.17.0 lib/fullcontact/request.rb
fullcontact-0.16.0 lib/fullcontact/request.rb
fullcontact-0.15.0 lib/fullcontact/request.rb