Class: NotificationHub::Channels::BrowserPushNotification::Fcm
- Defined in:
- lib/notification_hub/channels/browser_push_notification/fcm.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Fcm
constructor
A new instance of Fcm.
Constructor Details
#initialize(options) ⇒ Fcm
Returns a new instance of Fcm.
9 10 11 |
# File 'lib/notification_hub/channels/browser_push_notification/fcm.rb', line 9 def initialize() super end |
Class Method Details
.send_message(event_code, data, options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/notification_hub/channels/browser_push_notification/fcm.rb', line 14 def (event_code, data, ) event = event_code.split(".") begin json_string = ActionController::Base.new. render_to_string("#{[:template_path]}/#{event[0]}/#{event[1]}", locals: data) json_object = JSON.parse(json_string) json_object[:to] = [:push_token] json_object[:registration_ids] = [:push_tokens] response = HTTParty.post("https://fcm.googleapis.com/fcm/send", { :body => json_object.to_json, :headers => { 'Content-Type' => 'application/json', 'Authorization' => "key=#{[:server_key]}" }, :timeout => [:timeout_time] }) raise "BrowserPushNotification::FCM Error: #{response.body}" if response.code != 200 rescue => exception raise "BrowserPushNotification::FCM Error: #{exception.}" end end |