Class: Urbanairship::Push::ScheduledPush
- Inherits:
-
Object
- Object
- Urbanairship::Push::ScheduledPush
- Defined in:
- lib/urbanairship/push/push.rb
Constant Summary
Constants included from Common
Instance Attribute Summary collapse
-
#name ⇒ Object
writeonly
Sets the attribute name.
-
#push ⇒ Object
Returns the value of attribute push.
-
#schedule ⇒ Object
writeonly
Sets the attribute schedule.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.from_url(client: required('client'), url: required('url')) ⇒ Object
Build a Scheduled Push Notification object from its existing Scheduled Push URL.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel the Scheduled Push.
-
#initialize(client) ⇒ ScheduledPush
constructor
Initialize a Scheduled Push Object.
- #list(schedule_id: required('schedule_id')) ⇒ Object
- #payload ⇒ Object
-
#send_push ⇒ PushResponse
Schedule the Push Notification.
-
#update ⇒ Object
Update the Scheduled Push.
Methods included from Loggable
create_logger, logger, #logger
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(client) ⇒ ScheduledPush
Initialize a Scheduled Push Object
74 75 76 |
# File 'lib/urbanairship/push/push.rb', line 74 def initialize(client) @client = client end |
Instance Attribute Details
#name=(value) ⇒ Object (writeonly)
Sets the attribute name
66 67 68 |
# File 'lib/urbanairship/push/push.rb', line 66 def name=(value) @name = value end |
#push ⇒ Object
Returns the value of attribute push.
67 68 69 |
# File 'lib/urbanairship/push/push.rb', line 67 def push @push end |
#schedule=(value) ⇒ Object (writeonly)
Sets the attribute schedule
66 67 68 |
# File 'lib/urbanairship/push/push.rb', line 66 def schedule=(value) @schedule = value end |
#url ⇒ Object
Returns the value of attribute url.
67 68 69 |
# File 'lib/urbanairship/push/push.rb', line 67 def url @url end |
Class Method Details
.from_url(client: required('client'), url: required('url')) ⇒ Object
Build a Scheduled Push Notification object from its existing Scheduled Push URL
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/urbanairship/push/push.rb', line 110 def self.from_url(client: required('client'), url: required('url')) scheduled_push = ScheduledPush.new(client) response_payload = client.send_request( method: 'GET', body: nil, url: url ) payload = JSON.load(response_payload.to_json) p = Push.new(client) p.audience = payload['body']['push']['audience'] p.notification = payload['body']['push']['notification'] p.device_types = payload['body']['push']['device_types'] p. = payload['body']['push']['message'] p. = payload['body']['push']['options'] scheduled_push.name = payload['body']['name'] scheduled_push.schedule = payload['body']['schedule'] scheduled_push.push = p scheduled_push.url = url scheduled_push end |
Instance Method Details
#cancel ⇒ Object
Cancel the Scheduled Push
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/urbanairship/push/push.rb', line 136 def cancel fail ArgumentError, 'Cannot cancel ScheduledPush without a url.' if @url.nil? response = @client.send_request( method: 'DELETE', body: nil, url: @url, content_type: 'application/json' ) pr = PushResponse.new(http_response_body: response['body'], http_response_code: response['code'].to_s) logger.info { "Result of canceling scheduled push: #{@url} was a: [#{pr.status_code}]" } pr end |
#list(schedule_id: required('schedule_id')) ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/urbanairship/push/push.rb', line 168 def list(schedule_id: required('schedule_id')) fail ArgumentError, 'schedule_id must be a string' unless schedule_id.is_a? String resp = @client.send_request( method: 'GET', path: schedules_path(schedule_id) ) logger.info("Retrieved info for schedule_id #{schedule_id}") resp end |
#payload ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/urbanairship/push/push.rb', line 78 def payload compact_helper({ name: @name, schedule: @schedule, push: @push.payload }) end |
#send_push ⇒ PushResponse
Schedule the Push Notification
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/urbanairship/push/push.rb', line 92 def send_push response = @client.send_request( method: 'POST', body: JSON.dump(payload), path: schedules_path, content_type: 'application/json' ) pr = PushResponse.new(http_response_body: response['body'], http_response_code: response['code'].to_s) logger.info { pr.format } @url = pr.schedule_url pr end |
#update ⇒ Object
Update the Scheduled Push
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/urbanairship/push/push.rb', line 154 def update fail ArgumentError, 'Cannot update a ScheduledPush without a url.' if @url.nil? response = @client.send_request( method: 'PUT', body: JSON.dump(self.payload), url: @url, content_type: 'application/json' ) pr = PushResponse.new(http_response_body: response['body'], http_response_code: response['code'].to_s) logger.info { pr.format } pr end |