Class: BundleUp::Unify::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bundleup/unify/base.rb,
sig/bundleup/unify/base.rbs

Overview

Base class for Unify API clients.

Direct Known Subclasses

CRM, Chat, Drive, Git, Ticketing

Constant Summary collapse

BASE_URL =

Returns:

  • (String)
'https://unify.bundleup.io'
API_VERSION =

Returns:

  • (String)
'v1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, connection_id) ⇒ Base

Returns a new instance of Base.

Parameters:

  • api_key (String)
  • connection_id (String)


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_keyString (readonly)

Returns the value of attribute api_key.

Returns:

  • (String)


10
11
12
# File 'lib/bundleup/unify/base.rb', line 10

def api_key
  @api_key
end

#connection_idString (readonly)

Returns the value of attribute connection_id.

Returns:

  • (String)


10
11
12
# File 'lib/bundleup/unify/base.rb', line 10

def connection_id
  @connection_id
end

Instance Method Details

#connectionFaraday::Connection

Memoize the Faraday connection to reuse it across requests

Returns:

  • (Faraday::Connection)


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