Class: SynapsePayRest::Nodes

Inherits:
Object
  • Object
show all
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

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

#clientSynapsePayRest::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

Parameters:

  • user_id (String)
  • node_id (String)

Returns:

  • (Hash)

    API response

Raises:



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

TODO:

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

Parameters:

  • user_id (String)
  • node_id (String, void) (defaults to: nil)
  • page (String, Integer)

    (optional) response will default to 1

  • per_page (String, Integer)

    (optional) response will default to 20

  • type (String)

    (optional)

  • full_dehydrate (String, String)

    (optional) response will inclulde all transaction data

Returns:

  • (Hash)

    API response

Raises:

See Also:



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, **options)
  params = VALID_QUERY_PARAMS.map do |p|
    options[p] ? "#{p}=#{options[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

Parameters:

  • user_id (String)
  • node_id (String)
  • payload (Hash)

Returns:

  • (Hash)

    API response

Raises:

See Also:



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

Parameters:

  • user_id (String)
  • payload (Hash)

    format depends on node type

Returns:

  • (Hash)

    API response

Raises:

See Also:



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

Parameters:

  • user_id (String)
  • node_id (String)

Returns:

  • (Hash)

    API response

Raises:



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

Parameters:

  • user_id (String)
  • node_id (String)

Returns:

  • (Hash)

    API response

Raises:



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

Parameters:

  • user_id (String)
  • node_id (String)

Returns:

  • (Hash)

    API response

Raises:



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

Deprecated.

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).

Parameters:

  • user_id (String)
  • node_id (String, void) (defaults to: nil)
  • payload (Hash)

    see #patch and #post for payload format



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