Class: ReductoAI::Webhooks::Event
- Inherits:
-
Object
- Object
- ReductoAI::Webhooks::Event
- Defined in:
- lib/reducto_ai/webhooks/event.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(payload, headers: {}) ⇒ Event
constructor
A new instance of Event.
- #job_id ⇒ Object
- #metadata ⇒ Object
- #normalized_status ⇒ Object
- #status ⇒ Object
- #svix_id ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(payload, headers: {}) ⇒ Event
Returns a new instance of Event.
15 16 17 18 |
# File 'lib/reducto_ai/webhooks/event.rb', line 15 def initialize(payload, headers: {}) @payload = stringify_keys(payload || {}) @headers = stringify_keys(headers || {}) end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/reducto_ai/webhooks/event.rb', line 8 def headers @headers end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
8 9 10 |
# File 'lib/reducto_ai/webhooks/event.rb', line 8 def payload @payload end |
Class Method Details
.parse(payload, headers: {}) ⇒ Object
10 11 12 13 |
# File 'lib/reducto_ai/webhooks/event.rb', line 10 def self.parse(payload, headers: {}) parsed_payload = payload.is_a?(String) ? JSON.parse(payload) : payload new(parsed_payload, headers: headers) end |
Instance Method Details
#completed? ⇒ Boolean
40 41 42 |
# File 'lib/reducto_ai/webhooks/event.rb', line 40 def completed? ReductoAI::JobStatus.completed?(status) end |
#failed? ⇒ Boolean
44 45 46 |
# File 'lib/reducto_ai/webhooks/event.rb', line 44 def failed? ReductoAI::JobStatus.failed?(status) end |
#job_id ⇒ Object
24 25 26 |
# File 'lib/reducto_ai/webhooks/event.rb', line 24 def job_id payload["job_id"] end |
#metadata ⇒ Object
32 33 34 |
# File 'lib/reducto_ai/webhooks/event.rb', line 32 def payload["metadata"] || {} end |
#normalized_status ⇒ Object
36 37 38 |
# File 'lib/reducto_ai/webhooks/event.rb', line 36 def normalized_status ReductoAI::JobStatus.normalize_status(status) end |
#status ⇒ Object
28 29 30 |
# File 'lib/reducto_ai/webhooks/event.rb', line 28 def status payload["status"] end |
#svix_id ⇒ Object
20 21 22 |
# File 'lib/reducto_ai/webhooks/event.rb', line 20 def svix_id headers["svix-id"] || headers["webhook-id"] end |
#to_h ⇒ Object
48 49 50 |
# File 'lib/reducto_ai/webhooks/event.rb', line 48 def to_h payload end |