class RubyPushNotifications::FCM::FCMConnection
Encapsulates a connection to the FCM
service Responsible for final connection with the service.
@author Carlos Alonso
Constants
- AUTHORIZATION_HEADER
@private Authorization HTTP Header String
- CONTENT_TYPE_HEADER
@private Content-Type HTTP Header string
- FCM_URL
@private The URL of the Android
FCM
endpoint- GROUP_NOTIFICATION_BASE_URI
- JSON_CONTENT_TYPE
@private Application/JSON content type
Public Class Methods
post(notification, key)
click to toggle source
Issues a POST request to the FCM
send endpoint to submit the given notifications.
@param notification [String]. The text to POST @param key [String]. The FCM
sender id to use
(https://developer.android.com/google/gcm/gcm.html#senderid)
@return [FCMResponse]. The FCMResponse
that encapsulates the received response
# File lib/ruby-push-notifications/fcm/fcm_connection.rb, line 36 def self.post(notification, key) headers = { CONTENT_TYPE_HEADER => JSON_CONTENT_TYPE, AUTHORIZATION_HEADER => "key=#{key}" } params = { body: notification, headers: { AUTHORIZATION_HEADER => "key=#{key}", CONTENT_TYPE_HEADER => JSON_CONTENT_TYPE } } fcm_request = FCMRequest.new(params) response = fcm_request.make_request # puts '*' * 10 # puts response # puts '*' * 10 FCMResponse.new response.code.to_i, response.body end