Class: Rpush::Daemon::Adm::Delivery
- Includes:
- MultiJsonHelper
- Defined in:
- lib/rpush/daemon/adm/delivery.rb
Overview
Constant Summary collapse
- AMAZON_TOKEN_URI =
Oauth2.0 token endpoint. This endpoint is used to request authorization tokens.
URI.parse('https://api.amazon.com/auth/O2/token')
- AMAZON_ADM_URL =
ADM services endpoint. This endpoint is used to perform ADM requests.
'https://api.amazon.com/messaging/registrations/%s/messages'
- ACCESS_TOKEN_REQUEST_DATA =
Data used to request authorization tokens.
{ "grant_type" => "client_credentials", "scope" => "messaging:push" }
Instance Method Summary collapse
-
#initialize(app, http, notification, batch) ⇒ Delivery
constructor
A new instance of Delivery.
- #perform ⇒ Object
Methods included from MultiJsonHelper
#multi_json_dump, #multi_json_load
Methods inherited from Delivery
#mark_batch_delivered, #mark_batch_failed, #mark_batch_retryable, #mark_delivered, #mark_failed, #mark_retryable, #mark_retryable_exponential
Methods included from Loggable
#log_debug, #log_error, #log_info, #log_warn
Methods included from Reflectable
Constructor Details
#initialize(app, http, notification, batch) ⇒ Delivery
Returns a new instance of Delivery.
17 18 19 20 21 22 23 24 |
# File 'lib/rpush/daemon/adm/delivery.rb', line 17 def initialize(app, http, notification, batch) @app = app @http = http @notification = notification @batch = batch @sent_registration_ids = [] @failed_registration_ids = {} end |
Instance Method Details
#perform ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rpush/daemon/adm/delivery.rb', line 26 def perform @notification.registration_ids.each do |registration_id| handle_response(do_post(registration_id), registration_id) end if @sent_registration_ids.empty? fail Rpush::DeliveryError.new(nil, @notification.id, describe_errors) else unless @failed_registration_ids.empty? @notification.error_description = describe_errors Rpush::Daemon.store.update_notification(@notification) end mark_delivered end rescue Rpush::RateLimitError => error handle_rate_limited(error) rescue Rpush::RetryableError => error handle_retryable(error) rescue SocketError => error mark_retryable(@notification, Time.now + 10.seconds, error) raise rescue StandardError => error mark_failed(error) raise ensure @batch.notification_processed end |