stella_gcm 0.0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stella/gcm.rb +45 -0
  3. metadata +42 -13
  4. data/lib/stella_gcm.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 328d79ca75e3f8d73f3c538cfd3d029a9734bd33
4
- data.tar.gz: 269415291faa36a80919b87f521674e4593c77fe
3
+ metadata.gz: 85059777cd2f699518f88beed51648aeb181dc7a
4
+ data.tar.gz: 6dcd1176e6cc9b00426258cf4dd0cb9be00ce1bb
5
5
  SHA512:
6
- metadata.gz: cd63b6e956879027ff69d622fb31d3c4f533006e5f3a362d08164da4685588d4994d60525a483ac90387b02b8840f323c46c2f5d67af5fd9c98ce2c81b92546a
7
- data.tar.gz: 4e3c3a2d6060295f86775afef6deab45568b8464b70c19ed96afa87098e5460e54e63e08a39a2c5deb08874ecb4bf0a1761b861ed5058756369c3a2a660a2721
6
+ metadata.gz: 08c5ebe882651ba2ae5d65f3e3b8e3bf74ebfe268e3f5dfe7098754a9f0892e2790ea663a7c61926f7179b25bbe7f3d3fd32a2f89b63a4d0cce2894a7d76b5ba
7
+ data.tar.gz: 95c75ed6588f8d53fad0d0bb64bff7a458d85cb85e032a272c65cc53ea499527cbf79cd87c14f963147332392e7eb78fd2d59efc3537bf9a1aa384ebcbe72a32
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.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haru
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
12
- dependencies: []
13
- description: ''
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/stella_gcm.rb
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: '0'
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: '0'
65
+ version: 1.3.6
37
66
  requirements: []
38
- rubyforge_project:
39
- rubygems_version: 2.0.3
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