Class: StarkInfra::PixBalance

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

Overview

# PixBalance object

The PixBalance 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]: unique id returned when Balance is created. ex: ‘5656565656565656’

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

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

  • updated [DateTime]: latest update datetime for the balance. 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(id: nil, amount: nil, currency: nil, updated: nil) ⇒ PixBalance

Returns a new instance of PixBalance.



21
22
23
24
25
26
# File 'lib/pixbalance/pixbalance.rb', line 21

def initialize(id: nil, amount: nil, currency: nil, updated: nil)
  super(id)
  @amount = amount
  @currency = currency
  @updated = updated
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



20
21
22
# File 'lib/pixbalance/pixbalance.rb', line 20

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



20
21
22
# File 'lib/pixbalance/pixbalance.rb', line 20

def currency
  @currency
end

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/pixbalance/pixbalance.rb', line 20

def id
  @id
end

#updatedObject (readonly)

Returns the value of attribute updated.



20
21
22
# File 'lib/pixbalance/pixbalance.rb', line 20

def updated
  @updated
end

Class Method Details

.get(user: nil) ⇒ Object

# Retrieve PixBalance

Receive the PixBalance object linked to your workspace in the Stark Infra API

## Parameters (optional):

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

## Return:

  • PixBalance object with updated attributes



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

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

.resourceObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pixbalance/pixbalance.rb', line 41

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