Class: StarkBank::CorporateBalance

Inherits:
StarkCore::Utils::Resource
  • Object
show all
Defined in:
lib/corporate_balance/corporatebalance.rb

Overview

# CorporateBalance object

The CorporateBalance object displays the current corporate 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]: unique id returned when CorporateBalance is created. ex: ‘5656565656565656’

  • amount [integer]: current corporate balance amount of the Workspace in cents. ex: 200 (= R$ 2.00)

  • limit [integer]: the maximum negative balance allowed by the user. ex: 10000 (= R$ 100.00)

  • max_limit [integer]: the maximum negative balance allowed by StarkBank. ex: 100000 (= R$ 1000.00)

  • currency [string]: currency of the current Workspace. Expect others to be added eventually. ex: ‘BRL’

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount: nil, limit: nil, max_limit: nil, currency: nil, updated: nil, id: nil) ⇒ CorporateBalance

Returns a new instance of CorporateBalance.



22
23
24
25
26
27
28
29
# File 'lib/corporate_balance/corporatebalance.rb', line 22

def initialize(amount: nil, limit: nil, max_limit: nil, currency: nil, updated: nil, id: nil)
  super(id)
  @amount = amount
  @limit = limit
  @max_limit = max_limit
  @currency = currency
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



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

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



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

def currency
  @currency
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

#max_limitObject (readonly)

Returns the value of attribute max_limit.



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

def max_limit
  @max_limit
end

#updatedObject (readonly)

Returns the value of attribute updated.



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

def updated
  @updated
end

Class Method Details

.get(user: nil) ⇒ Object

# Retrieve the CorporateBalance object

Receive the CorporateBalance object linked to your Workspace in the Stark Infrq API

## Parameters (optional):

  • user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • CorporateBalance object with updated attributes



40
41
42
# File 'lib/corporate_balance/corporatebalance.rb', line 40

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

.resourceObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/corporate_balance/corporatebalance.rb', line 44

def self.resource
  {
    resource_name: 'CorporateBalance',
    resource_maker: proc { |json|
      CorporateBalance.new(
        id: json['id'],
        amount: json['amount'],
        limit: json['limit'],
        max_limit: json['max_limit'],
        currency: json['currency'],
        updated: json['updated']
      )
    }
  }
end