Class: BundleUp::Unify::Base
- Inherits:
-
Object
- Object
- BundleUp::Unify::Base
- Defined in:
- lib/bundleup/unify/base.rb,
sig/bundleup/unify/base.rbs
Overview
Base class for Unify API clients.
Constant Summary collapse
- BASE_URL =
'https://unify.bundleup.io'- API_VERSION =
'v1'
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
Returns the value of attribute api_key.
-
#connection_id ⇒ String
readonly
Returns the value of attribute connection_id.
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Memoize the Faraday connection to reuse it across requests.
-
#initialize(api_key, connection_id) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(api_key, connection_id) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/bundleup/unify/base.rb', line 12 def initialize(api_key, connection_id) @api_key = api_key @connection_id = connection_id end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/bundleup/unify/base.rb', line 10 def api_key @api_key end |
#connection_id ⇒ String (readonly)
Returns the value of attribute connection_id.
10 11 12 |
# File 'lib/bundleup/unify/base.rb', line 10 def connection_id @connection_id end |
Instance Method Details
#connection ⇒ Faraday::Connection
Memoize the Faraday connection to reuse it across requests
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bundleup/unify/base.rb', line 20 def connection @connection ||= Faraday.new(url: "#{BASE_URL}/#{API_VERSION}/") do |faraday| faraday.headers = { 'Authorization' => "Bearer #{@api_key}", 'Content-Type' => 'application/json', 'BU-Connection-Id' => @connection_id } faraday.request :json faraday.response :json, content_type: /\bjson$/ faraday.response :raise_error faraday.adapter Faraday.default_adapter end end |