Class: Renshuu::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/renshuu/client.rb

Overview

HTTP client for the Renshuu API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = Renshuu.configuration) ⇒ Client

Returns a new instance of Client.

Parameters:

  • configuration (Configuration) (defaults to: Renshuu.configuration)


9
10
11
# File 'lib/renshuu/client.rb', line 9

def initialize(configuration = Renshuu.configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationConfiguration (readonly)

Returns:



15
16
17
# File 'lib/renshuu/client.rb', line 15

def configuration
  @configuration
end

Instance Method Details

#httpxHTTPX::Session (private)

Returns:

  • (HTTPX::Session)


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

Parameters:

  • method (Symbol)
  • path (String)
  • params (Hash{Symbol, String => Object}) (defaults to: {})

Returns:

  • (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