Class: Assinafy::Resources::BaseResource

Inherits:
Object
  • Object
show all
Defined in:
lib/assinafy/resources/base_resource.rb,
sig/assinafy.rbs

Overview

Shared plumbing for every resource: a Faraday connection, an optional default account ID, parameter normalisation, response-envelope handling, pagination header parsing, and a single request/call pipeline that wraps Faraday and Assinafy errors into the SDK's own error hierarchy.

Constant Summary collapse

PATH_SEGMENT =

Returns:

  • (Regexp)
/\A[A-Za-z0-9._~-]+\z/
AUTH_HEADERS =

Returns:

  • (Array[String])
%w[X-Api-Key Authorization].freeze
PAGINATION_HEADERS =

Returns:

  • (Hash[Symbol, String])
{
  current_page: 'x-pagination-current-page',
  per_page:     'x-pagination-per-page',
  total:        'x-pagination-total-count',
  last_page:    'x-pagination-page-count'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(connection, default_account_id = nil, logger = nil) ⇒ BaseResource

Returns a new instance of BaseResource.

Parameters:

  • connection (Faraday::Connection)
  • default_account_id (String, nil) (defaults to: nil)

    used by account_id when no override is passed

  • logger (Logger, nil) (defaults to: nil)


22
23
24
25
26
27
# File 'lib/assinafy/resources/base_resource.rb', line 22

def initialize(connection,  = nil, logger = nil)
  @connection = connection
  @connection.headers['User-Agent'] = USER_AGENT
  @default_account_id = .is_a?(String) ? .dup.freeze : 
  @logger             = logger || NullLogger.new
end