Created
April 23, 2017 22:54
-
-
Save tasandberg/ac6c49a4911a971a52f5729c95db8fa1 to your computer and use it in GitHub Desktop.
Ruby Firebase Cloud Messaging Post Request with HTTParty
This file contains 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
include HTTParty | |
# The kicker here was I needed to turn the 'body' of the request into a JSON string, | |
# I had assumed HTTParty would JSONify any PORO passed in. WRONG! | |
opts = { | |
headers: { | |
'Authorization' => "key=#{ENV['FIREBASE_API_KEY'}", | |
'Content-Type' => 'application/json' | |
}, | |
body: { | |
notification: { | |
title: 'testaaang', | |
body: 'hurp deeerrrp' | |
}, | |
registration_ids: ['your recipient id'] | |
}.to_json | |
} | |
url = "https://fcm.googleapis.com/fcm/send" | |
self.class.post(url, opts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment