Class: ReductoAI::Webhooks::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/reducto_ai/webhooks/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/reducto_ai/webhooks/event.rb', line 8

def headers
  @headers
end

#payloadObject (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

Returns:

  • (Boolean)


40
41
42
# File 'lib/reducto_ai/webhooks/event.rb', line 40

def completed?
  ReductoAI::JobStatus.completed?(status)
end

#failed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/reducto_ai/webhooks/event.rb', line 44

def failed?
  ReductoAI::JobStatus.failed?(status)
end

#job_idObject



24
25
26
# File 'lib/reducto_ai/webhooks/event.rb', line 24

def job_id
  payload["job_id"]
end

#metadataObject



32
33
34
# File 'lib/reducto_ai/webhooks/event.rb', line 32

def 
  payload["metadata"] || {}
end

#normalized_statusObject



36
37
38
# File 'lib/reducto_ai/webhooks/event.rb', line 36

def normalized_status
  ReductoAI::JobStatus.normalize_status(status)
end

#statusObject



28
29
30
# File 'lib/reducto_ai/webhooks/event.rb', line 28

def status
  payload["status"]
end

#svix_idObject



20
21
22
# File 'lib/reducto_ai/webhooks/event.rb', line 20

def svix_id
  headers["svix-id"] || headers["webhook-id"]
end

#to_hObject



48
49
50
# File 'lib/reducto_ai/webhooks/event.rb', line 48

def to_h
  payload
end