Class: AdvancedBilling::Webhook

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/webhook.rb

Overview

Webhook Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(event = SKIP, id = SKIP, created_at = SKIP, last_error = SKIP, last_error_at = SKIP, accepted_at = SKIP, last_sent_at = SKIP, last_sent_url = SKIP, successful = SKIP, body = SKIP, signature = SKIP, signature_hmac_sha_256 = SKIP) ⇒ Webhook

Returns a new instance of Webhook.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/advanced_billing/models/webhook.rb', line 113

def initialize(event = SKIP, id = SKIP, created_at = SKIP,
               last_error = SKIP, last_error_at = SKIP, accepted_at = SKIP,
               last_sent_at = SKIP, last_sent_url = SKIP, successful = SKIP,
               body = SKIP, signature = SKIP, signature_hmac_sha_256 = SKIP)
  @event = event unless event == SKIP
  @id = id unless id == SKIP
  @created_at = created_at unless created_at == SKIP
  @last_error = last_error unless last_error == SKIP
  @last_error_at = last_error_at unless last_error_at == SKIP
  @accepted_at = accepted_at unless accepted_at == SKIP
  @last_sent_at = last_sent_at unless last_sent_at == SKIP
  @last_sent_url = last_sent_url unless last_sent_url == SKIP
  @successful = successful unless successful == SKIP
  @body = body unless body == SKIP
  @signature = signature unless signature == SKIP
  @signature_hmac_sha_256 = signature_hmac_sha_256 unless signature_hmac_sha_256 == SKIP
end

Instance Attribute Details

#accepted_atString

Timestamp indicating when the webhook was accepted by the merchant endpoint. When a webhook is explicitly replayed by the merchant, this value will be cleared until it is accepted again.

Returns:

  • (String)


41
42
43
# File 'lib/advanced_billing/models/webhook.rb', line 41

def accepted_at
  @accepted_at
end

#bodyString

The data sent within the webhook post

Returns:

  • (String)


60
61
62
# File 'lib/advanced_billing/models/webhook.rb', line 60

def body
  @body
end

#created_atString

Timestamp indicating when the webhook was created

Returns:

  • (String)


24
25
26
# File 'lib/advanced_billing/models/webhook.rb', line 24

def created_at
  @created_at
end

#eventString

A string describing which event type produced the given webhook

Returns:

  • (String)


14
15
16
# File 'lib/advanced_billing/models/webhook.rb', line 14

def event
  @event
end

#idInteger

The unique identifier for the webhooks (unique across all of Chargify). This is not changed on a retry/replay of the same webhook, so it may be used to avoid duplicate action for the same event.

Returns:

  • (Integer)


20
21
22
# File 'lib/advanced_billing/models/webhook.rb', line 20

def id
  @id
end

#last_errorString

Text describing the status code and/or error from the last failed attempt to send the Webhook. When a webhook is retried and accepted, this field will be cleared.

Returns:

  • (String)


30
31
32
# File 'lib/advanced_billing/models/webhook.rb', line 30

def last_error
  @last_error
end

#last_error_atString

Timestamp indicating when the last non-acceptance occurred. If a webhook is later resent and accepted, this field will be cleared.

Returns:

  • (String)


35
36
37
# File 'lib/advanced_billing/models/webhook.rb', line 35

def last_error_at
  @last_error_at
end

#last_sent_atString

Timestamp indicating when the most recent attempt was made to send the webhook

Returns:

  • (String)


46
47
48
# File 'lib/advanced_billing/models/webhook.rb', line 46

def last_sent_at
  @last_sent_at
end

#last_sent_urlString

The url that the endpoint was last sent to.

Returns:

  • (String)


50
51
52
# File 'lib/advanced_billing/models/webhook.rb', line 50

def last_sent_url
  @last_sent_url
end

#signatureString

The calculated webhook signature

Returns:

  • (String)


64
65
66
# File 'lib/advanced_billing/models/webhook.rb', line 64

def signature
  @signature
end

#signature_hmac_sha_256String

The calculated HMAC-SHA-256 webhook signature

Returns:

  • (String)


68
69
70
# File 'lib/advanced_billing/models/webhook.rb', line 68

def signature_hmac_sha_256
  @signature_hmac_sha_256
end

#successfulTrueClass | FalseClass

A boolean flag describing whether the webhook was accepted by the webhook endpoint for the most recent attempt. (Acceptance is defined by receiving a “200 OK” HTTP response within a reasonable timeframe, i.e. 15 seconds)

Returns:

  • (TrueClass | FalseClass)


56
57
58
# File 'lib/advanced_billing/models/webhook.rb', line 56

def successful
  @successful
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/advanced_billing/models/webhook.rb', line 132

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  event = hash.key?('event') ? hash['event'] : SKIP
  id = hash.key?('id') ? hash['id'] : SKIP
  created_at = hash.key?('created_at') ? hash['created_at'] : SKIP
  last_error = hash.key?('last_error') ? hash['last_error'] : SKIP
  last_error_at = hash.key?('last_error_at') ? hash['last_error_at'] : SKIP
  accepted_at = hash.key?('accepted_at') ? hash['accepted_at'] : SKIP
  last_sent_at = hash.key?('last_sent_at') ? hash['last_sent_at'] : SKIP
  last_sent_url = hash.key?('last_sent_url') ? hash['last_sent_url'] : SKIP
  successful = hash.key?('successful') ? hash['successful'] : SKIP
  body = hash.key?('body') ? hash['body'] : SKIP
  signature = hash.key?('signature') ? hash['signature'] : SKIP
  signature_hmac_sha_256 =
    hash.key?('signature_hmac_sha_256') ? hash['signature_hmac_sha_256'] : SKIP

  # Create object from extracted values.
  Webhook.new(event,
              id,
              created_at,
              last_error,
              last_error_at,
              accepted_at,
              last_sent_at,
              last_sent_url,
              successful,
              body,
              signature,
              signature_hmac_sha_256)
end

.namesObject

A mapping from model property names to API property names.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/advanced_billing/models/webhook.rb', line 71

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['event'] = 'event'
  @_hash['id'] = 'id'
  @_hash['created_at'] = 'created_at'
  @_hash['last_error'] = 'last_error'
  @_hash['last_error_at'] = 'last_error_at'
  @_hash['accepted_at'] = 'accepted_at'
  @_hash['last_sent_at'] = 'last_sent_at'
  @_hash['last_sent_url'] = 'last_sent_url'
  @_hash['successful'] = 'successful'
  @_hash['body'] = 'body'
  @_hash['signature'] = 'signature'
  @_hash['signature_hmac_sha_256'] = 'signature_hmac_sha_256'
  @_hash
end

.nullablesObject

An array for nullable fields



107
108
109
110
111
# File 'lib/advanced_billing/models/webhook.rb', line 107

def self.nullables
  %w[
    accepted_at
  ]
end

.optionalsObject

An array for optional fields



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/advanced_billing/models/webhook.rb', line 89

def self.optionals
  %w[
    event
    id
    created_at
    last_error
    last_error_at
    accepted_at
    last_sent_at
    last_sent_url
    successful
    body
    signature
    signature_hmac_sha_256
  ]
end