Class: Round::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/round/account.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

association, #hash_identifier, #method_missing, #refresh

Constructor Details

#initialize(options = {}) ⇒ Account

Returns a new instance of Account.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/round/account.rb', line 8

def initialize(options = {})
  raise ArgumentError, 'Account must be associated with a wallet' unless options[:wallet]
  super(options)
  @wallet = options[:wallet]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Round::Base

Instance Attribute Details

#walletObject

Returns the value of attribute wallet.



6
7
8
# File 'lib/round/account.rb', line 6

def wallet
  @wallet
end

Class Method Details

.hash_identifierObject



37
38
39
# File 'lib/round/account.rb', line 37

def self.hash_identifier
  "name"
end

Instance Method Details

#pay(payees, confirmations, redirect_uri = nil, mfa_token: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/round/account.rb', line 22

def pay(payees, confirmations, redirect_uri = nil, mfa_token: nil)
  raise 'You must unlock the wallet before attempting a transaction' unless @wallet.multiwallet

  payment = self.transactions.create(payees, confirmations)
  signed = payment.sign(@wallet.multiwallet, 
                        redirect_uri: redirect_uri, 
                        network: network.to_sym)
  if wallet.application
    mfa_token = mfa_token || @wallet.application.get_mfa
    signed.approve(mfa_token)
    signed.refresh
  end
  signed
end

#transactions(**query) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/round/account.rb', line 14

def transactions(**query)
  query[:status] = query[:status].join(',') if query[:status]
  Round::TransactionCollection.new(
    resource: @resource.transactions(query),
    client: @client
  )
end