Class: StarkBank::CorporateTransaction

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

Overview

# CorporateTransaction object

The CorporateTransaction objects created in your Workspace to represent each balance shift.

## Attributes (return-only):

  • id [string]: unique id returned when CorporateTransaction is created. ex: ‘5656565656565656’

  • amount [integer]: CorporateTransaction value in cents. ex: 1234 (= R$ 12.34)

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

  • description [string]: CorporateTransaction description. ex: ‘Buying food’

  • source [string]: source of the transaction. ex: ‘corporate-purchase/5656565656565656’

  • tags [string]: list of strings inherited from the source resource. ex: [‘tony’, ‘stark’]

  • created [DateTime]: creation datetime for the CorporateTransaction. 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, balance: nil, description: nil, source: nil, tags: nil, created: nil) ⇒ CorporateTransaction

Returns a new instance of CorporateTransaction.



22
23
24
25
26
27
28
29
30
# File 'lib/corporate_transaction/corporatetransaction.rb', line 22

def initialize(id: nil, amount: nil, balance: nil, description: nil, source: nil, tags: nil, created: nil)
  super(id)
  @amount = amount
  @balance = balance
  @description = description
  @source = source
  @tags = tags
  @created = StarkCore::Utils::Checks.check_datetime(created)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



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

def amount
  @amount
end

#balanceObject (readonly)

Returns the value of attribute balance.



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

def balance
  @balance
end

#createdObject (readonly)

Returns the value of attribute created.



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

def created
  @created
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Class Method Details

.get(id, user: nil) ⇒ Object

# Retrieve a specific CorporateTransaction

Receive a single CorporateTransaction object previously created in the Stark Bank API by its id

## Parameters (required):

  • id [string]: object unique id. ex: ‘5656565656565656’

## Parameters (optional):

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

## Return:

  • CorporateTransaction object with updated attributes



44
45
46
# File 'lib/corporate_transaction/corporatetransaction.rb', line 44

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

.page(cursor: nil, tags: nil, external_ids: nil, after: nil, before: nil, status: nil, ids: nil, limit: nil, user: nil) ⇒ Object

# Retrieve paged CorporateTransactions

Receive a list of up to 100 CorporateTransaction objects previously created in the Stark Bank API and the cursor to the next page. Use this function instead of query if you want to manually page your requests.

## Parameters (optional):

  • cursor [string, default nil]: cursor returned on the previous page function call.

  • limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35

  • after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)

  • before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)

  • tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]

  • external_ids [list of strings, default nil]: external IDs. ex: [‘5656565656565656’, ‘4545454545454545’]

  • status [string, default nil]: filter for status of retrieved objects. ex: ‘approved’, ‘canceled’, ‘denied’, ‘confirmed’ or ‘voided’

  • ids [list of strings, default nil]: purchase IDs

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

## Return:

  • list of CorporateTransactions objects with updated attributes

  • cursor to retrieve the next page of CorporateTransactions objects



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/corporate_transaction/corporatetransaction.rb', line 99

def self.page(cursor: nil, tags: nil, external_ids: nil, after: nil, before: nil, status: nil, ids: nil, limit: nil,
              user: nil)
  after = StarkCore::Utils::Checks.check_date(after)
  before = StarkCore::Utils::Checks.check_date(before)
  StarkBank::Utils::Rest.get_page(
    cursor: cursor,
    tags: tags,
    external_ids: external_ids,
    after: after,
    before: before,
    status: status,
    ids: ids,
    limit: limit,
    user: user,
    **resource
  )
end

.query(tags: nil, external_ids: nil, after: nil, before: nil, status: nil, ids: nil, limit: nil, user: nil) ⇒ Object

# Retrieve CorporateTransactions

Receive a generator of CorporateTransaction objects previously created in the Stark Bank API

## Parameters (optional):

  • tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]

  • external_ids [list of strings, default nil]: external IDs. ex: [‘5656565656565656’, ‘4545454545454545’]

  • after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)

  • before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)

  • status [string, default nil]: filter for status of retrieved objects. ex: ‘approved’, ‘canceled’, ‘denied’, ‘confirmed’ or ‘voided’

  • ids [list of strings, default nil]: purchase IDs

  • limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35

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

## Return:

  • generator of CorporateTransaction objects with updated attributes



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/corporate_transaction/corporatetransaction.rb', line 64

def self.query(tags: nil, external_ids: nil, after: nil, before: nil, status: nil, ids: nil, limit: nil, user: nil)
  after = StarkCore::Utils::Checks.check_date(after)
  before = StarkCore::Utils::Checks.check_date(before)
  StarkBank::Utils::Rest.get_stream(
    tags: tags,
    external_ids: external_ids,
    after: after,
    before: before,
    status: status,
    ids: ids,
    limit: limit,
    user: user,
    **resource
  )
end

.resourceObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/corporate_transaction/corporatetransaction.rb', line 117

def self.resource
  {
    resource_name: 'CorporateTransaction',
    resource_maker: proc { |json|
      CorporateTransaction.new(
        id: json['id'],
        amount: json['amount'],
        balance: json['balance'],
        description: json['description'],
        source: json['source'],
        tags: json['tags'],
        created: json['created']
      )
    }
  }
end