class SynapsePayRest::Statement

Represents a statement record and holds methods for getting statements from API calls. This is built on top of the SynapsePayRest::Client class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.

Attributes

client[R]
csv_url[R]
date_end[R]
date_start[R]
id[R]
json_url[R]
node[R]
pdf_url[R]
user[R]

Public Class Methods

by_node(client:, node:, page: nil, per_page: nil) click to toggle source

Gets statement by node or user. @param client [SynapsePayRest::Client] @param user [SynapsePayRest::Node]

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::Statement] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/statement/statement.rb, line 53
def by_node(client:, node:, page: nil, per_page: nil)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  raise ArgumentError, 'node must be a SynapsePayRest::Node' unless node.is_a?(BaseNode)

  [page, per_page].each do |arg|
    if arg && (!arg.is_a?(Integer) || arg < 1)
      raise ArgumentError, "#{arg} must be nil or an Integer >= 1"
    end
  end

  response = client.statements.get(user_id: node.user.id, node_id: node.id, page: page, per_page: per_page)
  multiple_from_response(client, response['statements'])
end
by_user(client:, user:, page: nil, per_page: nil) click to toggle source

Gets statement by node or user. @param client [SynapsePayRest::Client] @param user [SynapsePayRest::User]

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::Statement] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/statement/statement.rb, line 32
def by_user(client:, user:, page: nil, per_page: nil)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  raise ArgumentError, 'id must be a SynapsePayRest::User' unless user.is_a?(User)

  [page, per_page].each do |arg|
    if arg && (!arg.is_a?(Integer) || arg < 1)
      raise ArgumentError, "#{arg} must be nil or an Integer >= 1"
    end
  end

  response = client.statements.get(user_id: user.id, page: page, per_page: per_page)
  multiple_from_response(client, response['statements'])
end
from_response(client, response) click to toggle source

Creates a statements instance from a response hash. @note Shouldn't need to call this directly.

# File lib/synapse_pay_rest/models/statement/statement.rb, line 12
def from_response(client, response)
  args = {
    client:                   client,
    id:                       response['_id'],
    date_end:                 response['date_end'],
    date_start:               response['date_start'],
    csv_url:                  response['urls']['csv'],
    pdf_url:                  response['urls']['pdf'],
    json_url:                 response['urls']['json']
  }
  self.new(args)
end
multiple_from_response(client, response) click to toggle source
# File lib/synapse_pay_rest/models/statement/statement.rb, line 67
def multiple_from_response(client, response)
  return [] if response.empty?
  response.map { |statement_data| from_response(client, statement_data) }
end
new(**options) click to toggle source

@note Do not call directly. Use Statement.get or other class method

to instantiate via API action.
# File lib/synapse_pay_rest/models/statement/statement.rb, line 76
def initialize(**options)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
end