Sha256: 54b4e0ecf24d23d09eed4ccfcbd214654f1ad7bcbd775f9b81589d02c132ca2c

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'faraday'
require 'faraday_middleware'
require 'faraday/response/raise_footrest_http_error'

module Footrest
  module Connection

    attr_reader :connection

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
footrest-0.1.3 lib/footrest/connection.rb
footrest-0.1.2 lib/footrest/connection.rb