Class: StarkBank::Balance

Inherits:
Utils::Resource show all
Defined in:
lib/balance/balance.rb

Overview

# Balance object

The Balance object displays the current balance of the workspace, which is the result of the sum of all transactions within this workspace. The balance is never generated by the user, but it can be retrieved to see the available information.

## Attributes (return-only):

  • id [string, default nil]: unique id returned when Boleto is created. ex: “5656565656565656”

  • amount [integer, default nil]: current balance amount of the workspace in cents. ex: 200 (= R$ 2.00)

  • currency [string, default nil]: currency of the current workspace. Expect others to be added eventually. ex: “BRL”

  • updated [DateTime, default nil]: update datetime for the balance. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

Instance Attribute Summary collapse

Attributes inherited from Utils::Resource

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::Resource

#inspect, #to_s

Constructor Details

#initialize(amount:, currency:, updated:, id:) ⇒ Balance

Returns a new instance of Balance.



22
23
24
25
26
27
# File 'lib/balance/balance.rb', line 22

def initialize(amount:, currency:, updated:, id:)
  super(id)
  @amount = amount
  @currency = currency
  @updated = StarkBank::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



21
22
23
# File 'lib/balance/balance.rb', line 21

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



21
22
23
# File 'lib/balance/balance.rb', line 21

def currency
  @currency
end

#updatedObject (readonly)

Returns the value of attribute updated.



21
22
23
# File 'lib/balance/balance.rb', line 21

def updated
  @updated
end

Class Method Details

.get(user: nil) ⇒ Object

# Retrieve the Balance object

Receive the Balance object linked to your workspace in the Stark Bank API

## Parameters (optional):

  • user [Project object]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • Balance object with updated attributes



38
39
40
# File 'lib/balance/balance.rb', line 38

def self.get(user: nil)
  StarkBank::Utils::Rest.get_list(user: user, **resource).next
end