Class: Njalla::V1::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/njalla/v1/client.rb

Overview

Implements HTTP client

Instance Method Summary collapse

Constructor Details

#initialize(token:) ⇒ Client

Returns a new instance of Client.

Parameters:

  • token (String)


14
15
16
# File 'lib/njalla/v1/client.rb', line 14

def initialize(token:)
  @token = token
end

Instance Method Details

#get(method, params = nil) ⇒ Object

Parameters:

  • method (String)
  • params (Dry::Schema::Result) (defaults to: nil)


20
21
22
23
24
25
26
27
28
# File 'lib/njalla/v1/client.rb', line 20

def get(method, params = nil)
  raise params.errors.inspect unless params&.success?

  self.class.get('/', headers: headers, body: {
    jsonrpc: '2.0',
    method: method,
    params: params&.to_h
  }.to_json)
end

#post(method, params) ⇒ Object

Parameters:

  • method (String)
  • params (Dry::Schema::Result)


32
33
34
35
36
37
38
39
40
# File 'lib/njalla/v1/client.rb', line 32

def post(method, params)
  raise params.errors.inspect unless params.success?

  self.class.post('/', headers: headers, body: {
    jsonrpc: '2.0',
    method: method,
    params: params.to_h
  }.to_json)
end