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.message}", resopnse, notification)
raise error, error.message, cause.backtrace
end
|