Sha256: 86bbb2347f34b304880c3bbbcd2fe72c7e229d422dfe89163ed3d4a9401a1f84
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
module FrmMercury class Sender def self.send(to=nil, title=nil, body=nil, sound=nil, data=nil) config = FrmMercury.configuration require 'uri' require 'net/http' require 'net/https' require 'json' key = to.kind_of?(Array) ? "registration_ids" : "to" params = { "#{key}": to, "notification": { "title": title.nil? ? "Testing notification" : title, "body": body.nil? ? "This is a test push notification, liking it?" : body, "mutable_content": true, "sound": sound.nil? ? "enabled" : sound }, "data": data }.to_json uri = URI.parse("https://fcm.googleapis.com/fcm/send") https = Net::HTTP.new(uri.host,uri.port) https.use_ssl = true req = Net::HTTP::Post.new(uri.path, initheader = {"Content-Type" => "application/json", "Authorization" => "key=#{config.get_api_key}"}) req.body = params res = https.request(req) puts "Response #{res.code} #{res.message}: #{res.body}" res end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
frm_mercury-0.1.5 | lib/frm_mercury/sender.rb |