· 8 years ago · Dec 20, 2017, 06:24 PM
1@conn ||= Faraday.new(:url => 'https://fcm.googleapis.com') do |faraday|
2 faraday.request :url_encoded
3 faraday.response :logger
4 faraday.adapter Faraday.default_adapter
5end
6
7response = @conn.post do |req|
8 req.url '/fcm/send'
9 req.headers['Content-Type'] = 'application/json'
10 req.headers['Authorization'] = 'key= ' + secret_key
11 req.body = '{ "to": " + subscriber_id + '" }'
12end
13
14post https://fcm.googleapis.com/fcm/send
15User-Agent: "Faraday v0.9.2"
16Content-Type: "application/json"
17Authorization: "key= some_key"
18200
19content-type: "application/json; charset=UTF-8"
20date: "Wed, 20 Dec 2017 16:15:35 GMT"
21expires: "Wed, 20 Dec 2017 16:15:35 GMT"
22cache-control: "private, max-age=0"
23x-content-type-options: "nosniff"
24x-frame-options: "SAMEORIGIN"
25x-xss-protection: "1; mode=block"
26server: "GSE"
27alt-svc: "hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35""
28connection: "close"
29transfer-encoding: "chunked"
30
31function onPush(event) {
32 var title = (event.data && event.data.text()) || "Yay a message";
33
34 event.waitUntil(
35 self.registration.showNotification(title, {
36 body: "New message!",
37 icon: "/assets/test.jpg",
38 tag: "push-simple-demo-notification-tag"
39 })
40)}
41
42self.addEventListener("push", onPush);