pubsub-connect 0.0.2

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/pubsub.rb +46 -0
  3. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d526a17d68b2f8d49dd83974884f2b584976d52
4
+ data.tar.gz: b20f276bcc969786455ed772a4cb65d1008e66d9
5
+ SHA512:
6
+ metadata.gz: ee75f924a59a22dfa1589ee592122a302e1be527ba3b93ef5b7155f9d6b0486f5a5ac21acfac82ce0364ecbe59bc5abd14021eeb271a6f2281e16f1d07f55233
7
+ data.tar.gz: 4ac6e628c440498375ca38f65c6872f4f84b3de6b2b2d25ac8af567a40343f725776345d915b282f0cd4981a2033041fef63f7e93d985f430dec8c1c5c07e909
data/lib/pubsub.rb ADDED
@@ -0,0 +1,46 @@
1
+ #PubSub notification fior Android and iOS devices
2
+ #for detail please refer https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/create#body.aspect
3
+ module Pubsub
4
+
5
+ class Notification
6
+ attr_accessor :json_data
7
+
8
+ def initialize(data)
9
+ #data must be an hash object
10
+ #example {to: "/topics/News", data: {message: "testing one two three"}}
11
+
12
+ if data.blank?
13
+ raise "Data packet is missing."
14
+ elsif !data.has_key?(:to)
15
+ raise "Invalid topic or topic key 'to' is missing."
16
+ end
17
+
18
+ @json_data = JSON.pretty_generate(data)
19
+ end
20
+
21
+ def broadcast
22
+ begin
23
+ req = Curl::Easy.http_post("https://gcm-http.googleapis.com/gcm/send", @json_data) do |curl|
24
+ curl.headers["Content-Type"] = "application/json"
25
+ curl.headers["Authorization"] = "key=#{GCM_API_KEY}"
26
+ end
27
+ rescue Exception => e
28
+ Rails.logger.info("======================")
29
+ Rails.logger.info e.message
30
+ #error log here
31
+ raise e.message
32
+ end
33
+ #call below function if you need to log notification response
34
+ # record_notification_logs(req)
35
+
36
+ return JSON.parse req.body_str
37
+ end
38
+
39
+ def record_notification_logs(req)
40
+ #put your code here to record notification response
41
+ Rails.logger.info JSON.parse req.body_str
42
+ end
43
+
44
+ end
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubsub-connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Lareb Nawab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A lightweight ruby gem, which enables developers to send messages between
28
+ servers and client apps (Android & iOS).
29
+ email:
30
+ - lareb.indore@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/pubsub.rb
36
+ homepage: https://github.com/lareb/pubsub-connect
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.4.6
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A lightweight ruby gem, which enables developers to send messages between
60
+ servers and client apps (Android & iOS).
61
+ test_files: []