stella_gcm 0.0.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/stella/gcm.rb +45 -0
- metadata +42 -13
- data/lib/stella_gcm.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c4992bf072d520ac19c540dbd25e11307423100
|
4
|
+
data.tar.gz: 2cb72048c1fb33099568438fc849d9a73ca37f32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c445137a3846c0a8dc1dda9ce0e7b26a8871763eed5e429224deffc6e0c880c9cc2c10839e0d14ed5d6f187beb3bd67cf080f55250dda32a7dbd031717e879a
|
7
|
+
data.tar.gz: 405153ce8d6e5d20074a421876b70d64c20b24205127302c12242b9a405c8298f7fc7331e5cdbb38432e5f85c28a5ba57dde3a6c5a1c21841e6722ee4a2feb2e
|
data/lib/stella/gcm.rb
ADDED
@@ -0,0 +1,45 @@
|
|
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
|
metadata
CHANGED
@@ -1,24 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stella_gcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Haru
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-http-persistent
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
description: GCM For HTTP
|
14
42
|
email: aqure84@naver.com
|
15
43
|
executables: []
|
16
44
|
extensions: []
|
17
45
|
extra_rdoc_files: []
|
18
46
|
files:
|
19
|
-
- lib/
|
47
|
+
- lib/stella/gcm.rb
|
20
48
|
homepage: http://www.forelf.com
|
21
|
-
licenses:
|
49
|
+
licenses:
|
50
|
+
- GPL-2
|
22
51
|
metadata: {}
|
23
52
|
post_install_message:
|
24
53
|
rdoc_options: []
|
@@ -26,18 +55,18 @@ require_paths:
|
|
26
55
|
- lib
|
27
56
|
required_ruby_version: !ruby/object:Gem::Requirement
|
28
57
|
requirements:
|
29
|
-
- -
|
58
|
+
- - ">="
|
30
59
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
60
|
+
version: '1.9'
|
32
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
62
|
requirements:
|
34
|
-
- -
|
63
|
+
- - ">="
|
35
64
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
65
|
+
version: 1.3.6
|
37
66
|
requirements: []
|
38
|
-
rubyforge_project:
|
39
|
-
rubygems_version: 2.
|
67
|
+
rubyforge_project: stella_gcm
|
68
|
+
rubygems_version: 2.2.2
|
40
69
|
signing_key:
|
41
70
|
specification_version: 4
|
42
|
-
summary:
|
71
|
+
summary: GCM Send HTTP
|
43
72
|
test_files: []
|
data/lib/stella_gcm.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'net/http/persistent'
|
2
|
-
require 'active_support/json'
|
3
|
-
|
4
|
-
class StellaGcm
|
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.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
|
13
|
-
@http.headers['Authorization'] = "key=#{private_key}"
|
14
|
-
@http.headers['Content-Type'] = "application/json"
|
15
|
-
#@http.debug_output = $stderr
|
16
|
-
end
|
17
|
-
def reconnect
|
18
|
-
@http.reconnect_ssl()
|
19
|
-
end
|
20
|
-
def send_notification(ids, option)
|
21
|
-
post_uri = URI URL
|
22
|
-
post = Net::HTTP::Post.new post_uri.path
|
23
|
-
post.body = self.body(ids, option).to_json
|
24
|
-
#post.set_form_data nil
|
25
|
-
|
26
|
-
response = @http.request post_uri, post
|
27
|
-
begin
|
28
|
-
body = ActiveSupport::JSON.decode response.body
|
29
|
-
print body
|
30
|
-
rescue
|
31
|
-
return {:code => 500,
|
32
|
-
:success => 0}
|
33
|
-
end
|
34
|
-
return {:code => response.code.to_i,
|
35
|
-
:success => (body['success'].to_i == 1)?true:false} #:results => (body['results']['error'].nil?)?"":body['results']['error']}
|
36
|
-
end
|
37
|
-
def body(ids, option)
|
38
|
-
{:registration_ids => ids}.merge!(option)
|
39
|
-
end
|
40
|
-
end
|