Class: Pushing::Adapters::ApnoticAdapter
- Inherits:
-
Object
- Object
- Pushing::Adapters::ApnoticAdapter
- Defined in:
- lib/pushing/adapters/apn/apnotic_adapter.rb
Constant Summary collapse
- APS_DICTIONARY_KEYS =
%i[ alert badge sound content_available category url_args mutable_content ].freeze
- DEFAULT_ADAPTER_OPTIONS =
{ size: Process.getrlimit(Process::RLIMIT_NOFILE).first / 8 }.freeze
Instance Attribute Summary collapse
-
#connection_pool ⇒ Object
readonly
Returns the value of attribute connection_pool.
Instance Method Summary collapse
-
#initialize(apn_settings) ⇒ ApnoticAdapter
constructor
A new instance of ApnoticAdapter.
- #push!(notification) ⇒ Object
Constructor Details
#initialize(apn_settings) ⇒ ApnoticAdapter
Returns a new instance of ApnoticAdapter.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pushing/adapters/apn/apnotic_adapter.rb', line 25 def initialize(apn_settings) = case apn_settings.connection_scheme.to_sym when :token { auth_method: :token, cert_path: apn_settings.certificate_path, key_id: apn_settings.key_id, team_id: apn_settings.team_id } when :certificate { cert_path: apn_settings.certificate_path, cert_pass: apn_settings.certificate_password } else raise "Unknown connection scheme #{apn_settings.connection_scheme.inspect}. " \ "The connection scheme should either be :token or :certificate." end @connection_pool = { development: Apnotic::ConnectionPool.development(, DEFAULT_ADAPTER_OPTIONS), production: Apnotic::ConnectionPool.new(, DEFAULT_ADAPTER_OPTIONS), } end |
Instance Attribute Details
#connection_pool ⇒ Object (readonly)
Returns the value of attribute connection_pool.
23 24 25 |
# File 'lib/pushing/adapters/apn/apnotic_adapter.rb', line 23 def connection_pool @connection_pool end |
Instance Method Details
#push!(notification) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pushing/adapters/apn/apnotic_adapter.rb', line 50 def push!(notification) = Apnotic::Notification.new(notification.device_token) json = notification.payload.dup if aps = json.delete(:aps) APS_DICTIONARY_KEYS.each {|key| .instance_variable_set(:"@#{key}", aps[key]) } end .custom_payload = json .apns_id = notification.headers[:'apns-id'] || .apns_id .expiration = notification.headers[:'apns-expiration'].to_i .priority = notification.headers[:'apns-priority'] .topic = notification.headers[:'apns-topic'] .apns_collapse_id = notification.headers[:'apns-collapse-id'] response = connection_pool[notification.environment].with {|connection| connection.push() } if !response raise "Timeout sending a push notification" elsif response.status != '200' raise response.body.to_s end ApnResponse.new(response) rescue => cause response = response ? ApnResponse.new(response) : nil error = Pushing::ApnDeliveryError.new("Error while trying to send push notification: #{cause.}", response, notification) raise error, error., cause.backtrace end |