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, additional_properties: {}) ⇒ Webhook

Returns a new instance of Webhook.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/advanced_billing/models/webhook.rb', line 114

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,
               additional_properties: {})
  @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

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#accepted_atDateTime

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:

  • (DateTime)


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

def accepted_at
  @accepted_at
end

#bodyString

The data sent within the webhook post

Returns:

  • (String)


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

def body
  @body
end

#created_atDateTime

Timestamp indicating when the webhook was created

Returns:

  • (DateTime)


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

def created_at
  @created_at
end

#eventString

A string describing which event type produced the given webhook

Returns:

  • (String)


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

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)


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

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)


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

def last_error
  @last_error
end

#last_error_atDateTime

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

Returns:

  • (DateTime)


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

def last_error_at
  @last_error_at
end

#last_sent_atDateTime

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

Returns:

  • (DateTime)


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

def last_sent_at
  @last_sent_at
end

#last_sent_urlString

The url that the endpoint was last sent to.

Returns:

  • (String)


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

def last_sent_url
  @last_sent_url
end

#signatureString

The calculated webhook signature

Returns:

  • (String)


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

def signature
  @signature
end

#signature_hmac_sha_256String

The calculated HMAC-SHA-256 webhook signature

Returns:

  • (String)


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

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)


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

def successful
  @successful
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/advanced_billing/models/webhook.rb', line 139

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 = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  last_error = hash.key?('last_error') ? hash['last_error'] : SKIP
  last_error_at = if hash.key?('last_error_at')
                    (DateTimeHelper.from_rfc3339(hash['last_error_at']) if hash['last_error_at'])
                  else
                    SKIP
                  end
  accepted_at = if hash.key?('accepted_at')
                  (DateTimeHelper.from_rfc3339(hash['accepted_at']) if hash['accepted_at'])
                else
                  SKIP
                end
  last_sent_at = if hash.key?('last_sent_at')
                   (DateTimeHelper.from_rfc3339(hash['last_sent_at']) if hash['last_sent_at'])
                 else
                   SKIP
                 end
  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

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

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

.namesObject

A mapping from model property names to API property names.



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

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



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

def self.nullables
  %w[
    accepted_at
  ]
end

.optionalsObject

An array for optional fields



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

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

Instance Method Details

#to_custom_accepted_atObject



200
201
202
# File 'lib/advanced_billing/models/webhook.rb', line 200

def to_custom_accepted_at
  DateTimeHelper.to_rfc3339(accepted_at)
end

#to_custom_created_atObject



192
193
194
# File 'lib/advanced_billing/models/webhook.rb', line 192

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_last_error_atObject



196
197
198
# File 'lib/advanced_billing/models/webhook.rb', line 196

def to_custom_last_error_at
  DateTimeHelper.to_rfc3339(last_error_at)
end

#to_custom_last_sent_atObject



204
205
206
# File 'lib/advanced_billing/models/webhook.rb', line 204

def to_custom_last_sent_at
  DateTimeHelper.to_rfc3339(last_sent_at)
end