Class: StarkBank::UtilityPayment::Log

Inherits:
StarkBank::Utils::Resource show all
Defined in:
lib/utility_payment/log.rb

Overview

# UtilityPayment::Log object

Every time a UtilityPayment entity is modified, a corresponding UtilityPayment::Log is generated for the entity. This log is never generated by the user, but it can be retrieved to check additional information on the UtilityPayment.

## Attributes:

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

  • payment [UtilityPayment]: UtilityPayment entity to which the log refers to.

  • errors [list of strings]: list of errors linked to this UtilityPayment event.

  • type [string]: type of the UtilityPayment event which triggered the log creation. ex: ‘processing’ or ‘success’

  • created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StarkBank::Utils::SubResource

#inspect, #to_s

Constructor Details

#initialize(id:, created:, type:, errors:, payment:) ⇒ Log



24
25
26
27
28
29
30
# File 'lib/utility_payment/log.rb', line 24

def initialize(id:, created:, type:, errors:, payment:)
  super(id)
  @type = type
  @errors = errors
  @payment = payment
  @created = StarkBank::Utils::Checks.check_datetime(created)
end

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



23
24
25
# File 'lib/utility_payment/log.rb', line 23

def created
  @created
end

#errorsObject (readonly)

Returns the value of attribute errors.



23
24
25
# File 'lib/utility_payment/log.rb', line 23

def errors
  @errors
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/utility_payment/log.rb', line 23

def id
  @id
end

#paymentObject (readonly)

Returns the value of attribute payment.



23
24
25
# File 'lib/utility_payment/log.rb', line 23

def payment
  @payment
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/utility_payment/log.rb', line 23

def type
  @type
end

Class Method Details

.get(id, user: nil) ⇒ Object

# Retrieve a specific Log

Receive a single Log object previously created by the Stark Bank API by passing its id

## Parameters (required):

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

## Parameters (optional):

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

## Return:

  • Log object with updated attributes



44
45
46
# File 'lib/utility_payment/log.rb', line 44

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

.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil) ⇒ Object

# Retrieve paged Logs

Receive a list of up to 100 Log 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 nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35

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

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

  • types [list of strings, default nil]: filter retrieved objects by event types. ex: ‘paid’ or ‘registered’

  • payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]

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

## Return:

  • list of Log objects with updated attributes and cursor to retrieve the next page of Log objects



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/utility_payment/log.rb', line 92

def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  return StarkBank::Utils::Rest.get_page(
    cursor: cursor,
    limit: limit,
    after: after,
    before: before,
    types: types,
    payment_ids: payment_ids,
    user: user,
    **resource
  )
end

.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil) ⇒ Object

# Retrieve Logs

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

## Parameters (optional):

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

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

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

  • types [list of strings, default nil]: filter retrieved objects by event types. ex: ‘paid’ or ‘registered’

  • payment_ids [list of strings, default nil]: list of UtilityPayment ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]

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

## Return:

  • list of Log objects with updated attributes



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/utility_payment/log.rb', line 62

def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  StarkBank::Utils::Rest.get_stream(
    limit: limit,
    after: after,
    before: before,
    types: types,
    payment_ids: payment_ids,
    user: user,
    **resource
  )
end

.resourceObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/utility_payment/log.rb', line 107

def self.resource
  payment_maker = StarkBank::UtilityPayment.resource[:resource_maker]
  {
    resource_name: 'UtilityPaymentLog',
    resource_maker: proc { |json|
      Log.new(
        id: json['id'],
        created: json['created'],
        type: json['type'],
        errors: json['errors'],
        payment: StarkBank::Utils::API.from_api_json(payment_maker, json['payment'])
      )
    }
  }
end