Class: HybiscusPdfReport::Client

Inherits:
Object
  • Object
show all
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.

Examples:

Basic usage

client = HybiscusPdfReport::Client.new(api_key: "your_api_key")
response = client.request.build_report(report_data)

Using environment variables

ENV["HYBISCUS_API_KEY"] = "your_api_key"
client = HybiscusPdfReport::Client.new

Custom configuration

client = HybiscusPdfReport::Client.new(
  api_key: "your_key",
  api_url: "https://api.hybiscus.dev/api/v1/",
  timeout: 30
)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adapterObject (readonly)

Returns the value of attribute adapter.



29
30
31
# File 'lib/hybiscus_pdf_report/client.rb', line 29

def adapter
  @adapter
end

#api_keyObject (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_urlObject (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_requestObject (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

#requestObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



49
50
51
# File 'lib/hybiscus_pdf_report/client.rb', line 49

def request
  @request ||= Request.new(self)
end