Class: SynapsePayRest::Nodes
- Inherits:
-
Object
- Object
- SynapsePayRest::Nodes
- Defined in:
- lib/synapse_pay_rest/api/nodes.rb
Overview
Wrapper class for /nodes endpoints
Constant Summary collapse
- VALID_QUERY_PARAMS =
TODO:
Should refactor this to HTTPClient
Valid optional args for #get
[:page, :per_page, :type, :full_dehydrate].freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#delete(user_id:, node_id:) ⇒ Hash
Sends a DELETE request to /node endpoint to remove a node, and returns the response.
-
#get(user_id:, node_id: nil, **options) ⇒ Hash
Sends a GET request to /nodes endpoint.
-
#initialize(client) ⇒ Nodes
constructor
A new instance of Nodes.
-
#patch(user_id:, node_id:, payload:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to update a node, and returns the response.
-
#post(user_id:, payload:) ⇒ Hash
(also: #add)
Sends a POST request to /nodes endpoint, to create a new node for the current user, and returns the response.
-
#reissue_card(user_id:, node_id:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to reissue debit card-us node, and returns the response.
-
#reorder_card(user_id:, node_id:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to reorder debit card-us node, and returns the response.
-
#resend_micro(user_id:, node_id:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to reinitiate microdeposits on a node, and returns the response.
-
#verify(user_id:, node_id: nil, payload:) ⇒ Object
deprecated
Deprecated.
Use #update for microdeposit verification or #post for MFA answers.
Constructor Details
#initialize(client) ⇒ Nodes
Returns a new instance of Nodes.
13 14 15 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 13 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ SynapsePayRest::HTTPClient
10 11 12 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 10 def client @client end |
Instance Method Details
#delete(user_id:, node_id:) ⇒ Hash
Sends a DELETE request to /node endpoint to remove a node, and returns the response.
HTTP response from API
138 139 140 141 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 138 def delete(user_id:, node_id:) path = node_path(user_id: user_id, node_id: node_id) client.delete(path) end |
#get(user_id:, node_id: nil, **options) ⇒ Hash
should use CGI or RestClient’s param builder instead of rolling our own, probably error-prone and untested github.com/rest-client/rest-client#usage-raw-url
Sends a GET request to /nodes endpoint. Queries a specific node_id if node_id supplied, else queries all nodes. Returns the response.
HTTP response from API
36 37 38 39 40 41 42 43 44 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 36 def get(user_id:, node_id: nil, **) params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path = node_path(user_id: user_id, node_id: node_id) path += '?' + params.join('&') if params.any? client.get(path) end |
#patch(user_id:, node_id:, payload:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to update a node, and returns the response. Only used to verify microdeposits for ACH-US nodes currently.
HTTP response from API
76 77 78 79 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 76 def patch(user_id:, node_id:, payload:) path = node_path(user_id: user_id, node_id: node_id) client.patch(path, payload) end |
#post(user_id:, payload:) ⇒ Hash Also known as: add
Sends a POST request to /nodes endpoint, to create a new node for the current user, and returns the response.
HTTP response from API
57 58 59 60 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 57 def post(user_id:, payload:) path = node_path(user_id: user_id) client.post(path, payload) end |
#reissue_card(user_id:, node_id:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to reissue debit card-us node, and returns the response.
HTTP response from API
107 108 109 110 111 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 107 def reissue_card(user_id:, node_id:) path = node_path(user_id: user_id, node_id: node_id) path += '?reissue_card=YES' client.patch(path, {}) end |
#reorder_card(user_id:, node_id:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to reorder debit card-us node, and returns the response.
HTTP response from API
123 124 125 126 127 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 123 def reorder_card(user_id:, node_id:) path = node_path(user_id: user_id, node_id: node_id) path += '?reorder_card=YES' client.patch(path, {}) end |
#resend_micro(user_id:, node_id:) ⇒ Hash
Sends a PATCH request to /nodes endpoint to reinitiate microdeposits on a node, and returns the response.
HTTP response from API
91 92 93 94 95 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 91 def resend_micro(user_id:, node_id:) path = node_path(user_id: user_id, node_id: node_id) path += '?resend_micro=YES' client.patch(path, {}) end |
#verify(user_id:, node_id: nil, payload:) ⇒ Object
Use #update for microdeposit verification or #post for MFA answers.
Verifies microdeposits (via #patch) for a node if a node_id supplied, else submits answers to bank login MFA questions (via #post).
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/synapse_pay_rest/api/nodes.rb', line 150 def verify(user_id:, node_id: nil, payload:) if node_id warn caller.first + " DEPRECATION WARNING: #{self.class}##{__method__} is deprecated. Use #patch instead." # verify microdeposits patch(user_id: user_id, node_id: node_id, payload: payload) else warn caller.first + " DEPRECATION WARNING: #{self.class}##{__method__} is deprecated. Use #post instead." # verify MFA questions post(user_id: user_id, payload: payload) end end |