Class: Fintoc::V1::Link
- Inherits:
-
Object
- Object
- Fintoc::V1::Link
- Includes:
- Utils
- Defined in:
- lib/fintoc/v1/resources/link.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#holder_type ⇒ Object
readonly
Returns the value of attribute holder_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#institution ⇒ Object
readonly
Returns the value of attribute institution.
-
#link_token ⇒ Object
readonly
Returns the value of attribute link_token.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #delete ⇒ Object
- #find ⇒ Object
- #find_all(**kwargs) ⇒ Object
-
#initialize(id:, username:, holder_type:, institution:, created_at:, mode:, accounts: nil, link_token: nil, client: nil) ⇒ Link
constructor
A new instance of Link.
- #show_accounts(rows = 5) ⇒ Object
- #to_s ⇒ Object
- #update_accounts ⇒ Object
Methods included from Utils
#flatten, #pick, #pluralize, #snake_to_pascal
Constructor Details
#initialize(id:, username:, holder_type:, institution:, created_at:, mode:, accounts: nil, link_token: nil, client: nil) ⇒ Link
Returns a new instance of Link.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fintoc/v1/resources/link.rb', line 15 def initialize( id:, username:, holder_type:, institution:, created_at:, mode:, accounts: nil, link_token: nil, client: nil, ** ) @id = id @username = username @holder_type = holder_type @institution = Fintoc::V1::Institution.new(**institution) @created_at = Date.iso8601(created_at) @mode = mode @accounts = if accounts.nil? [] else accounts.map { |data| Fintoc::V1::Account.new(**data, client:) } end @token = link_token @client = client end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def accounts @accounts end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def created_at @created_at end |
#holder_type ⇒ Object (readonly)
Returns the value of attribute holder_type.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def holder_type @holder_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def id @id end |
#institution ⇒ Object (readonly)
Returns the value of attribute institution.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def institution @institution end |
#link_token ⇒ Object (readonly)
Returns the value of attribute link_token.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def link_token @link_token end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def mode @mode end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/fintoc/v1/resources/link.rb', line 10 def username @username end |
Instance Method Details
#delete ⇒ Object
76 77 78 |
# File 'lib/fintoc/v1/resources/link.rb', line 76 def delete @client.links.delete(@id) end |
#find ⇒ Object
51 52 53 54 |
# File 'lib/fintoc/v1/resources/link.rb', line 51 def find(**) results = find_all(**) results.any? ? results.first : nil end |
#find_all(**kwargs) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/fintoc/v1/resources/link.rb', line 42 def find_all(**kwargs) raise 'You must provide *exactly one* account field.' if kwargs.size != 1 field, value = kwargs.to_a.first @accounts.select do |account| account.send(field.to_sym) == value end end |
#show_accounts(rows = 5) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fintoc/v1/resources/link.rb', line 56 def show_accounts(rows = 5) puts "This links has #{Utils.pluralize(@accounts.size, 'account')}" return unless @accounts.any? accounts = @accounts.to_a.slice(0, rows) .map.with_index do |acc, index| [index + 1, acc.name, acc.holder_name, acc.currency] end headers = ['#', 'Name', 'Holder', 'Currency'] puts puts tabulate(headers, accounts, indent: 4, style: 'fancy') end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/fintoc/v1/resources/link.rb', line 80 def to_s "<#{@username}@#{@institution.name}> 🔗 <Fintoc>" end |
#update_accounts ⇒ Object
69 70 71 72 73 74 |
# File 'lib/fintoc/v1/resources/link.rb', line 69 def update_accounts @accounts.each do |account| account.update_balance account.update_movements end end |