Class: Rafflesia::BaseClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rafflesia/base_client.rb

Direct Known Subclasses

Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, api_host: nil, base_url: nil, configuration: nil, **opts) ⇒ BaseClient

Returns a new instance of BaseClient.

Raises:



24
25
26
27
28
29
# File 'lib/rafflesia/base_client.rb', line 24

def initialize(api_key: nil, api_host: nil, base_url: nil, configuration: nil, **opts)
  @configuration =
    configuration ||
      Configuration.new(api_key: api_key, api_host: api_host, base_url: base_url, **opts)
  raise ConfigurationError, 'api_key is required' if @configuration.api_key.nil?
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



22
23
24
# File 'lib/rafflesia/base_client.rb', line 22

def configuration
  @configuration
end

Instance Method Details

#api_hostObject



35
36
37
# File 'lib/rafflesia/base_client.rb', line 35

def api_host
  @configuration.api_host
end

#api_keyObject



31
32
33
# File 'lib/rafflesia/base_client.rb', line 31

def api_key
  @configuration.api_key
end

#request(method:, path:, auth: true, params: nil, body: nil, request_options: {}) ⇒ Object

Issue an HTTP request. Returns the raw Net::HTTPResponse so the spec-derived caller can read .body, .code, headers, and the x-request-id.



42
43
44
45
46
47
48
# File 'lib/rafflesia/base_client.rb', line 42

def request(method:, path:, auth: true, params: nil, body: nil, request_options: {})
  uri = build_uri(path, params)
  req = build_request(method, uri, body: body, auth: auth, request_options: request_options)
  response = perform(uri, req, request_options: request_options)
  raise_for_status(response)
  response
end