Class: SynapsePayRest::Statements

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/api/statements.rb

Overview

Wrapper class for /client endpoint

Constant Summary collapse

VALID_QUERY_PARAMS =
TODO:

Should refactor this to HTTPClient

Valid optional args for #get

[:page, :per_page].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Statements

Returns a new instance of Statements.

Parameters:



14
15
16
# File 'lib/synapse_pay_rest/api/statements.rb', line 14

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientSynapsePayRest::HTTPClient



11
12
13
# File 'lib/synapse_pay_rest/api/statements.rb', line 11

def client
  @client
end

Instance Method Details

#get(user_id:, node_id: nil, **options) ⇒ Hash

Sends a GET request /node or /user statments endpoint to retrieve statements, and returns the response.

HTTP response from API

Parameters:

  • user_id (String)
  • node_id (String) (defaults to: nil)

    optional

Returns:

  • (Hash)

    API response

Raises:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/synapse_pay_rest/api/statements.rb', line 28

def get(user_id:, node_id: nil, **options)
  params = VALID_QUERY_PARAMS.map do |p|
    options[p] ? "#{p}=#{options[p]}" : nil
  end.compact

  path = "/users/#{user_id}"
  path += "/nodes/#{node_id}" if node_id
  path += "/statements"
  path += '?' + params.join('&') if params.any?
  client.get(path)
end