Sha256: d11097bef6b65e90f7391554d7db96e2de05caec919ba940ee7184e20e0b8a9e
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 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}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
frm_mercury-0.1.4 | lib/frm_mercury/sender.rb |