stella_gcm_xmpp 0.0.1beta

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/stella_gcm_xmpp.rb +67 -0
  3. metadata +71 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68d3f2777ca4b106cae5ef6e5c2c04dddf75ed3f
4
+ data.tar.gz: a3e39945cf8eed4ee93d198ccaf67b6290fca955
5
+ SHA512:
6
+ metadata.gz: a2c8ce560fdddcedae657e9415ca9064dd0069b5531e8151d937633466d47aa40fc65a8cf58980440397800899214373e74ff68d1ff348995de1f6c841db177c
7
+ data.tar.gz: 79afc6c4b2979c2d9b152e838f222978ed9b9a16561053ddb72af5b1756afd7e8c28dffb798858b4557302a84cc32f305e5f91c5a656ff023367da277d2d0c66
@@ -0,0 +1,67 @@
1
+ require 'xmpp4r/client'
2
+ require 'active_support/json'
3
+ require 'active_support/core_ext/hash'
4
+
5
+ class StellaGcmXmpp
6
+ def initialize(id, password, debug = false, log = false)
7
+ @id = id
8
+ @password = password
9
+ @log = log
10
+ Jabber::debug = debug
11
+ end
12
+ def connect
13
+ jid = Jabber::JID::new(@id)
14
+
15
+ @client = Jabber::Client::new(jid)
16
+ @client.use_ssl = true
17
+ @client.connect("gcm.googleapis.com", 5235)
18
+ @client.auth(@password)
19
+ end
20
+ def callback(function = nil)
21
+ @client.add_message_callback do |m|
22
+ begin
23
+ result = Hash.from_xml(m.to_s).with_indifferent_access
24
+ rescue
25
+ return self.fail
26
+ end
27
+ begin
28
+ data = JSON.parse(result[:message][:gcm]).with_indifferent_access
29
+ rescue
30
+ return self.fail
31
+ end
32
+ if data[:message_type] == 'ack'
33
+ print "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] GCM send Success id: #{data[:message_id]}\n" if @log && data[:message_id].to_s != 'BLANK_STABLE_PACKET'
34
+ else
35
+ print "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] GCM send Failed id: #{data[:message_id]} error: #{data[:error]}\n" if @log && data[:message_id].to_s != 'BLANK_STABLE_PACKET'
36
+ end
37
+ call(function) unless function.nil?
38
+ end
39
+ end
40
+ def fail
41
+ print "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] GCM send Critical Error\n" if @log
42
+ end
43
+ def send(to, message_id, data)
44
+ json = {:to => to,
45
+ :message_id => message_id,
46
+ :data => data,
47
+ :time_to_live => 600,
48
+ :delay_while_idle => false}
49
+ msg = "<message id=\"\">
50
+ <gcm xmlns=\"google:mobile:data\">
51
+ #{json.to_json}
52
+ </gcm>
53
+ </message>"
54
+ @client.send msg
55
+ end
56
+ def disconnect
57
+ @client.close
58
+ @client = nil
59
+ end
60
+ def reconnect
61
+ self.reconnect
62
+ self.connect
63
+ end
64
+ def stable_blank
65
+ self.send("NULL", "BLANK_STABLE_PACKET", {:type => nil})
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stella_gcm_xmpp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1beta
5
+ platform: ruby
6
+ authors:
7
+ - Haru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xmpp4r
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: ''
42
+ email: aqure84@naver.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/stella_gcm_xmpp.rb
48
+ homepage: http://www.forelf.com
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '1.9'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.3.6
65
+ requirements: []
66
+ rubyforge_project: stella_gcm_xmpp
67
+ rubygems_version: 2.2.2
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: ''
71
+ test_files: []