Class: Urbanairship::CustomEvents::CustomEventResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanairship/custom_events/custom_event.rb

Overview

Response to a successful custom event creation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body: nil, code: nil) ⇒ CustomEventResponse

Returns a new instance of CustomEventResponse.



39
40
41
42
43
44
# File 'lib/urbanairship/custom_events/custom_event.rb', line 39

def initialize(body: nil, code: nil)
  @payload = (body.nil? || body.empty?) ? {} : body
  @ok = payload['ok']
  @operation_id = payload['operationId']
  @status_code = code
end

Instance Attribute Details

#okObject (readonly)

Returns the value of attribute ok.



37
38
39
# File 'lib/urbanairship/custom_events/custom_event.rb', line 37

def ok
  @ok
end

#operation_idObject (readonly)

Returns the value of attribute operation_id.



37
38
39
# File 'lib/urbanairship/custom_events/custom_event.rb', line 37

def operation_id
  @operation_id
end

#payloadObject (readonly)

Returns the value of attribute payload.



37
38
39
# File 'lib/urbanairship/custom_events/custom_event.rb', line 37

def payload
  @payload
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



37
38
39
# File 'lib/urbanairship/custom_events/custom_event.rb', line 37

def status_code
  @status_code
end

Instance Method Details

#formatObject

String Formatting of the CustomEventResponse

Returns:

  • (Object)

    String Formatted CustomEventResponse



49
50
51
# File 'lib/urbanairship/custom_events/custom_event.rb', line 49

def format
  "Received [#{status_code}] response code.\nBody:\n#{formatted_body}"
end

#formatted_bodyObject



53
54
55
56
57
# File 'lib/urbanairship/custom_events/custom_event.rb', line 53

def formatted_body
  payload
    .map { |key, value| "#{key}:\t#{value.to_s || 'None'}" }
    .join("\n")
end