Class: RubyPushNotifications::FCM::FCMConnection
- Inherits:
-
Object
- Object
- RubyPushNotifications::FCM::FCMConnection
- Defined in:
- lib/ruby-push-notifications/fcm/fcm_connection.rb
Overview
Encapsulates a connection to the FCM service Responsible for final connection with the service.
Constant Summary collapse
- FCM_URL =
Credits: github.com/calos0921 - for this url change to FCM std
'https://fcm.googleapis.com/fcm/send'
- CONTENT_TYPE_HEADER =
'Content-Type'
- JSON_CONTENT_TYPE =
'application/json'
- AUTHORIZATION_HEADER =
'Authorization'
Class Method Summary collapse
-
.post(notification, key, options = {}) ⇒ FCMResponse
Issues a POST request to the FCM send endpoint to submit the given notifications.
Class Method Details
.post(notification, key, options = {}) ⇒ FCMResponse
Issues a POST request to the FCM send endpoint to submit the given notifications.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruby-push-notifications/fcm/fcm_connection.rb', line 38 def self.post(notification, key, = {}) headers = { CONTENT_TYPE_HEADER => JSON_CONTENT_TYPE, AUTHORIZATION_HEADER => "key=#{key}" } url = URI.parse .fetch(:url, FCM_URL) http = Net::HTTP.new url.host, url.port http.use_ssl = url.scheme == 'https' http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.open_timeout = .fetch(:open_timeout, 30) http.read_timeout = .fetch(:read_timeout, 30) response = http.post url.path, notification, headers FCMResponse.new response.code.to_i, response.body end |