Sha256: 7a1414de87d920d4f4e75e1b5003b76d0d0e4da71fa476e5040390e7143cdaf2

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

require 'faraday'
require 'footrest/http_error'
require 'footrest/pagination'
require 'footrest/follow_redirects'
require 'footrest/parse_json'

module Footrest
  module Connection

    attr_reader :connection

    def set_connection(config)
      config[:logger] = config[:logging] if config[:logging]
      @connection = Faraday.new(url: config[:prefix]) do |faraday|
        faraday.request                     :multipart
        faraday.request                     :url_encoded
        if config[:logger] == true
          faraday.response :logger
        elsif config[:logger]
          faraday.use Faraday::Response::Logger, config[:logger]
        end
        faraday.adapter                     Faraday.default_adapter
        faraday.use                         Footrest::FollowRedirects
        faraday.use                         Footrest::ParseJson, :content_type => /\bjson$/
        faraday.use                         Footrest::RaiseFootrestErrors
        faraday.use                         Footrest::Pagination
        faraday.headers[:accept]          = "application/json"
        faraday.headers[:authorization]   = "Bearer #{config[:token]}" if config[:token]
        faraday.headers[:user_agent]      = "Footrest"
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
footrest-0.5.2 lib/footrest/connection.rb
footrest-0.5.1 lib/footrest/connection.rb
footrest-0.5.0 lib/footrest/connection.rb
footrest-0.4.1 lib/footrest/connection.rb