Class: SimpleConnect::Responses::EventResponse

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

Overview

Wraps the ‘events.detail` success payload. Holds the event-log row and, optionally, a nested `MessageResponse` if a WhatsApp message is linked to the event.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ EventResponse

Returns a new instance of EventResponse.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/simple_connect/responses/event_response.rb', line 12

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.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def created_at
  @created_at
end

#error_textObject (readonly)

Returns the value of attribute error_text.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def error_text
  @error_text
end

#event_idObject (readonly)

Returns the value of attribute event_id.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def event_id
  @event_id
end

#event_keyObject (readonly)

Returns the value of attribute event_key.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def event_key
  @event_key
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def message
  @message
end

#occurred_atObject (readonly)

Returns the value of attribute occurred_at.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def occurred_at
  @occurred_at
end

#payloadObject (readonly)

Returns the value of attribute payload.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def payload
  @payload
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def status
  @status
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



9
10
11
# File 'lib/simple_connect/responses/event_response.rb', line 9

def updated_at
  @updated_at
end

Instance Method Details

#dispatched?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/simple_connect/responses/event_response.rb', line 27

def dispatched?
  @status == "dispatched"
end

#failed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/simple_connect/responses/event_response.rb', line 31

def failed?
  @status == "failed"
end

#message?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/simple_connect/responses/event_response.rb', line 39

def message?
  !@message.nil?
end

#skipped?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/simple_connect/responses/event_response.rb', line 35

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

#to_hObject



47
48
49
# File 'lib/simple_connect/responses/event_response.rb', line 47

def to_h
  @json.dup
end

#used_previous_secret?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/simple_connect/responses/event_response.rb', line 43

def used_previous_secret?
  @used_previous_secret
end