Module: SynapsePayRest::Node
- Defined in:
- lib/synapse_pay_rest/models/node/node.rb
Overview
use mixins to remove duplication between Node and BaseNode
Factory for BaseNode subclasses.
Constant Summary collapse
- NODE_TYPES_TO_CLASSES =
Node type to node class mappings.
{ 'ACH-US' => AchUsNode, 'EFT-NP' => EftNpNode, 'EFT-IND' => EftIndNode, 'IOU' => IouNode, 'RESERVE-US' => ReserveUsNode, 'DEPOSIT-US' => DepositUsNode, 'SYNAPSE-IND' => SynapseIndNode, 'SYNAPSE-NP' => SynapseNpNode, 'SYNAPSE-US' => SynapseUsNode, 'TRIUMPH-SUBACCOUNT-US' => TriumphSubaccountUsNode, 'SUBACCOUNT-US' => SubaccountUsNode, 'WIRE-INT' => WireIntNode, 'WIRE-US' => WireUsNode, 'CHECK-US' => CheckUsNode, 'CLEARING-US' => ClearingUsNode, 'IB-DEPOSIT-US' => IbDepositUsNode, 'IB-SUBACCOUNT-US' => IbSubaccountUsNode, 'INTERCHANGE-US' => InterchangeUsNode, 'CARD-US' => CardUsNode, 'SUBCARD-US' => SubcardUsNode, 'CRYPTO-US' => CryptoUsNode, "CUSTODY-US" => CustodyUsNode }.freeze
Class Method Summary collapse
-
.all(user:, page: nil, per_page: nil, type: nil) ⇒ Array<SynapsePayRest::BaseNode>
Queries the API for all nodes belonging to the supplied user (with optional filters) and returns them as node instances.
-
.by_type(user:, type:, page: nil, per_page: nil) ⇒ Array<SynapsePayRest::BaseNode>
Queries the API for all nodes belonging to the supplied user (with optional filters) and matching the given type.
-
.find(user:, id:, full_dehydrate: 'no') ⇒ SynapsePayRest::BaseNode
Queries the API for a node with the supplied id belong to the supplied user, and returns a node instance from the response data.
Class Method Details
.all(user:, page: nil, per_page: nil, type: nil) ⇒ Array<SynapsePayRest::BaseNode>
Queries the API for all nodes belonging to the supplied user (with optional filters) and returns them as node instances.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/synapse_pay_rest/models/node/node.rb', line 64 def all(user:, page: nil, per_page: nil, type: nil) raise ArgumentError, 'user must be a User object' 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 unless type.nil? || NODE_TYPES_TO_CLASSES.keys.include?(type) raise ArgumentError, "type must be nil or in #{NODE_TYPES_TO_CLASSES.keys}" end response = user.client.nodes.get( user_id: user.id, page: page, per_page: per_page, type: type ) multiple_from_response(user, response['nodes']) end |
.by_type(user:, type:, page: nil, per_page: nil) ⇒ Array<SynapsePayRest::BaseNode>
Queries the API for all nodes belonging to the supplied user (with optional filters) and matching the given type.
96 97 98 |
# File 'lib/synapse_pay_rest/models/node/node.rb', line 96 def by_type(user:, type:, page: nil, per_page: nil) all(user: user, page: page, per_page: per_page, type: type) end |
.find(user:, id:, full_dehydrate: 'no') ⇒ SynapsePayRest::BaseNode
Queries the API for a node with the supplied id belong to the supplied user, and returns a node instance from the response data.
44 45 46 47 48 49 50 |
# File 'lib/synapse_pay_rest/models/node/node.rb', line 44 def find(user:, id:, full_dehydrate: 'no') raise ArgumentError, 'user must be a User object' unless user.is_a?(User) raise ArgumentError, 'id must be a String' unless id.is_a?(String) response = user.client.nodes.get(user_id: user.id, node_id: id, full_dehydrate: full_dehydrate) from_response(user, response) end |