Class: StarkInfra::PixRequest::Log

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

Overview

# PixRequest::Log object

Every time a PixRequest entity is modified, a corresponding PixRequest::Log is generated for the entity. This log is never generated by the user.

## Attributes (return-only):

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

  • request [PixRequest object]: PixRequest entity to which the log refers to.

  • type [string]: type of the PixRequest event which triggered the log creation. ex: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”

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

  • 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

Constructor Details

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

Returns a new instance of Log.



22
23
24
25
26
27
28
# File 'lib/pixrequest/log.rb', line 22

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

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



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

def created
  @created
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.get(id, user: nil) ⇒ Object

# Retrieve a specific PixRequest::Log

Receive a single PixRequest::Log object previously created by the Stark Infra API by passing 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 StarkInfra.user was set before function call

## Return:

  • PixRequest::Log object with updated attributes



42
43
44
# File 'lib/pixrequest/log.rb', line 42

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

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

# Retrieve paged PixRequest::Logs

Receive a list of up to 100 PixRequest::Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your logs.

## 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)

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

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

  • reconciliation_id [string]: PixRequest reconciliation id to filter retrieved objects. ex: “b77f5236-7ab9-4487-9f95-66ee6eaf1781”

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

## Return:

  • list of PixRequest::Log objects with updated attributes

  • cursor to retrieve the next page of Log objects



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pixrequest/log.rb', line 95

def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, request_ids: nil, reconciliation_id: nil, user: nil)
  after = StarkCore::Utils::Checks.check_date(after)
  before = StarkCore::Utils::Checks.check_date(before)
  StarkInfra::Utils::Rest.get_page(
    cursor: cursor,
    limit: limit,
    after: after,
    before: before,
    types: types,
    request_ids: request_ids,
    reconciliation_id: reconciliation_id,
    user: user,
    **resource
  )
end

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

# Retrieve PixRequest::Logs

Receive a generator of PixRequest::Log objects previously created in the Stark Infra API

## Parameters (optional):

  • limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. 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)

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

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

  • reconciliation_id [string, default nil]: PixRequest reconciliation id to filter retrieved objects. ex: “b77f5236-7ab9-4487-9f95-66ee6eaf1781”

  • ids [list of strings, default nil]: Log ids to filter PixKey Logs. ex: [‘5656565656565656’]

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

## Return:

  • generator of PixRequest::Log objects with updated attributes



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

def self.query(limit: nil, after: nil, before: nil, types: nil, request_ids: nil, reconciliation_id: nil, user: nil)
  after = StarkCore::Utils::Checks.check_date(after)
  before = StarkCore::Utils::Checks.check_date(before)
  StarkInfra::Utils::Rest.get_stream(
    limit: limit,
    after: after,
    before: before,
    types: types,
    request_ids: request_ids,
    reconciliation_id: reconciliation_id,
    user: user,
    **resource
  )
end

.resourceObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/pixrequest/log.rb', line 111

def self.resource
  request_maker = StarkInfra::PixRequest.resource[:resource_maker]
  {
    resource_name: 'PixRequestLog',
    resource_maker: proc { |json|
      Log.new(
        id: json['id'],
        request: StarkCore::Utils::API.from_api_json(request_maker, json['request']),
        type: json['type'],
        errors: json['errors'],
        created: json['created']
      )
    }
  }
end