Skip to content

Instantly share code, notes, and snippets.

@tasandberg
Created April 23, 2017 22:54
Show Gist options
  • Save tasandberg/ac6c49a4911a971a52f5729c95db8fa1 to your computer and use it in GitHub Desktop.
Save tasandberg/ac6c49a4911a971a52f5729c95db8fa1 to your computer and use it in GitHub Desktop.
Ruby Firebase Cloud Messaging Post Request with HTTParty
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