pubnub-ruby 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pubnub-ruby.rb +1 -1
- data/lib/pubnub.rb +50 -40
- metadata +33 -44
- data/LICENSE.PUBNUB +0 -27
- data/README +0 -2
- data/README.ROOT +0 -39
data/lib/pubnub-ruby.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "pubnub"
|
1
|
+
require "./pubnub.rb"
|
data/lib/pubnub.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
## www.pubnub.com - PubNub realtime push service in the cloud.
|
2
|
-
## http://www.pubnub.com/blog/ruby-push-api - Ruby Push API Blog
|
1
|
+
## www.pubnub.com - PubNub realtime push service in the cloud.
|
2
|
+
## http://www.pubnub.com/blog/ruby-push-api - Ruby Push API Blog
|
3
3
|
|
4
4
|
## PubNub Real Time Push APIs and Notifications Framework
|
5
5
|
## Copyright (c) 2010 Stephen Blum
|
@@ -12,10 +12,13 @@
|
|
12
12
|
require 'digest/md5'
|
13
13
|
require 'open-uri'
|
14
14
|
require 'uri'
|
15
|
+
require 'net/http'
|
15
16
|
require 'json'
|
16
17
|
require 'pp'
|
17
18
|
|
18
19
|
class Pubnub
|
20
|
+
MAX_RETRIES = 3
|
21
|
+
|
19
22
|
#**
|
20
23
|
#* Pubnub
|
21
24
|
#*
|
@@ -39,6 +42,9 @@ class Pubnub
|
|
39
42
|
else
|
40
43
|
@origin = 'http://' + @origin
|
41
44
|
end
|
45
|
+
|
46
|
+
uri = URI.parse(@origin)
|
47
|
+
@connection = Net::HTTP.start(uri.host, uri.port)
|
42
48
|
end
|
43
49
|
|
44
50
|
#**
|
@@ -100,7 +106,6 @@ class Pubnub
|
|
100
106
|
## Capture User Input
|
101
107
|
channel = args['channel']
|
102
108
|
callback = args['callback']
|
103
|
-
timetoken = args['timetoken'] ? args['timetoken'] : 0
|
104
109
|
|
105
110
|
## Fail if missing channel
|
106
111
|
if !channel
|
@@ -114,39 +119,36 @@ class Pubnub
|
|
114
119
|
return false
|
115
120
|
end
|
116
121
|
|
117
|
-
## Begin
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
122
|
+
## Begin Subscribe
|
123
|
+
loop do
|
124
|
+
begin
|
125
|
+
timetoken = args['timetoken'] ? args['timetoken'] : 0
|
126
|
+
|
127
|
+
## Wait for Message
|
128
|
+
response = self._request([
|
129
|
+
'subscribe',
|
130
|
+
@subscribe_key,
|
131
|
+
channel,
|
132
|
+
'0',
|
133
|
+
timetoken.to_s
|
134
|
+
])
|
135
|
+
|
136
|
+
messages = response[0]
|
137
|
+
args['timetoken'] = response[1]
|
138
|
+
|
139
|
+
## If it was a timeout
|
140
|
+
next if !messages.length
|
141
|
+
|
142
|
+
## Run user Callback and Reconnect if user permits.
|
143
|
+
messages.each do |message|
|
144
|
+
if !callback.call(message)
|
145
|
+
return
|
146
|
+
end
|
140
147
|
end
|
148
|
+
rescue Timeout::Error
|
149
|
+
rescue
|
150
|
+
sleep(1)
|
141
151
|
end
|
142
|
-
|
143
|
-
## Keep Listening.
|
144
|
-
return self.subscribe(args)
|
145
|
-
rescue Timeout::Error
|
146
|
-
return self.subscribe(args)
|
147
|
-
rescue
|
148
|
-
sleep(1)
|
149
|
-
return self.subscribe(args)
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
@@ -201,17 +203,25 @@ class Pubnub
|
|
201
203
|
#*
|
202
204
|
def _request(request)
|
203
205
|
## Construct Request URL
|
204
|
-
url =
|
206
|
+
url = '/' + request.map{ |bit| bit.split('').map{ |ch|
|
205
207
|
' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.index(ch) ?
|
206
208
|
'%' + ch.unpack('H2')[0].to_s.upcase : URI.encode(ch)
|
207
209
|
}.join('') }.join('/')
|
208
210
|
|
209
|
-
response =
|
210
|
-
|
211
|
-
|
212
|
-
|
211
|
+
response = send_with_retries(url, MAX_RETRIES)
|
212
|
+
JSON.parse(response)
|
213
|
+
end
|
214
|
+
|
215
|
+
private
|
213
216
|
|
214
|
-
|
217
|
+
def send_with_retries(url, retries)
|
218
|
+
tries = 0
|
219
|
+
begin
|
220
|
+
@connection.get(url).body
|
221
|
+
rescue
|
222
|
+
tries += 1
|
223
|
+
tries < retries ? retry : raise
|
224
|
+
end
|
215
225
|
end
|
216
226
|
end
|
217
227
|
|
metadata
CHANGED
@@ -1,74 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubnub-ruby
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.5
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Luke Carpenter
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &19743640 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *19743640
|
25
|
+
description: Simply Pubnub.rb in gem format, :require => "pubnub" - ask @rubynerd
|
26
|
+
for upgrades
|
27
|
+
email: x@rubynerd.net
|
28
28
|
executables: []
|
29
|
-
|
30
29
|
extensions: []
|
31
|
-
|
32
|
-
|
33
|
-
- LICENSE.PUBNUB
|
34
|
-
- README
|
35
|
-
- README.ROOT
|
36
|
-
files:
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
37
32
|
- examples/history-example.rb
|
38
33
|
- examples/publish-example.rb
|
39
34
|
- examples/subscribe-example.rb
|
40
35
|
- lib/pubnub-ruby.rb
|
41
36
|
- lib/pubnub.rb
|
42
37
|
- tests/unit-test.rb
|
43
|
-
|
44
|
-
|
45
|
-
- README.ROOT
|
46
|
-
homepage: http://github.com/rubynerd/pubnub
|
47
|
-
licenses:
|
38
|
+
homepage: http://github.com/pubnub/pubnub-api/tree/master/ruby
|
39
|
+
licenses:
|
48
40
|
- MIT
|
49
41
|
post_install_message:
|
50
42
|
rdoc_options: []
|
51
|
-
|
52
|
-
require_paths:
|
43
|
+
require_paths:
|
53
44
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
46
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version:
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
52
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version:
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
66
57
|
requirements: []
|
67
|
-
|
68
58
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.
|
59
|
+
rubygems_version: 1.8.11
|
70
60
|
signing_key:
|
71
61
|
specification_version: 3
|
72
62
|
summary: PubNub unofficial gem
|
73
63
|
test_files: []
|
74
|
-
|
data/LICENSE.PUBNUB
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks
|
2
|
-
Copyright (c) 2011 TopMambo Inc.
|
3
|
-
http://www.pubnub.com/
|
4
|
-
http://www.pubnub.com/terms
|
5
|
-
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
8
|
-
in the Software without restriction, including without limitation the rights
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
11
|
-
furnished to do so, subject to the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be included in
|
14
|
-
all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
THE SOFTWARE.
|
23
|
-
|
24
|
-
PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks
|
25
|
-
Copyright (c) 2011 TopMambo Inc.
|
26
|
-
http://www.pubnub.com/
|
27
|
-
http://www.pubnub.com/terms
|
data/README
DELETED
data/README.ROOT
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
## ---------------------------------------------------
|
2
|
-
##
|
3
|
-
## YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
|
4
|
-
## http://www.pubnub.com/account
|
5
|
-
##
|
6
|
-
## ----------------------------------------------------
|
7
|
-
|
8
|
-
## -----------------------------------
|
9
|
-
## PubNub 3.0 Real-time Cloud Push API
|
10
|
-
## -----------------------------------
|
11
|
-
##
|
12
|
-
## www.pubnub.com - PubNub Real-time Push Service in the Cloud.
|
13
|
-
## http://www.pubnub.com/tutorial/javascript-push-api
|
14
|
-
##
|
15
|
-
## PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
|
16
|
-
## This is a cloud-based service for broadcasting Real-time messages
|
17
|
-
## to thousands of web and mobile clients simultaneously.
|
18
|
-
|
19
|
-
JavaScript Tutorial: http://www.pubnub.com/tutorial/javascript-push-api
|
20
|
-
|
21
|
-
Website: http://www.pubnub.com
|
22
|
-
Videos: http://www.pubnub.com/#videos
|
23
|
-
Docs: http://www.pubnub.com/tutorial
|
24
|
-
Blog: http://www.pubnub.com/blog
|
25
|
-
Podcast Interview: http://techzinglive.com/?p=227
|
26
|
-
|
27
|
-
|
28
|
-
===============================================================================
|
29
|
-
PubNub Client APIs!
|
30
|
-
===============================================================================
|
31
|
-
Visit the PubNub website for more details at http://www.pubnub.com/
|
32
|
-
PubNub is a client-to-client push service in the cloud.
|
33
|
-
|
34
|
-
This public repository hosts client APIs for PubNub.
|
35
|
-
PHP, Ruby, JavaScript and more.
|
36
|
-
|
37
|
-
The API is SO FAST that iPhone, Android and Blackberry phones zip!
|
38
|
-
The JavaScript Payload is less than 3KB.
|
39
|
-
It's a breeze for mobile phones.
|