fcm_pusher 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/fcm_pusher.rb +44 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d4907b8aac2d5918043cdcb407bdb07ad1cb3f2
4
+ data.tar.gz: 7db69837928a543f85dbd29f415bee88af6e5b87
5
+ SHA512:
6
+ metadata.gz: 7f9ffdb0e52df59f05450adc7b36290527e2e607d64038ad4c3464893f02e05a7472431b38cd1ae533d5f193d6945d7da087713d69218b518e9cbd0579a778ef
7
+ data.tar.gz: ac48bac74c84af3bbe536287d23cfdc64129785a8c68d77d264fc628b966bb79fececde8f363230fafba2191272861c023f92029a50662b599a9c8f291995464
data/lib/fcm_pusher.rb ADDED
@@ -0,0 +1,44 @@
1
+ # This class initializes a push notification object
2
+ # to be sended as a JSON POST request to Google FCM API Server
3
+ # Use the FCM APY_KEY and the FCM_TOKEN from an user or device
4
+
5
+ require 'dotenv/load'
6
+ require 'json'
7
+ require 'net/https'
8
+ require 'uri'
9
+
10
+
11
+ class FcmPusher
12
+ FCM_BASE_URL = "https://fcm.googleapis.com/fcm/send"
13
+ FCM_API_KEY = ENV['FCM_API_KEY']
14
+ attr_accessor :fcm_token
15
+
16
+ def initialize(fcm_token)
17
+ @fcm_token = fcm_token
18
+ end
19
+
20
+ def send(title, body, icon, sound, badge, priority)
21
+ uri = URI(FCM_BASE_URL)
22
+ https = Net::HTTP.new(uri.host, uri.port)
23
+ https.use_ssl = true
24
+ request = Net::HTTP::Post.new(uri.path, {'Content-Type': 'application/json', 'Authorization': "key=#{FCM_API_KEY}"})
25
+ request.body = json_format(@fcm_token, title, body, icon, sound, badge, priority)
26
+ response = https.request(request)
27
+ puts "Finished successfully with response #{response}"
28
+ rescue => exception
29
+ puts "Failed with #{exception}"
30
+ end
31
+
32
+ def json_format(to, title, body, icon, sound, badge, priority)
33
+ { to: to,
34
+ notification: {
35
+ title: title,
36
+ body: body,
37
+ icon: icon,
38
+ badge: badge,
39
+ sound: sound
40
+ },
41
+ priority: priority
42
+ }.to_json
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fcm_pusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Amarildo Lucas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Send push notifications using the Firebase Cloud Messaging Server
28
+ email: vmarildo@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/fcm_pusher.rb
34
+ homepage: http://rubygems.org/gems/fcm_pusher
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.6.8
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: FCM Pusher
58
+ test_files: []