Class: Polar::Webhooks::Event
- Inherits:
-
Object
- Object
- Polar::Webhooks::Event
- Defined in:
- lib/polar/webhooks.rb
Overview
Webhook event wrapper class
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#raw_payload ⇒ Object
readonly
Returns the value of attribute raw_payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #benefit_event? ⇒ Boolean
- #customer_event? ⇒ Boolean
-
#initialize(payload) ⇒ Event
constructor
A new instance of Event.
- #order_event? ⇒ Boolean
- #payment_event? ⇒ Boolean
- #subscription_event? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(payload) ⇒ Event
Returns a new instance of Event.
134 135 136 137 138 139 140 141 142 |
# File 'lib/polar/webhooks.rb', line 134 def initialize(payload) @raw_payload = payload.is_a?(String) ? payload : payload.to_json parsed = payload.is_a?(String) ? JSON.parse(payload) : payload @id = parsed['id'] @type = parsed['type'] || parsed['event_type'] @created_at = parsed['created_at'] ? Time.parse(parsed['created_at']) : nil @data = parsed['data'] || parsed end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
132 133 134 |
# File 'lib/polar/webhooks.rb', line 132 def created_at @created_at end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
132 133 134 |
# File 'lib/polar/webhooks.rb', line 132 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
132 133 134 |
# File 'lib/polar/webhooks.rb', line 132 def id @id end |
#raw_payload ⇒ Object (readonly)
Returns the value of attribute raw_payload.
132 133 134 |
# File 'lib/polar/webhooks.rb', line 132 def raw_payload @raw_payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
132 133 134 |
# File 'lib/polar/webhooks.rb', line 132 def type @type end |
Instance Method Details
#benefit_event? ⇒ Boolean
160 161 162 |
# File 'lib/polar/webhooks.rb', line 160 def benefit_event? type&.start_with?('benefit.') end |
#customer_event? ⇒ Boolean
156 157 158 |
# File 'lib/polar/webhooks.rb', line 156 def customer_event? type&.start_with?('customer.') end |
#order_event? ⇒ Boolean
148 149 150 |
# File 'lib/polar/webhooks.rb', line 148 def order_event? type&.start_with?('order.') end |
#payment_event? ⇒ Boolean
152 153 154 |
# File 'lib/polar/webhooks.rb', line 152 def payment_event? type&.start_with?('payment.') end |
#subscription_event? ⇒ Boolean
144 145 146 |
# File 'lib/polar/webhooks.rb', line 144 def subscription_event? type&.start_with?('subscription.') end |
#to_h ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/polar/webhooks.rb', line 164 def to_h { id: id, type: type, created_at: created_at, data: data } end |