Module: ActiveProject::Adapters::Basecamp::Connection

Includes:
Connections::Rest
Included in:
ActiveProject::Adapters::BasecampAdapter
Defined in:
lib/active_project/adapters/basecamp/connection.rb

Constant Summary collapse

BASE_URL_TEMPLATE =
"https://3.basecampapi.com/%<account_id>s/"

Constants included from Connections::HttpClient

Connections::HttpClient::DEFAULT_HEADERS, Connections::HttpClient::DEFAULT_RETRY_OPTS

Instance Attribute Summary

Attributes included from Connections::HttpClient

#connection, #last_response

Instance Method Summary collapse

Methods included from Connections::Rest

#init_rest, #request_rest

Methods included from Connections::Pagination

#each_edge, #each_page

Methods included from Connections::HttpClient

#build_connection, #request

Methods included from Connections::Base

#parse_link_header

Instance Method Details

#initialize(config:) ⇒ Object

Initializes the Basecamp Adapter.

Parameters:

Raises:

  • (ArgumentError)

    if required configuration options (:account_id, :access_token) are missing.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_project/adapters/basecamp/connection.rb', line 12

def initialize(config:)
  # For now, Basecamp uses the base config. If specific Basecamp options are added,
  # create BasecampConfiguration and check for that type.
  unless config.is_a?(ActiveProject::Configurations::BaseAdapterConfiguration)
    raise ArgumentError, "BasecampAdapter requires a BaseAdapterConfiguration object"
  end

  super(config: config)

     = @config.options.fetch(:account_id)
  access_token = @config.options.fetch(:access_token)

  init_rest(
    base_url: format(BASE_URL_TEMPLATE, account_id: ),
    auth_middleware: ->(conn) { conn.request :authorization, :bearer, access_token }
  )

  return if  && !.empty? && access_token && !access_token.empty?

  raise ArgumentError, "BasecampAdapter configuration requires :account_id and :access_token"
end