Class: StarkBank::Event::Attempt

Inherits:
Utils::Resource show all
Defined in:
lib/event/attempt.rb

Overview

# Event::Attempt object

When an Event delivery fails, an event attempt will be registered. It carries information meant to help you debug event reception issues.

## Attributes:

  • id [string]: unique id that identifies the delivery attempt. ex: “5656565656565656”

  • code [string]: delivery error code. ex: badHttpStatus, badConnection, timeout

  • message [string]: delivery error full description. ex: “HTTP POST request returned status 404”

  • event_id [string]: ID of the Event whose delivery failed. ex: “4848484848484848”

  • webhook_id [string]: ID of the Webhook that triggered this event. ex: “5656565656565656”

  • 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 Utils::SubResource

#inspect, #to_s

Constructor Details

#initialize(id:, code:, message:, event_id:, webhook_id:, created:) ⇒ Attempt

Returns a new instance of Attempt.



24
25
26
27
28
29
30
31
# File 'lib/event/attempt.rb', line 24

def initialize(id:, code:, message:, event_id:, webhook_id:, created:)
  super(id)
  @code = code
  @message = message
  @event_id = event_id
  @webhook_id = webhook_id
  @created = StarkBank::Utils::Checks.check_datetime(created)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



23
24
25
# File 'lib/event/attempt.rb', line 23

def code
  @code
end

#createdObject (readonly)

Returns the value of attribute created.



23
24
25
# File 'lib/event/attempt.rb', line 23

def created
  @created
end

#event_idObject (readonly)

Returns the value of attribute event_id.



23
24
25
# File 'lib/event/attempt.rb', line 23

def event_id
  @event_id
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/event/attempt.rb', line 23

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message.



23
24
25
# File 'lib/event/attempt.rb', line 23

def message
  @message
end

#webhook_idObject (readonly)

Returns the value of attribute webhook_id.



23
24
25
# File 'lib/event/attempt.rb', line 23

def webhook_id
  @webhook_id
end

Class Method Details

.get(id, user: nil) ⇒ Object

# Retrieve a specific Event::Attempt

Receive a single Event::Attempt object previously created by the Stark Bank API by 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:

  • Event::Attempt object with updated attributes



45
46
47
# File 'lib/event/attempt.rb', line 45

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, event_ids: nil, webhook_ids: nil, user: nil) ⇒ Object

# Retrieve paged Attempts

Receive a list of up to 100 Attempt 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)

  • event_ids [list of strings, default None]: list of Event ids to filter attempts. ex: [“5656565656565656”, “4545454545454545”]

  • webhook_ids [list of strings, default None]: list of Webhook ids to filter attempts. ex: [“5656565656565656”, “4545454545454545”]

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

## Return:

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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/event/attempt.rb', line 93

def self.page(cursor: nil, limit: nil, after: nil, before: nil, event_ids: nil, webhook_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,
    event_ids: event_ids,
    webhook_ids: webhook_ids,
    user: user,
    **resource
  )
end

.query(limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil) ⇒ Object

# Retrieve Event::Attempts

Receive a generator of Event::Attempt 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)

  • event_ids [list of strings, default None]: list of Event ids to filter attempts. ex: [“5656565656565656”, “4545454545454545”]

  • webhook_ids [list of strings, default None]: list of Webhook ids to filter attempts. ex: [“5656565656565656”, “4545454545454545”]

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

## Return:

  • generator of Event::Attempt objects with updated attributes



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

def self.query(limit: nil, after: nil, before: nil, event_ids: nil, webhook_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,
    event_ids: event_ids,
    webhook_ids: webhook_ids,
    user: user,
    **resource
  )
end

.resourceObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/event/attempt.rb', line 108

def self.resource
  {
    resource_name: 'EventAttempt',
    resource_maker: proc { |json|
      Attempt.new(
        id: json['id'],
        code: json['code'],
        message: json['message'],
        event_id: json['event_id'],
        webhook_id: json['webhook_id'],
        created: json['created']
      )
    }
  }
end