Class: HybiscusPdfReport::Client
- Inherits:
-
Object
- Object
- HybiscusPdfReport::Client
- Defined in:
- lib/hybiscus_pdf_report/client.rb
Overview
HTTP client for the Hybiscus PDF Reports API.
This class handles all HTTP communication with the Hybiscus API, including authentication, connection management, and request routing. It uses Faraday for HTTP requests and supports custom adapters for testing.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#last_request ⇒ Object
readonly
Returns the value of attribute last_request.
Instance Method Summary collapse
- #connection(header = {}) ⇒ Object
-
#initialize(api_key: nil, api_url: nil, timeout: nil, adapter: nil, stubs: nil) ⇒ Client
constructor
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#request ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
Constructor Details
#initialize(api_key: nil, api_url: nil, timeout: nil, adapter: nil, stubs: nil) ⇒ Client
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hybiscus_pdf_report/client.rb', line 32 def initialize(api_key: nil, api_url: nil, timeout: nil, adapter: nil, stubs: nil) @api_key = (api_key || config.api_key)&.strip if @api_key.nil? || @api_key.empty? raise ArgumentError, "No API key defined. Set it in config or pass to Client.new." end @api_url = api_url || config.api_url @timeout = timeout || config.timeout # param made available for testing purposes: In the rspec tests the following adapter is used: :test # https://www.rubydoc.info/gems/faraday/Faraday/Adapter/Test @adapter = adapter || config.adapter @stubs = stubs || config.stubs end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
29 30 31 |
# File 'lib/hybiscus_pdf_report/client.rb', line 29 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
29 30 31 |
# File 'lib/hybiscus_pdf_report/client.rb', line 29 def api_key @api_key end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
29 30 31 |
# File 'lib/hybiscus_pdf_report/client.rb', line 29 def api_url @api_url end |
#last_request ⇒ Object (readonly)
Returns the value of attribute last_request.
29 30 31 |
# File 'lib/hybiscus_pdf_report/client.rb', line 29 def last_request @last_request end |
Instance Method Details
#connection(header = {}) ⇒ Object
53 54 55 |
# File 'lib/hybiscus_pdf_report/client.rb', line 53 def connection(header = {}) @connection ||= build_connection(header) end |