Method: Unit::Connection#initialize
- Defined in:
- lib/unit-ruby/util/connection.rb
#initialize(custom_headers = {}) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/unit-ruby/util/connection.rb', line 13 def initialize(custom_headers = {}) @connection = Faraday.new(self.class.base_url) do |f| f.headers['UNIT_TRUST_TOKEN'] = self.class.trust_token if self.class.trust_token f.headers['Authorization'] = "Bearer #{self.class.api_key}" f.headers['Content-Type'] = 'application/vnd.api+json' f.headers.merge!(custom_headers) f.request :json # encode req bodies as JSON f.request :retry # retry transient failures f.response :json # decode response bodies as JSON end end |