class SynapsePayRest::Nodes

Wrapper class for /nodes endpoints

Constants

VALID_QUERY_PARAMS

Valid optional args for get @todo Should refactor this to HTTPClient

Attributes

client[RW]

@!attribute [rw] client

@return [SynapsePayRest::HTTPClient]

Public Class Methods

new(client) click to toggle source

@param [SynapsePayRest::HTTPClient]

# File lib/synapse_pay_rest/api/nodes.rb, line 13
def initialize(client)
  @client = client
end

Public Instance Methods

add(user_id:, payload:)

Alias for post (legacy name)

Alias for: post
delete(user_id:, node_id:) click to toggle source

Sends a DELETE request to /node endpoint to remove a node, and returns the response.

@param user_id [String] @param node_id [String]

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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) click to toggle source

Sends a GET request to /nodes endpoint. Queries a specific node_id if node_id supplied, else queries all nodes. Returns the response.

@param user_id [String] @param node_id [String,void] @param page [String,Integer] (optional) response will default to 1 @param per_page [String,Integer] (optional) response will default to 20 @param type [String] (optional) @see docs.synapsepay.com/docs/node-resources node types @param full_dehydrate [String, String] (optional) response will inclulde all transaction data

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

@todo should use CGI or RestClient's param builder instead of

rolling our own, probably error-prone and untested
https://github.com/rest-client/rest-client#usage-raw-url
# 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:) click to toggle source

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.

@param user_id [String] @param node_id [String] @param payload [Hash] @see docs.synapsepay.com/docs/verify-micro-deposit payload structure

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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:) click to toggle source

Sends a POST request to /nodes endpoint, to create a new node for the current user, and returns the response.

@param user_id [String] @param payload [Hash] format depends on node type @see docs.synapsepay.com/docs/node-resources payload structure

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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
Also aliased as: add
reissue_card(user_id:, node_id:) click to toggle source

Sends a PATCH request to /nodes endpoint to reissue debit card-us node, and returns the response.

@param user_id [String] @param node_id [String]

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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:) click to toggle source

Sends a PATCH request to /nodes endpoint to reorder debit card-us node, and returns the response.

@param user_id [String] @param node_id [String]

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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:) click to toggle source

Sends a PATCH request to /nodes endpoint to reinitiate microdeposits on a node, and returns the response.

@param user_id [String] @param node_id [String]

@raise [SynapsePayRest::Error] may return subclasses of error based on HTTP response from API

@return [Hash] API response

# 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:) click to toggle source

Verifies microdeposits (via patch) for a node if a node_id supplied, else submits answers to bank login MFA questions (via post).

@param user_id [String] @param node_id [String,void] @param payload [Hash] see patch and post for payload format @deprecated Use update for microdeposit verification or post for MFA answers.

# 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

Private Instance Methods

node_path(user_id:, node_id: nil) click to toggle source
# File lib/synapse_pay_rest/api/nodes.rb, line 166
def node_path(user_id:, node_id: nil)
  path = "/users/#{user_id}/nodes"
  path += "/#{node_id}" if node_id
  path
end