class SynapsePayRest::User

Represents a user record and holds methods for constructing user instances from API calls. This is built on top of the SynapsePayRest::Users class and is intended to make it easier to use the API without knowing payload formats or knowledge of REST.

@todo use mixins to remove duplication between Node and BaseNode. @todo reduce duplicated logic between User/BaseNode/Transaction

Attributes

base_documents[RW]
cip_tag[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
client[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
expires_in[RW]
flag[RW]
id[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
ips[RW]
is_business[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
logins[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
note[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
oauth_key[RW]
permission[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
phone_numbers[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions
refresh_token[RW]
supp_id[R]

@!attribute [rw] base_documents

@return [Array<SynapsePayRest::BaseDocument>]

@!attribute [r] permission

@return [String] https://docs.synapsepay.com/docs/user-resources#section-user-permissions

Public Class Methods

all(client:, page: nil, per_page: nil, query: nil) click to toggle source

Queries the API for all users (with optional filters) and returns them as User instances.

@param client [SynapsePayRest::Client] @param query [String] (optional) response will be filtered to

users with matching name/email

@param page [String,Integer] (optional) response will default to 1 @param per_page [String,Integer] (optional) response will default to 20

@raise [SynapsePayRest::Error] if HTTP error or invalid argument format

@return [Array<SynapsePayRest::User>]

@note users created this way are not automatically OAuthed

# File lib/synapse_pay_rest/models/user/user.rb, line 95
def all(client:, page: nil, per_page: nil, query: nil)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  [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
  if query && !query.is_a?(String)
    raise ArgumentError, 'query must be a String'
  end

  response = client.users.get(page: page, per_page: per_page, query: query)
  multiple_from_response(client, response['users'])
end
create(client:, logins:, phone_numbers:, legal_names:, **options) click to toggle source

Creates a new user in the API and returns a User instance from the response data.

@param client [SynapsePayRest::Client] @param logins [Array<Hash>] @param phone_numbers [Array<String>] @param legal_names [Array<String>] @param note [String] (optional) @param supp_id [String] (optional) @param is_business [Boolean] (optional) API defaults to false @param cip_tag [Integer] (optional) the CIP tag to use in this users CIP doc

@example logins argument (only :email is required)

[{
  email: "test@test.com", 
  password: "letmein", 
  read_only: false
}]

@raise [SynapsePayRest::Error] if HTTP error or invalid argument format

@return [SynapsePayRest::User]

@todo simplify the logins argument somehow. separate class?

# File lib/synapse_pay_rest/models/user/user.rb, line 43
def create(client:, logins:, phone_numbers:, legal_names:, **options)
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  if [logins, phone_numbers, legal_names].any? { |arg| !arg.is_a? Array}
    raise ArgumentError, 'logins/phone_numbers/legal_names must be Array'
  end
  if [logins, phone_numbers, legal_names].any?(&:empty?)
    raise ArgumentError, 'logins/phone_numbers/legal_names cannot be empty'
  end
  unless logins.first.is_a? Hash
    raise ArgumentError, 'logins must contain at least one hash {email: (required), password:, read_only:}'
  end
  unless logins.first[:email].is_a?(String) && logins.first[:email].length > 0
    raise ArgumentError, 'logins must contain at least one hash with :email key'
  end

  payload = payload_for_create(logins: logins, phone_numbers: phone_numbers, legal_names: legal_names, **options)
  response = client.users.create(payload: payload)
  from_response(client, response)
end
find(client:, id:, full_dehydrate:'no') click to toggle source

Queries the API for a user by id and returns a User instances if found.

@param client [SynapsePayRest::Client] @param id [String] id of the user to find @param full_dehydrate [String] (optional) if 'yes', returns all KYC on user

@raise [SynapsePayRest::Error] if user not found or invalid client credentials

@return [SynapsePayRest::User]

# File lib/synapse_pay_rest/models/user/user.rb, line 72
def find(client:, id:, full_dehydrate:'no')
  raise ArgumentError, 'client must be a SynapsePayRest::Client' unless client.is_a?(Client)
  raise ArgumentError, 'id must be a String' unless id.is_a?(String)

  response = client.users.get(user_id: id, full_dehydrate: full_dehydrate)
  
  from_response(client, response)
end
from_response(client, response, oauth: true) click to toggle source

Constructs a user instance from a user response. @note Do not call directly.

# File lib/synapse_pay_rest/models/user/user.rb, line 149
def from_response(client, response, oauth: true)
  user = self.new(
    client:            client,
    id:                response['_id'],
    refresh_token:     response['refresh_token'],
    logins:            response['logins'],
    phone_numbers:     response['phone_numbers'],
    legal_names:       response['legal_names'],
    permission:        response['permission'],
    note:              response['extra']['note'],
    supp_id:           response['extra']['supp_id'],
    is_business:       response['extra']['is_business'],
    cip_tag:           response['extra']['cip_tag'],
    flag:              nil,
    ips:               nil,
    oauth_key:         nil,
    expires_in:        nil
  )

  if response.has_key?('flag')
    user.flag = response['flag']
  end

  if response.has_key?('ips')
    user.ips = response['ips']
  end

  unless response['documents'].empty?
    base_documents = BaseDocument.from_response(user, response)
    user.base_documents = base_documents
  end
  oauth ? user.authenticate : user
end
multiple_from_response(client, response) click to toggle source

Calls from_response on each member of a response collection. @note users created this way are not automatically OAuthed

# File lib/synapse_pay_rest/models/user/user.rb, line 185
def multiple_from_response(client, response)
  return [] if response.empty?
  response.map { |user_data| from_response(client.dup, user_data, oauth: false)}
end
new(**options) click to toggle source

@note Do not call directly. Use User.create or other class method

to instantiate via API action.
# File lib/synapse_pay_rest/models/user/user.rb, line 193
def initialize(**options)
  options.each { |key, value| instance_variable_set("@#{key}", value) }
  @base_documents  ||= []
end
payload_for_create(logins:, phone_numbers:, legal_names:, **options) click to toggle source

Maps args to API payload format. @note Do not call directly.

# File lib/synapse_pay_rest/models/user/user.rb, line 130
def payload_for_create(logins:, phone_numbers:, legal_names:, **options)
  payload = {
    'logins'        => logins,
    'phone_numbers' => phone_numbers,
    'legal_names'   => legal_names,
  }
  # optional payload fields
  extra = {}
  extra['note']        = options[:note] if options[:note]
  extra['supp_id']     = options[:supp_id] if options[:supp_id]
  extra['is_business'] = options[:is_business] if options[:is_business]
  extra['cip_tag']     = options[:cip_tag] if options[:cip_tag]
  payload['extra']     = extra if extra.any?

  payload
end

Public Instance Methods

==(other) click to toggle source

Checks if two User instances have same id (different instances of same record).

# File lib/synapse_pay_rest/models/user/user.rb, line 805
def ==(other)
  other.instance_of?(self.class) && !id.nil? && id == other.id
end
add_login(email:, password: nil, read_only: nil) click to toggle source

Adds a login for the user.

@param email [String] @param password [String] (optional) @param read_only [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::User] (self)

# File lib/synapse_pay_rest/models/user/user.rb, line 280
def add_login(email:, password: nil, read_only: nil)
  raise ArgumentError, 'email must be a String' unless email.is_a?(String)
  raise ArgumentError, 'password must be nil or String' if password && !password.is_a?(String)
  if read_only && ![true, false].include?(read_only)
    raise ArgumentError, 'read_only must be nil or Boolean' 
  end

  login = {'email' => email}
  # optional
  login['password']  = password if password
  login['read_only'] = read_only if read_only
  update(login: login)
end
add_phone_number(phone_number) click to toggle source

Add a phone_number to the user.

@param phone_number [String]

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::User] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/user/user.rb, line 315
def add_phone_number(phone_number)
  raise ArgumentError, 'phone_number must be a String' unless phone_number.is_a? String

  update(phone_number: phone_number)
end
authenticate() click to toggle source

Updates the oauth token.

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::User] (new instance with updated tokens)

# File lib/synapse_pay_rest/models/user/user.rb, line 203
def authenticate
  response        = client.users.refresh(user_id: id, payload: payload_for_refresh)
  self.oauth_key  = response['oauth_key']
  self.expires_in = response['expires_in']
  self
end
confirm_2fa_pin(pin:, device:) click to toggle source

Step 3 (final) step of fingerprint registration. Confirms the PIN sent to the device after calling select_2fa_device (step 2).

@param pin [String] @param device [String]

@raise [SynapsePayRest::Error]

@return [:success] if successful

# File lib/synapse_pay_rest/models/user/user.rb, line 403
def confirm_2fa_pin(pin:, device:)
  raise ArgumentError, 'pin must be a String' unless pin.is_a?(String)
  raise ArgumentError, 'device must be a String' unless device.is_a?(String)
  
  payload = payload_for_refresh
  payload['phone_number']   = device
  payload['validation_pin'] = pin
  client.users.refresh(user_id: id, payload: payload)
  :success
end
create_ach_us_node(**options) click to toggle source

Creates an ACH-US node via account and routing numbers, belonging to this user.

@param nickname [String] nickname for the node @param account_number [String] @param routing_number [String] @param account_type [String] 'PERSONAL' or 'BUSINESS' @param account_class [String] 'CHECKING' or 'SAVINGS' @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::AchUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 454
def create_ach_us_node(**options)
  AchUsNode.create(user: self, **options)
end
create_ach_us_nodes_via_bank_login(**options) click to toggle source

Creates an ACH-US node via bank login, belonging to this user.

@param bank_name [String] @see synapsepay.com/api/v3/institutions/show valid bank_name options @param username [String] user's bank login username @param password [String] user's bank login password

@raise [SynapsePayRest::Error]

@return [Array<SynapsePayRest::AchUsNode>] may contain multiple nodes (checking and/or savings)

# File lib/synapse_pay_rest/models/user/user.rb, line 468
def create_ach_us_nodes_via_bank_login(**options)
  AchUsNode.create_via_bank_login(user: self, **options)
end
create_ach_us_nodes_via_bank_login_mfa(**options) click to toggle source

Creates an Unverified Node Class node via access token, belonging to this user

@param access_token [String] @see synapsepay.com/api/v3/institutions/show valid bank_name options

@raise [SynapsePayRest::Error]

@return [<SynapsePayRest::UnverifiedNode>]

# File lib/synapse_pay_rest/models/user/user.rb, line 480
def create_ach_us_nodes_via_bank_login_mfa(**options)
  AchUsNode.create_via_bank_login_mfa(user: self, **options)
end
create_base_document(**args) click to toggle source

Creates a new base document for the user. To update an existing base document, see SynapsePay::BaseDocument#update.

@param email [String] @param phone_number [String] @param ip [String] @param name [String] @param aka [String] corresponds to 'alias' in docs, use name if no alias @param entity_type [String] consult your organization's CIP for valid options @see docs.synapsepay.com/docs/user-resources#section-supported-entity-types all supported entity_type values @param entity_scope [String] consult your organization's CIP for valid options @see docs.synapsepay.com/docs/user-resources#section-supported-entity-scope all entity_scope options @param birth_day [Integer] @param birth_month [Integer] @param birth_year [Integer] @param address_street [String] @param address_city [String] @param address_subdivision [String] @param address_postal_code [String] @param address_country_code [String] @param physical_documents [Array<SynapsePayRest::PhysicalDocument>] (optional) @param social_documents [Array<SynapsePayRest::SocialDocument>] (optional) @param virtual_documents [Array<SynapsePayRest::VirtualDocument>] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::User] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/user/user.rb, line 267
def create_base_document(**args)
  BaseDocument.create(user: self, **args)
end
create_card_us_node(**options) click to toggle source

Creates a CARD-US node.

@param nickname [String] nickname for the node @param document_id [String] Document ID of user's base document that the card is associated with @param card_type PHYSICAL or VIRTUAL

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::CardUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 749
def create_card_us_node(**options)
  CardUsNode.create(user: self, **options)
end
create_check_us_node(**options) click to toggle source

Creates a CHECK-US node.

@param nickname [String] nickname for the node @param bank_name [String] @param account_number [String] @param routing_number [String] @param name_on_account [String] @param address [String] @param correspondent_routing_number [String] (optional) @param correspondent_bank_name [String] (optional) @param correspondent_address [String] (optional) @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::CheckUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 684
def create_check_us_node(**options)
  CheckUsNode.create(user: self, **options)
end
create_clearing_us_node(**options) click to toggle source

Creates a CLEARING-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::ClearingUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 697
def create_clearing_us_node(**options)
  ClearingUsNode.create(user: self, **options)
end
create_crypto_us_node(**options) click to toggle source

Creates a CRYPTO-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::CryptoUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 775
def create_crypto_us_node(**options)
  CryptoUsNode.create(user: self, **options)
end
create_custody_us_node(**options) click to toggle source

Creates a CUSTODY-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::CustodyUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 788
def create_custody_us_node(**options)
  CustodyUsNode.create(user: self, **options)
end
create_deposit_us_node(**options) click to toggle source

Creates a DEPOSIT-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::SynapseUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 593
def create_deposit_us_node(**options)
  DepositUsNode.create(user: self, **options)
end
create_eft_ind_node(**options) click to toggle source

Creates an EFT-IND node.

@param nickname [String] nickname for the node @param account_number [String] @param ifsc [String] @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::EftIndNode]

@deprecated

# File lib/synapse_pay_rest/models/user/user.rb, line 497
def create_eft_ind_node(**options)
  EftIndNode.create(user: self, **options)
end
create_eft_np_node(**options) click to toggle source

Creates an EFT-NP node.

@param nickname [String] nickname for the node @param bank_name [String] @param account_number [String] @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::EftNpNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 512
def create_eft_np_node(**options)
  EftNpNode.create(user: self, **options)
end
create_ib_deposit_us_node(**options) click to toggle source

Creates a IB-DEPOSIT-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::IbDepositUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 710
def create_ib_deposit_us_node(**options)
  IbDepositUsNode.create(user: self, **options)
end
create_ib_subaccount_us_node(**options) click to toggle source

Creates a IB-SUBACCOUNT-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::IbSubaccountUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 723
def create_ib_subaccount_us_node(**options)
  IbSubaccountUsNode.create(user: self, **options)
end
create_interchange_us_node(**options) click to toggle source

Creates a INTERCHANGE-US node.

@param nickname [String] nickname for the node @param document_id [String] Document ID of user's base document that the card is associated with @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::InterchangeUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 736
def create_interchange_us_node(**options)
  InterchangeUsNode.create(user: self, **options)
end
create_iou_node(**options) click to toggle source

Creates an IOU node.

@param nickname [String] nickname for the node @param currency [String] e.g. 'USD' @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::IouNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 526
def create_iou_node(**options)
  IouNode.create(user: self, **options)
end
create_reserve_us_node(**options) click to toggle source

Creates a RESERVE-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::IouNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 539
def create_reserve_us_node(**options)
  ReserveUsNode.create(user: self, **options)
end
create_subaccount_us_node(**options) click to toggle source

Creates a SUBACCOUNT-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::SubaccountUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 606
def create_subaccount_us_node(**options)
  SubaccountUsNode.create(user: self, **options)
end
create_subcard_us_node(**options) click to toggle source

Creates a SUBCARD-US node.

@param nickname [String] nickname for the node @param document_id [String] Document ID of user's base document that the card is associated with @param card_type PHYSICAL or VIRTUAL

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::SubcardUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 762
def create_subcard_us_node(**options)
  SubcardUsNode.create(user: self, **options)
end
create_synapse_ind_node(**options) click to toggle source

Creates a SYNAPSE-IND node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::SynapseIndNode]

@deprecated

# File lib/synapse_pay_rest/models/user/user.rb, line 554
def create_synapse_ind_node(**options)
  SynapseIndNode.create(user: self, **options)
end
create_synapse_np_node(**options) click to toggle source

Creates a SYNAPSE-NP node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::SynapseNpNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 567
def create_synapse_np_node(**options)
  SynapseNpNode.create(user: self, **options)
end
create_synapse_us_node(**options) click to toggle source

Creates a SYNAPSE-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::SynapseUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 580
def create_synapse_us_node(**options)
  SynapseUsNode.create(user: self, **options)
end
create_triumph_subaccount_us_node(**options) click to toggle source

Creates a TRIUMPH-SUBACCOUNT-US node.

@param nickname [String] nickname for the node @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::TriumphSubaccountUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 619
def create_triumph_subaccount_us_node(**options)
  TriumphSubaccountUsNode.create(user: self, **options)
end
create_wire_int_node(**options) click to toggle source

Creates a WIRE-INT node.

@param nickname [String] nickname for the node @param bank_name [String] @param account_number [String] @param swift [String] @param name_on_account [String] @param address [String] @param routing_number [String] (optional) @param correspondent_bank_name [String] (optional) @param correspondent_routing_number [String] (optional) @param correspondent_address [String] (optional) @param correspondent_swift [String] (optional) @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::WireIntNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 642
def create_wire_int_node(**options)
  WireIntNode.create(user: self, **options)
end
create_wire_us_node(**options) click to toggle source

Creates a WIRE-US node.

@param nickname [String] nickname for the node @param bank_name [String] @param account_number [String] @param routing_number [String] @param name_on_account [String] @param address [String] @param correspondent_routing_number [String] (optional) @param correspondent_bank_name [String] (optional) @param correspondent_address [String] (optional) @param supp_id [String] (optional) @param gateway_restricted [Boolean] (optional)

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::WireUsNode]

# File lib/synapse_pay_rest/models/user/user.rb, line 663
def create_wire_us_node(**options)
  WireUsNode.create(user: self, **options)
end
find_node(id:) click to toggle source

Queries the API for a node belonging to this user by node id and returns a node instance if found.

@param id [String] id of the node to find

@raise [SynapsePayRest::Error] if node not found or other HTTP error

@return [SynapsePayRest::BaseNode] subclass depends on node type

# File lib/synapse_pay_rest/models/user/user.rb, line 437
def find_node(id:)
  Node.find(user: self, id: id)
end
get_statement() click to toggle source

Gets statement for user

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::Statement]

# File lib/synapse_pay_rest/models/user/user.rb, line 800
def get_statement()
  Statement.by_user(client: self.client, user:self)
end
nodes(**options) click to toggle source

Queries the API for all nodes belonging to this user and returns them as node (SynapsePayRest::BaseNode) instances.

@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

@raise [SynapsePayRest::Error]

@return [Array<SynapsePayRest::BaseNode>] subclass d`epends on node types

# File lib/synapse_pay_rest/models/user/user.rb, line 425
def nodes(**options)
  Node.all(user: self, **options)
end
register_fingerprint(fingerprint) click to toggle source

Step 1 of fingerprint registration. Requests a new fingerprint be registered to the user.

@param fingerprint [String]

@raise [SynapsePayRest::Error]

@return [Array<String>] array of devices (phone number / email)

# File lib/synapse_pay_rest/models/user/user.rb, line 368
def register_fingerprint(fingerprint)
  raise ArgumentError, 'fingerprint must be a String' unless fingerprint.is_a?(String)

  client.http_client.update_headers(fingerprint: fingerprint)
  response = client.users.refresh(user_id: id, payload: payload_for_refresh)
  response['phone_numbers']
end
remove_login(email:) click to toggle source

Removes a login from the user.

@param email [String]

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::User] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/user/user.rb, line 301
def remove_login(email:)
  raise ArgumentError, 'email must be a String' unless email.is_a? String

  login = {email: email}
  update(remove_login: login)
end
remove_phone_number(phone_number) click to toggle source

Removes a phone_number from the user.

@param phone_number [String]

@raise [SynapsePayRest::Error]

@return [SynapsePayRest::User] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/user/user.rb, line 341
def remove_phone_number(phone_number)
  raise ArgumentError, 'phone_number must be a String' unless phone_number.is_a? String

  update(remove_phone_number: phone_number)
end
select_2fa_device(device) click to toggle source

Step 2 of fingerprint registration. Sends a request to the API to send a 2FA PIN to the device specified. The device must be selected from return value of register_fingerprint.

@param device [String]

@raise [SynapsePayRest::Error]

@return [:success] if successful

# File lib/synapse_pay_rest/models/user/user.rb, line 385
def select_2fa_device(device)
  raise ArgumentError, 'device must be a String' unless device.is_a?(String)

  payload = payload_for_refresh
  payload['phone_number'] = device
  client.users.refresh(user_id: id, payload: payload)
  :success
end
update(**options) click to toggle source

Updates the given key value pairs.

@param login [Hash] @param phone_number [String] @param legal_name [String] @param remove_login [Hash] @param remove_phone_number [String] @param read_only [Boolean] @param remove_legal_name [String]

@example login/remove_login argument (only email is required)

{
  email: "test@test.com", 
  password: "letmein", 
  read_only: false
}

@raise [SynapsePayRest::Error] if HTTP error or invalid argument format

@return [SynapsePayRest::User] new instance corresponding to same API record

# File lib/synapse_pay_rest/models/user/user.rb, line 230
def update(**options)
  if options.empty?
    raise ArgumentError, 'must provide a key-value pair to update. keys: login,
      read_only, phone_number, legal_name, remove_phone_number, remove_login'
  end
  response = client.users.update(user_id: id, payload: payload_for_update(options))
  # return an updated user instance
  self.class.from_response(client, response)
end

Private Instance Methods

payload_for_refresh() click to toggle source
# File lib/synapse_pay_rest/models/user/user.rb, line 827
def payload_for_refresh
  {'refresh_token' => refresh_token}
end
payload_for_update(**options) click to toggle source

Converts update args into API payload structure.

# File lib/synapse_pay_rest/models/user/user.rb, line 812
def payload_for_update(**options)
  payload = {
    'refresh_token' => refresh_token,
    'update' => {}
  }
  # must have one of these
  payload['update']['login']               = options[:login] if options[:login]
  payload['update']['remove_login']        = options[:remove_login] if options[:remove_login]
  payload['update']['legal_name']          = options[:legal_name] if options[:legal_name]
  payload['update']['phone_number']        = options[:phone_number] if options[:phone_number]
  payload['update']['remove_phone_number'] = options[:remove_phone_number] if options[:remove_phone_number]
  payload['update']['remove_legal_name']   = options[:remove_legal_name] if options[:remove_legal_name]
  payload
end