notify_fcm 0.0.1

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/notify_fcm.rb +49 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b03849b1278bd9458988fd39bbf3e2c3affc0aa
4
+ data.tar.gz: bd7e3a3fdd0b59bb5d1c5a5ffe1f28f4961ed11d
5
+ SHA512:
6
+ metadata.gz: db31f59f3aa369de08313d91d55733ec83442735e0b49465721de542b0d8ccd37a2742d07883f4abd85b2c9258ef753581bd0d1cf84977275269e1954b18eaa2
7
+ data.tar.gz: 62546bd60735223f8ec7d957729e6517d09736ad67a39c0773f87b59f25f2adbddde73a99c2ce13ff3cf7d82f95a25af625b579e12b7aa5365f3dc6808a9e16f
data/lib/notify_fcm.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'httparty'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ class NOTIFY_FCM
6
+ include HTTParty
7
+ attr_accessor :body, :title
8
+ base_uri 'https://android.googleapis.com/gcm'
9
+ # constants
10
+ NOTIFICATION_BASE_URI = 'https://android.googleapis.com/gcm'
11
+
12
+ def initialize(api_key, options = {})
13
+ @api_key = api_key
14
+ @options = options
15
+ end
16
+
17
+ def send_notification(registration_ids, options = {})
18
+
19
+ raise ArgumentError, 'Api Key not Found' unless !@api_key.nil?
20
+ raise ArgumentError, 'Body is missing' unless !body.nil?
21
+
22
+ message = message_body()
23
+ body = build_body(registration_ids, message)
24
+ params = {
25
+ body: body.to_json,
26
+ headers: {
27
+ 'Authorization' => "key=#{@api_key}",
28
+ 'Content-Type' => 'application/json'
29
+ }
30
+ }
31
+
32
+ response = self.class.post('/send', params.merge(@options))
33
+ return response
34
+ # build_response(response, registration_ids)
35
+ end
36
+
37
+ alias send send_notification
38
+
39
+ def build_body(registration_ids, options = {})
40
+ { registration_ids: registration_ids }.merge(options)
41
+ end
42
+
43
+ def message_body()
44
+ {notification: { body: body, title: title}}
45
+ end
46
+
47
+
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notify_fcm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vipin Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple hello world gem
14
+ email: buffercoder@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/notify_fcm.rb
20
+ homepage: http://rubygems.org/gems/hola
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Firebase Push Notification
44
+ test_files: []