Module: Footrest::Connection
- Included in:
- Client
- Defined in:
- lib/footrest/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
11 12 13 |
# File 'lib/footrest/connection.rb', line 11 def connection @connection end |
Instance Method Details
#set_connection(config) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/footrest/connection.rb', line 13 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] logger = config[:logger] == true ? nil : config[:logger] faraday.response :logger, logger do |formatter| # Keep bearer tokens out of the logs. Faraday logs request headers # by default, and dump_headers lives on the formatter in both 1.x # and 2.x, so filter here rather than monkeypatching the logger. formatter.filter(/(Authorization:\s*).*/i, '\1[FILTERED]') end end 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" faraday.adapter Faraday.default_adapter end end |