stella_gcm 0.2.1 → 0.2.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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stella_gcm.rb +43 -0
  3. metadata +2 -2
  4. data/lib/stella/gcm.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86be6814a300253fc60b70e7729a25d84c7c05e0
4
- data.tar.gz: 012bcf794d265750ced9caa1e70de01e63c13556
3
+ metadata.gz: 346c78764c3e91a83c2c7154fb333f466e3ae673
4
+ data.tar.gz: 4d5e7637fb3394e0896154d12cba209ac1b0594d
5
5
  SHA512:
6
- metadata.gz: e273e6b2740b8f63190af666df397750f5ee34e77ef47e47be5472ad36582df874a1659a21ad2a96926d6a8a2bbe7b6c36f481449ebd494766d96b4a781a2ef8
7
- data.tar.gz: 1dcf40aea7dc693509ede845dd14449f77a73fdafd007dc6cdd74c1cf1418a58397f3636189c2e1f37cc41fb26a8f01496a55ba06957ef9a6abe01aeb0f63bc6
6
+ metadata.gz: a425b83648cbab212f1e6ac4ce32c4c91a68989f099d61ef447bf2c532ca189e53606cc8eeaedabbba65dadd37803674243ea46bacb1479b129fbf0d094c5047
7
+ data.tar.gz: c2430c299675421de839c34728f671800cc2ea2a3a4ab4674572708184bf1c8602b531848f894bbf68759936d233ebefd2db2093292e0eaac972ee2d73d4a92c
data/lib/stella_gcm.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'net/http/persistent'
2
+ require 'active_support/json'
3
+ class StellaGCM
4
+ URL = 'https://android.googleapis.com/gcm/send'
5
+
6
+ def initialize(private_key, option = nil)
7
+ @http = Net::HTTP::Persistent.new 'StellaGcm'
8
+ @http.idle_timeout = option.nil? ? 1 :option[:idle_timeout]
9
+ @http.open_timeout = option.nil? ? 30 :option[:open_timeout]
10
+ @http.read_timeout = option.nil? ? 60 :option[:read_timeout]
11
+ @http.headers['Authorization'] = "key=#{private_key}"
12
+ @http.headers['Content-Type'] = "application/json"
13
+ end
14
+
15
+ def send_notification(ids, option)
16
+ gcm_server_uri = URI URL
17
+ request = Net::HTTP::Post.new gcm_server_uri.path
18
+ request.body = self.body(ids, option).to_json
19
+
20
+ begin
21
+ response = @http.request gcm_server_uri, request
22
+ rescue
23
+ return {:code => 404,
24
+ :success => false,
25
+ :msg => "GCM Server Not Connected."}
26
+ end
27
+
28
+ begin
29
+ body = ActiveSupport::JSON.decode(response.body).with_indifferent_access
30
+ rescue
31
+ return {:code => 500,
32
+ :success => false,
33
+ :msg => "Json Parse failed Return Value."}
34
+ end
35
+
36
+ {:code => response.code.to_i,
37
+ :success => body[:success].to_i == 1}
38
+ end
39
+
40
+ def body(ids, option)
41
+ {:registration_ids => ids}.merge!(option)
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stella_gcm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haru
@@ -44,7 +44,7 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - lib/stella/gcm.rb
47
+ - lib/stella_gcm.rb
48
48
  homepage: http://www.forelf.com
49
49
  licenses:
50
50
  - GPL-2
data/lib/stella/gcm.rb DELETED
@@ -1,45 +0,0 @@
1
- require 'net/http/persistent'
2
- require 'active_support/json'
3
- module Stella
4
- class GCM
5
- URL = 'https://android.googleapis.com/gcm/send'
6
-
7
- def initialize(private_key, option = nil)
8
- @http = Net::HTTP::Persistent.new 'StellaGcm'
9
- @http.idle_timeout = option.nil? ? 1 :option[:idle_timeout]
10
- @http.open_timeout = option.nil? ? 30 :option[:open_timeout]
11
- @http.read_timeout = option.nil? ? 60 :option[:read_timeout]
12
- @http.headers['Authorization'] = "key=#{private_key}"
13
- @http.headers['Content-Type'] = "application/json"
14
- end
15
-
16
- def send_notification(ids, option)
17
- gcm_server_uri = URI URL
18
- request = Net::HTTP::Post.new gcm_server_uri.path
19
- request.body = self.body(ids, option).to_json
20
-
21
- begin
22
- response = @http.request gcm_server_uri, request
23
- rescue
24
- return {:code => 404,
25
- :success => false,
26
- :msg => "GCM Server Not Connected."}
27
- end
28
-
29
- begin
30
- body = ActiveSupport::JSON.decode(response.body).with_indifferent_access
31
- rescue
32
- return {:code => 500,
33
- :success => false,
34
- :msg => "Json Parse failed Return Value."}
35
- end
36
-
37
- {:code => response.code.to_i,
38
- :success => body[:success].to_i == 1}
39
- end
40
-
41
- def body(ids, option)
42
- {:registration_ids => ids}.merge!(option)
43
- end
44
- end
45
- end