Class: SimpleConnect::Responses::EventResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_connect/responses/event_response.rb

Overview

Wraps the persisted event-log row and (optionally) the linked WhatsApp message. Returned from two endpoints:

* `events.detail` — the full GET payload, where the server wraps
  the log under an `"event_log"` key alongside `"message"`.
* `events.deliver` (server ≥ 0.3.0) — the same shape, embedded
  under the `"event"` key on the deliver ack so callers know
  immediately whether the event was queued (`"received"`) or
  skipped (`"skipped_paused"`, `"skipped_disabled"`, …).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ EventResponse

Returns a new instance of EventResponse.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_connect/responses/event_response.rb', line 18

def initialize(json)
  @json                 = json.is_a?(Hash) ? json : {}
  event_log             = @json["event_log"].is_a?(Hash) ? @json["event_log"] : {}
  @event_id             = event_log["event_id"]
  @event_key            = event_log["event_key"]
  @status               = event_log["status"]
  @occurred_at          = parse_time(event_log["occurred_at"])
  @created_at           = parse_time(event_log["created_at"])
  @updated_at           = parse_time(event_log["updated_at"])
  @error_text           = event_log["error_text"]
  @used_previous_secret = event_log["used_previous_secret"] == true
  @payload              = event_log["payload"].is_a?(Hash) ? event_log["payload"] : {}
  @message              = @json["message"] ? MessageResponse.new(@json["message"]) : nil
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def created_at
  @created_at
end

#error_textObject (readonly)

Returns the value of attribute error_text.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def error_text
  @error_text
end

#event_idObject (readonly)

Returns the value of attribute event_id.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def event_id
  @event_id
end

#event_keyObject (readonly)

Returns the value of attribute event_key.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def event_key
  @event_key
end

#messageObject (readonly)

Returns the value of attribute message.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def message
  @message
end

#occurred_atObject (readonly)

Returns the value of attribute occurred_at.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def occurred_at
  @occurred_at
end

#payloadObject (readonly)

Returns the value of attribute payload.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def payload
  @payload
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def status
  @status
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



15
16
17
# File 'lib/simple_connect/responses/event_response.rb', line 15

def updated_at
  @updated_at
end

Instance Method Details

#dispatched?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/simple_connect/responses/event_response.rb', line 33

def dispatched?
  @status == "dispatched"
end

#failed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/simple_connect/responses/event_response.rb', line 37

def failed?
  @status == "failed"
end

#message?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/simple_connect/responses/event_response.rb', line 45

def message?
  !@message.nil?
end

#skipped?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/simple_connect/responses/event_response.rb', line 41

def skipped?
  @status.to_s.start_with?("skipped")
end

#to_hObject



53
54
55
# File 'lib/simple_connect/responses/event_response.rb', line 53

def to_h
  @json.dup
end

#used_previous_secret?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/simple_connect/responses/event_response.rb', line 49

def used_previous_secret?
  @used_previous_secret
end