Sha256: 6fe0cd916877cd37193040d3b95b922b80880d693eb307781a72176bce714e79

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

require 'faraday'
require 'faraday_middleware'
require 'angellist_api/core_ext/hash'
require 'angellist_api/request/multipart_with_file'
require 'angellist_api/request/gateway'
require 'angellist_api/request/angellist_api_oauth'
require 'angellist_api/response/raise_client_error'
require 'angellist_api/response/raise_server_error'

module AngellistApi
  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
        },
        :proxy => proxy,
        :ssl => {:verify => false},
        :url => options.fetch(:endpoint, api_endpoint)
      }

      @connection ||= Faraday.new(connection_options.deep_merge(default_options)) do |builder|
        builder.use AngellistApi::Request::MultipartWithFile
        builder.use AngellistApi::Request::AngellistApiOAuth, authentication if authenticated?
        builder.use Faraday::Request::Multipart
        builder.use Faraday::Request::UrlEncoded
        builder.use AngellistApi::Request::Gateway, gateway if gateway
        builder.use AngellistApi::Response::RaiseClientError
        builder.use Faraday::Response::Mashify
        builder.use Faraday::Response::ParseJson
        builder.use AngellistApi::Response::RaiseServerError
        builder.adapter(adapter)
      end

      @connection
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
angellist_api-1.1.0 lib/angellist_api/connection.rb
angellist_api-1.0.7 lib/angellist_api/connection.rb
angellist_api-1.0.6 lib/angellist_api/connection.rb
angellist_api-1.0.5 lib/angellist_api/connection.rb
angellist_api-1.0.4 lib/angellist_api/connection.rb
angellist_api-1.0.3 lib/angellist_api/connection.rb
angellist_api-1.0.2 lib/angellist_api/connection.rb