Class: Retab::BaseClient
- Inherits:
-
Object
- Object
- Retab::BaseClient
- Defined in:
- lib/retab/base_client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #api_host ⇒ Object
- #api_key ⇒ Object
-
#initialize(api_key: nil, api_host: nil, configuration: nil, **opts) ⇒ BaseClient
constructor
A new instance of BaseClient.
-
#request(method:, path:, auth: true, params: nil, body: nil, request_options: {}) ⇒ Object
Issue an HTTP request.
Constructor Details
#initialize(api_key: nil, api_host: nil, configuration: nil, **opts) ⇒ BaseClient
Returns a new instance of BaseClient.
21 22 23 24 25 26 |
# File 'lib/retab/base_client.rb', line 21 def initialize(api_key: nil, api_host: nil, configuration: nil, **opts) @configuration = configuration || Configuration.new(api_key: api_key, api_host: api_host, **opts) raise ConfigurationError, 'api_key is required' if @configuration.api_key.nil? end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
19 20 21 |
# File 'lib/retab/base_client.rb', line 19 def configuration @configuration end |
Instance Method Details
#api_host ⇒ Object
32 33 34 |
# File 'lib/retab/base_client.rb', line 32 def api_host @configuration.api_host end |
#api_key ⇒ Object
28 29 30 |
# File 'lib/retab/base_client.rb', line 28 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`.
39 40 41 42 43 44 45 |
# File 'lib/retab/base_client.rb', line 39 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: ) response = perform(uri, req, request_options: ) raise_for_status(response) response end |