Class: Renshuu::Client
- Inherits:
-
Object
- Object
- Renshuu::Client
- Defined in:
- lib/renshuu/client.rb
Overview
HTTP client for the Renshuu API.
Instance Attribute Summary collapse
- #configuration ⇒ Configuration readonly
Instance Method Summary collapse
- #httpx ⇒ HTTPX::Session private
-
#initialize(configuration = Renshuu.configuration) ⇒ Client
constructor
A new instance of Client.
- #query(method, path, params: {}) ⇒ Hash{Symbol => Object}, Array
Constructor Details
#initialize(configuration = Renshuu.configuration) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/renshuu/client.rb', line 9 def initialize(configuration = Renshuu.configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Configuration (readonly)
15 16 17 |
# File 'lib/renshuu/client.rb', line 15 def configuration @configuration end |
Instance Method Details
#httpx ⇒ HTTPX::Session (private)
32 33 34 35 36 37 |
# File 'lib/renshuu/client.rb', line 32 def httpx @httpx ||= HTTPX.with( origin: configuration.api_url, headers: { authorization: "Bearer #{configuration.api_key}" } ) end |
#query(method, path, params: {}) ⇒ Hash{Symbol => Object}, Array
23 24 25 26 |
# File 'lib/renshuu/client.rb', line 23 def query(method, path, params: {}) httpx.request(method, path, params:) .raise_for_status.json(symbolize_names: true) end |