Class: SynapsePayRest::Subnet
- Inherits:
-
Object
- Object
- SynapsePayRest::Subnet
- Defined in:
- lib/synapse_pay_rest/models/subnet/subnet.rb
Overview
Represents a subnet record and holds methods for constructing subnet instances from API calls. This is built on top of the SynapsePayRest::Subnets class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.
Instance Attribute Summary collapse
-
#account_num ⇒ Object
readonly
Returns the value of attribute account_num.
-
#allowed ⇒ Object
readonly
Returns the value of attribute allowed.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_name ⇒ Object
readonly
Returns the value of attribute client_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
- #node ⇒ Object
-
#routing_num_ach ⇒ Object
readonly
Returns the value of attribute routing_num_ach.
-
#routing_num_wire ⇒ Object
readonly
Returns the value of attribute routing_num_wire.
Class Method Summary collapse
-
.all(node:, page: nil, per_page: nil) ⇒ Array<SynapsePayRest::Subnet>
Queries the API for all subnets belonging to the supplied node and returns them as Subnet instances.
-
.create(node:, nickname:, **options) ⇒ SynapsePayRest::Subnet
Creates a new subnet in the API belonging to the provided node and returns a subnet instance from the response data.
-
.find(node:, id:) ⇒ SynapsePayRest::Subnet
Queries the API for a subnet belonging to the supplied node by subnet id and returns a Subnet n instance if found.
-
.from_response(node, response) ⇒ Object
Creates a Subnet from a response hash.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks if two Subnet instances have same id (different instances of same record).
-
#initialize(**options) ⇒ Subnet
constructor
A new instance of Subnet.
-
#lock ⇒ Array<SynapsePayRest::Subnet>
Changes Subnet’s allowed permission from ‘CREDIT’ to ‘LOCKED’.
Constructor Details
#initialize(**options) ⇒ Subnet
Do not call directly. Use Subnet.create or other class method to instantiate via API action.
Returns a new instance of Subnet.
128 129 130 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 128 def initialize(**) .each { |key, value| instance_variable_set("@#{key}", value) } end |
Instance Attribute Details
#account_num ⇒ Object (readonly)
Returns the value of attribute account_num.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def account_num @account_num end |
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def allowed @allowed end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def client_id @client_id end |
#client_name ⇒ Object (readonly)
Returns the value of attribute client_name.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def client_name @client_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def id @id end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def nickname @nickname end |
#node ⇒ Object
9 10 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 attr_reader :id, :account_num, :allowed, :client_id, :client_name, :nickname, :node, :routing_num_ach, :routing_num_wire |
#routing_num_ach ⇒ Object (readonly)
Returns the value of attribute routing_num_ach.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def routing_num_ach @routing_num_ach end |
#routing_num_wire ⇒ Object (readonly)
Returns the value of attribute routing_num_wire.
9 10 11 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 9 def routing_num_wire @routing_num_wire end |
Class Method Details
.all(node:, page: nil, per_page: nil) ⇒ Array<SynapsePayRest::Subnet>
Queries the API for all subnets belonging to the supplied node and returns them as Subnet instances.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 74 def all(node:, page: nil, per_page: nil) raise ArgumentError, 'node must be a type of BaseNode object' 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 = node.user.client.subnets.get( user_id: node.user.id, node_id: node.id, page: page, per_page: per_page ) multiple_from_response(node, response['subnets']) end |
.create(node:, nickname:, **options) ⇒ SynapsePayRest::Subnet
Creates a new subnet in the API belonging to the provided node and returns a subnet instance from the response data.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 25 def create(node:, nickname:, **) raise ArgumentError, 'cannot create a transaction with an UnverifiedNode' if node.is_a?(UnverifiedNode) raise ArgumentError, 'node must be a type of BaseNode object' unless node.is_a?(BaseNode) [nickname].each do |arg| if [arg] && ![arg].is_a?(String) raise ArgumentError, "#{arg} must be a String" end end payload = payload_for_create(node: node, nickname: nickname, **) response = node.user.client.subnets.create( user_id: node.user.id, node_id: node.id, payload: payload, ) from_response(node, response) end |
.find(node:, id:) ⇒ SynapsePayRest::Subnet
Queries the API for a subnet belonging to the supplied node by subnet id and returns a Subnet n instance if found.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 52 def find(node:, id:) raise ArgumentError, 'node must be a type of BaseNode object' unless node.is_a?(BaseNode) raise ArgumentError, 'id must be a String' unless id.is_a?(String) response = node.user.client.subnets.get( user_id: node.user.id, node_id: node.id, subnet_id: id ) from_response(node, response) end |
.from_response(node, response) ⇒ Object
Shouldn’t need to call this directly.
Creates a Subnet from a response hash.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 95 def from_response(node, response) args = { node: node, id: response['_id'], account_num: response['account_num'], allowed: response['allowed'], client_id: response['client']['id'], client_name: response['client']['name'], nickname: response['nickname'], node_id: response['node_id'], routing_num_ach: response['routing_num']['ach'], routing_num_wire: response['routing_num']['wire'], user_id: response['user_id'] } self.new(args) end |
Instance Method Details
#==(other) ⇒ Object
Checks if two Subnet instances have same id (different instances of same record).
157 158 159 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 157 def ==(other) other.instance_of?(self.class) && !id.nil? && id == other.id end |
#lock ⇒ Array<SynapsePayRest::Subnet>
Changes Subnet’s allowed permission from ‘CREDIT’ to ‘LOCKED’.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/synapse_pay_rest/models/subnet/subnet.rb', line 139 def lock payload = {'allowed' => 'LOCKED'} response = node.user.client.subnets.update( user_id: node.user.id, node_id: node.id, subnet_id: id, payload: payload ) if response['subnets'] # api v3.1 self.class.from_response(node, response['subnets']) else # api v3.1.1 self.class.from_response(node, response) end end |