Class: Pushing::Adapters::FcmGemAdapter
- Inherits:
-
Object
- Object
- Pushing::Adapters::FcmGemAdapter
- Defined in:
- lib/pushing/adapters/fcm/fcm_gem_adapter.rb
Constant Summary collapse
- SUCCESS_CODES =
(200..299).freeze
Instance Attribute Summary collapse
-
#server_key ⇒ Object
readonly
Returns the value of attribute server_key.
Instance Method Summary collapse
-
#initialize(fcm_settings) ⇒ FcmGemAdapter
constructor
A new instance of FcmGemAdapter.
- #push!(notification) ⇒ Object
Constructor Details
#initialize(fcm_settings) ⇒ FcmGemAdapter
Returns a new instance of FcmGemAdapter.
14 15 16 |
# File 'lib/pushing/adapters/fcm/fcm_gem_adapter.rb', line 14 def initialize(fcm_settings) @server_key = fcm_settings.server_key end |
Instance Attribute Details
#server_key ⇒ Object (readonly)
Returns the value of attribute server_key.
12 13 14 |
# File 'lib/pushing/adapters/fcm/fcm_gem_adapter.rb', line 12 def server_key @server_key end |
Instance Method Details
#push!(notification) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pushing/adapters/fcm/fcm_gem_adapter.rb', line 18 def push!(notification) json = notification.payload ids = json.delete(:registration_ids) || Array(json.delete(:to)) response = FCM.new(server_key).send(ids, json) if SUCCESS_CODES.include?(response[:status_code]) FcmResponse.new(response.slice(:body, :headers, :status_code).merge(raw_response: response)) else raise "#{response[:response]} (response body: #{response[:body]})" end rescue => cause resopnse = FcmResponse.new(response.slice(:body, :headers, :status_code).merge(raw_response: response)) if response error = Pushing::FcmDeliveryError.new("Error while trying to send push notification: #{cause.}", resopnse, notification) raise error, error., cause.backtrace end |