Class: Urbanairship::Push::PushResponse

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/urbanairship/push/push.rb

Overview

Response to a successful push notification send or schedule.

Constant Summary

Constants included from Common

Common::CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#apid_path, #channel_path, #compact_helper, #create_and_send_path, #custom_events_path, #device_token_path, #experiments_path, #lists_path, #named_users_path, #open_channel_path, #pipelines_path, #push_path, #reports_path, #required, #schedules_path, #segments_path, #tag_lists_path, #try_helper

Constructor Details

#initialize(http_response_body: nil, http_response_code: nil) ⇒ PushResponse

Returns a new instance of PushResponse.



194
195
196
197
198
199
200
201
# File 'lib/urbanairship/push/push.rb', line 194

def initialize(http_response_body: nil, http_response_code: nil)
  @payload = ((http_response_body.nil? || http_response_body.empty?) ? {} : http_response_body)
  @ok = @payload['ok']
  @push_ids = @payload['push_ids']
  @schedule_url = try_helper(:first, @payload['schedule_urls'])
  @operation_id = @payload['operation_id']
  @status_code = http_response_code
end

Instance Attribute Details

#okObject (readonly)

Returns the value of attribute ok.



191
192
193
# File 'lib/urbanairship/push/push.rb', line 191

def ok
  @ok
end

#operation_idObject (readonly)

Returns the value of attribute operation_id.



191
192
193
# File 'lib/urbanairship/push/push.rb', line 191

def operation_id
  @operation_id
end

#payloadObject (readonly)

Returns the value of attribute payload.



191
192
193
# File 'lib/urbanairship/push/push.rb', line 191

def payload
  @payload
end

#push_idsObject (readonly)

Returns the value of attribute push_ids.



191
192
193
# File 'lib/urbanairship/push/push.rb', line 191

def push_ids
  @push_ids
end

#schedule_urlObject (readonly)

Returns the value of attribute schedule_url.



191
192
193
# File 'lib/urbanairship/push/push.rb', line 191

def schedule_url
  @schedule_url
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



191
192
193
# File 'lib/urbanairship/push/push.rb', line 191

def status_code
  @status_code
end

Instance Method Details

#formatObject

String Formatting of the PushResponse

Returns:

  • (Object)

    String Formatted PushResponse



206
207
208
209
210
211
212
213
# File 'lib/urbanairship/push/push.rb', line 206

def format
  base = "Received [#{@status_code}] response code. \nHeaders: \tBody:\n"
  payload.each do |key, value|
    safe_value = value.to_s || 'None'
    base << "#{key}:\t#{safe_value}\n"
  end
  base
end