stella_gcm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/stella_gcm.rb +40 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 328d79ca75e3f8d73f3c538cfd3d029a9734bd33
4
+ data.tar.gz: 269415291faa36a80919b87f521674e4593c77fe
5
+ SHA512:
6
+ metadata.gz: cd63b6e956879027ff69d622fb31d3c4f533006e5f3a362d08164da4685588d4994d60525a483ac90387b02b8840f323c46c2f5d67af5fd9c98ce2c81b92546a
7
+ data.tar.gz: 4e3c3a2d6060295f86775afef6deab45568b8464b70c19ed96afa87098e5460e54e63e08a39a2c5deb08874ecb4bf0a1761b861ed5058756369c3a2a660a2721
data/lib/stella_gcm.rb ADDED
@@ -0,0 +1,40 @@
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
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stella_gcm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Haru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: aqure84@naver.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/stella_gcm.rb
20
+ homepage: http://www.forelf.com
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.0.3
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: ''
43
+ test_files: []