Last active
December 7, 2019 00:41
-
-
Save emptyflask/1654aaf0743664251b43b01166850183 to your computer and use it in GitHub Desktop.
reddit fcm question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FcmController < AppController | |
def fcm | |
result = fcm_post | |
if result.success? | |
render json: result.body | |
else | |
render json: {error: 'something failed...'} | |
end | |
end | |
private | |
def fcm_post | |
# maybe this works, I don't know anything about FCM: | |
headers = [ | |
'Authorization: key=****', | |
'Content-Type:application/json' | |
] | |
RestClient.post('https://fcm.googleapis.com/fcm/send', fcm_params.to_json, headers) | |
end | |
def fcm_alt_post | |
# otherwise, something like this might be the better way to go: | |
# (using firebase-ruby) | |
Firebase::Client.new(base_uri).push(params[:to], fcm) | |
end | |
def fcm_params | |
{ | |
to: params[:to], | |
data: { | |
notificationOptions: { | |
id: params[:id], | |
channelId: params[:channel], | |
channelName: params[:channelName], | |
channelDescription: params[:channelDescription], | |
text: params[:message], | |
title: params[:title], | |
smallIcon: 'mipmap/icon', | |
vibrate: [ 100, 500, 100, 500], | |
sound: params[:sound], | |
color: 255, | |
autoCancel: true, | |
priority: 'high' | |
} | |
} | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment