Sha256: a40b1a4a259db8a7c99ca2780e3cf56181c1c3240faccafcbe1315fa0312f6d8

Contents?: true

Size: 1.59 KB

Versions: 10

Compression:

Stored size: 1.59 KB

Contents

require 'faraday_middleware'
require 'faraday/request/phoenix'
require 'faraday/request/multipart_with_file'
require 'faraday/request/gateway'
require 'faraday/request/twitter_oauth'
require 'faraday/response/raise_http_4xx'
require 'faraday/response/raise_http_5xx'

module AngellistApi
  # @private
  module Connection
    private

    def connection(options={})
      merged_options = faraday_options.merge({
        :headers => {
          'Accept' => "application/#{format}",
          'User-Agent' => user_agent
        },
        :proxy => proxy,
        :ssl => {:verify => false},
        :url => options.fetch(:endpoint, api_endpoint)
      })
      
      Faraday.new(merged_options) do |builder|
        builder.use Faraday::Request::Phoenix if options[:phoenix]
        builder.use Faraday::Request::MultipartWithFile
        builder.use Faraday::Request::AngellistApiOAuth, authentication if authenticated?
        builder.use Faraday::Request::Multipart
        builder.use Faraday::Request::UrlEncoded
        builder.use Faraday::Request::Gateway, gateway if gateway
        builder.use Faraday::Response::RaiseHttp4xx
        unless options[:raw]
          case options.fetch(:format, format).to_s.downcase
          when 'json', 'phoenix'
            builder.use Faraday::Response::Mashify
            builder.use Faraday::Response::ParseJson
          when 'xml'
            builder.use Faraday::Response::Mashify
            builder.use Faraday::Response::ParseXml
          end
        end
        builder.use Faraday::Response::RaiseHttp5xx
        builder.adapter(adapter)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
angellist_api-0.1.0 lib/angellist_api/connection.rb
angellist_api-0.0.9 lib/angellist_api/connection.rb
angellist_api-0.0.8 lib/angellist_api/connection.rb
angellist_api-0.0.7 lib/angellist_api/connection.rb
angellist_api-0.0.6 lib/angellist_api/connection.rb
angellist_api-0.0.5 lib/angellist_api/connection.rb
angellist_api-0.0.4 lib/angellist_api/connection.rb
angellist_api-0.0.3 lib/angellist_api/connection.rb
angellist_api-0.0.2 lib/angellist_api/connection.rb
angellist_api-0.0.1 lib/angellist_api/connection.rb