Class: SynapsePayRest::Statement
- Inherits:
-
Object
- Object
- SynapsePayRest::Statement
- Defined in:
- lib/synapse_pay_rest/models/statement/statement.rb
Overview
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.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#csv_url ⇒ Object
readonly
Returns the value of attribute csv_url.
-
#date_end ⇒ Object
readonly
Returns the value of attribute date_end.
-
#date_start ⇒ Object
readonly
Returns the value of attribute date_start.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#json_url ⇒ Object
readonly
Returns the value of attribute json_url.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#pdf_url ⇒ Object
readonly
Returns the value of attribute pdf_url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
-
.by_node(client:, node:, page: nil, per_page: nil) ⇒ SynapsePayRest::Statement
Gets statement by node or user.
-
.by_user(client:, user:, page: nil, per_page: nil) ⇒ SynapsePayRest::Statement
Gets statement by node or user.
-
.from_response(client, response) ⇒ Object
Creates a statements instance from a response hash.
- .multiple_from_response(client, response) ⇒ Object
Instance Method Summary collapse
-
#initialize(**options) ⇒ Statement
constructor
A new instance of Statement.
Constructor Details
#initialize(**options) ⇒ Statement
Do not call directly. Use Statement.get or other class method to instantiate via API action.
Returns a new instance of Statement.
76 77 78 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 76 def initialize(**) .each { |key, value| instance_variable_set("@#{key}", value) } end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def client @client end |
#csv_url ⇒ Object (readonly)
Returns the value of attribute csv_url.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def csv_url @csv_url end |
#date_end ⇒ Object (readonly)
Returns the value of attribute date_end.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def date_end @date_end end |
#date_start ⇒ Object (readonly)
Returns the value of attribute date_start.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def date_start @date_start end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def id @id end |
#json_url ⇒ Object (readonly)
Returns the value of attribute json_url.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def json_url @json_url end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def node @node end |
#pdf_url ⇒ Object (readonly)
Returns the value of attribute pdf_url.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def pdf_url @pdf_url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'lib/synapse_pay_rest/models/statement/statement.rb', line 7 def user @user end |
Class Method Details
.by_node(client:, node:, page: nil, per_page: nil) ⇒ SynapsePayRest::Statement
Gets statement by node or user.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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) ⇒ SynapsePayRest::Statement
Gets statement by node or user.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
Shouldn’t need to call this directly.
Creates a statements instance from a response hash.
12 13 14 15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
67 68 69 70 |
# 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 |