pubnub-ruby 0.0.9 → 3.3.0.1
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.
- data/lib/pubnub.rb +320 -235
- data/lib/pubnub_crypto.rb +53 -0
- data/lib/pubnub_deferrable.rb +37 -0
- data/lib/pubnub_request.rb +287 -0
- metadata +90 -61
- data/README +0 -55
- data/examples/history-example.rb +0 -37
- data/examples/publish-example.rb +0 -40
- data/examples/subscribe-example.rb +0 -41
- data/lib/pubnub-ruby.rb +0 -1
- data/tests/unit-test.rb +0 -75
data/README
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
Pubnub - http://github/pubnub/pubnub-api
|
2
|
-
@poptartinc on Twitter, @poptart on Github
|
3
|
-
|
4
|
-
## ------------------------------------------
|
5
|
-
## PubNub 3.0 Real-time Cloud Push API - RUBY
|
6
|
-
## ------------------------------------------
|
7
|
-
##
|
8
|
-
## www.pubnub.com - PubNub Real-time Push Service in the Cloud.
|
9
|
-
## http://www.pubnub.com/blog/ruby-push-api
|
10
|
-
##
|
11
|
-
## PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
|
12
|
-
## This is a cloud-based service for broadcasting Real-time messages
|
13
|
-
## to thousands of web and mobile clients simultaneously.
|
14
|
-
|
15
|
-
## -------------
|
16
|
-
## Ruby Push API
|
17
|
-
## -------------
|
18
|
-
pubnub = Pubnub.new(
|
19
|
-
"demo", ## PUBLISH_KEY
|
20
|
-
"demo", ## SUBSCRIBE_KEY
|
21
|
-
"", ## SECRET_KEY
|
22
|
-
false ## SSL_ON?
|
23
|
-
)
|
24
|
-
|
25
|
-
# -------
|
26
|
-
# PUBLISH
|
27
|
-
# -------
|
28
|
-
# Send Message
|
29
|
-
info = pubnub.publish({
|
30
|
-
'channel' => 'hello_world',
|
31
|
-
'message' => { 'text' => 'some text data' }
|
32
|
-
})
|
33
|
-
puts(info)
|
34
|
-
|
35
|
-
# ---------
|
36
|
-
# SUBSCRIBE
|
37
|
-
# ---------
|
38
|
-
# Listen for Messages *BLOCKING*
|
39
|
-
pubnub.subscribe({
|
40
|
-
'channel' => 'hello_world',
|
41
|
-
'callback' => lambda do |message|
|
42
|
-
puts(message) ## print message
|
43
|
-
return true ## keep listening?
|
44
|
-
end
|
45
|
-
})
|
46
|
-
|
47
|
-
# -------
|
48
|
-
# HISTORY
|
49
|
-
# -------
|
50
|
-
# Load Previously Published Messages
|
51
|
-
messages = pubnub.history({
|
52
|
-
'channel' => 'hello_world',
|
53
|
-
'limit' => 10
|
54
|
-
})
|
55
|
-
puts(messages)
|
data/examples/history-example.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
##including required libraries
|
2
|
-
require 'rubygems'
|
3
|
-
require './lib/pubnub.rb'
|
4
|
-
|
5
|
-
##declaring publish_key, subscribe_key, secret_key, cipher_key
|
6
|
-
publish_key = 'demo'
|
7
|
-
subscribe_key = 'demo'
|
8
|
-
secret_key =''
|
9
|
-
cipher_key ='demo'
|
10
|
-
ssl_on = !!ARGV[4]
|
11
|
-
|
12
|
-
## Print usage if missing info.
|
13
|
-
if !subscribe_key
|
14
|
-
puts('
|
15
|
-
Get API Keys at http://www.pubnub.com/account
|
16
|
-
==============
|
17
|
-
EXAMPLE USAGE:
|
18
|
-
==============
|
19
|
-
ruby history-example.rb PUBLISH-KEY SUBSCRIBE-KEY SSL-ON
|
20
|
-
ruby history-example.rb demo demo true
|
21
|
-
')
|
22
|
-
end
|
23
|
-
|
24
|
-
## Create Pubnub Client API (INITIALIZATION)
|
25
|
-
|
26
|
-
puts('Creating new Pubnub Client API')
|
27
|
-
pubnub = Pubnub.new(publish_key,subscribe_key,secret_key,cipher_key,ssl_on=false)
|
28
|
-
|
29
|
-
## Request Past Publishes (HISTORY)
|
30
|
-
|
31
|
-
puts('Requesting History with history() Function')
|
32
|
-
message = pubnub.history(
|
33
|
-
{
|
34
|
-
'channel' => 'HelloWorld',
|
35
|
-
'limit' => 20
|
36
|
-
})
|
37
|
-
puts(message)
|
data/examples/publish-example.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
##including required libraries
|
2
|
-
require './lib/pubnub.rb'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
##declaring publish_key, subscribe_key, secret_key, cipher_key, message
|
6
|
-
publish_key = 'demo'
|
7
|
-
subscribe_key = 'demo'
|
8
|
-
secret_key = 'demo'
|
9
|
-
cipher_key = 'demo'
|
10
|
-
message = 'HelloRuby'
|
11
|
-
channel = 'HelloWorld'
|
12
|
-
ssl_on = !!ARGV[4]
|
13
|
-
|
14
|
-
## Print usage if missing info.
|
15
|
-
if !message
|
16
|
-
puts('
|
17
|
-
Get API Keys at http://www.pubnub.com/account
|
18
|
-
==============
|
19
|
-
EXAMPLE USAGE:
|
20
|
-
==============
|
21
|
-
ruby publish-example.rb PUB-KEY SUB-KEY SECRET-KEY "message text" SSL-ON
|
22
|
-
ruby publish-example.rb demo demo "" "hey what is up?" true
|
23
|
-
')
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
## Create Pubnub Client API (INITIALIZATION)
|
28
|
-
|
29
|
-
puts('Creating new Pubnub Client API')
|
30
|
-
pubnub = Pubnub.new(publish_key,subscribe_key,secret_key,cipher_key,ssl_on=false)
|
31
|
-
|
32
|
-
## Send Message (PUBLISH)
|
33
|
-
|
34
|
-
puts('Sending a message with publish() Function')
|
35
|
-
info = pubnub.publish({'channel' => channel ,'message' => message})
|
36
|
-
|
37
|
-
|
38
|
-
## Print Info
|
39
|
-
puts(info)
|
40
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
##including required libraries
|
2
|
-
require 'rubygems'
|
3
|
-
require './lib/pubnub.rb'
|
4
|
-
|
5
|
-
##declaring publish_key, subscribe_key, secret_key, cipher_key
|
6
|
-
publish_key = 'demo'
|
7
|
-
subscribe_key = 'demo'
|
8
|
-
secret_key = 'demo'
|
9
|
-
cipher_key = 'demo'
|
10
|
-
ssl_on = !!ARGV[2]
|
11
|
-
|
12
|
-
|
13
|
-
## Print usage if missing info.
|
14
|
-
if !subscribe_key
|
15
|
-
puts('
|
16
|
-
Get API Keys at http://www.pubnub.com/account
|
17
|
-
==============
|
18
|
-
EXAMPLE USAGE:
|
19
|
-
==============
|
20
|
-
ruby subscribe-example.rb PUBLISH-KEY SUBSCRIBE-KEY SSL-ON
|
21
|
-
ruby subscribe-example.rb demo demo true
|
22
|
-
')
|
23
|
-
end
|
24
|
-
|
25
|
-
## Create Pubnub Client API (INITIALIZATION)
|
26
|
-
|
27
|
-
puts('Creating new Pubnub Client API')
|
28
|
-
pubnub = Pubnub.new(publish_key,subscribe_key,secret_key,cipher_key,ssl_on=false)
|
29
|
-
|
30
|
-
## Listen for Messages (SUBSCRIBE)
|
31
|
-
|
32
|
-
puts('Listening for new messages with subscribe() Function')
|
33
|
-
puts('Press CTRL+C to quit.')
|
34
|
-
|
35
|
-
pubnub.subscribe({
|
36
|
-
'channel' => 'HelloWorld',
|
37
|
-
'callback' => lambda do |message|
|
38
|
-
puts(message) ## print message
|
39
|
-
return true ## keep listening?
|
40
|
-
end
|
41
|
-
})
|
data/lib/pubnub-ruby.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "./pubnub.rb"
|
data/tests/unit-test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
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
|
-
|
4
|
-
## PubNub Real Time Push APIs and Notifications Framework
|
5
|
-
## Copyright (c) 2010 Stephen Blum
|
6
|
-
## http://www.pubnub.com/
|
7
|
-
|
8
|
-
## -----------------------------------
|
9
|
-
## PubNub 3.0 Real-time Push Cloud API
|
10
|
-
## -----------------------------------
|
11
|
-
|
12
|
-
##including required libraries
|
13
|
-
require 'rubygems'
|
14
|
-
require './lib/pubnub.rb'
|
15
|
-
|
16
|
-
##declaring publish_key, subscribe_key, secret_key, cipher_key, message, ssl_on
|
17
|
-
publish_key = ARGV[0] || 'demo'
|
18
|
-
subscribe_key = ARGV[1] || 'demo'
|
19
|
-
secret_key = ARGV[2] || 'demo'
|
20
|
-
cipher_key = ARGV[3]||'demo'
|
21
|
-
message ='hellounit'
|
22
|
-
ssl_on = !!ARGV[4]
|
23
|
-
|
24
|
-
|
25
|
-
## ---------------------------------------------------------------------------
|
26
|
-
## Create Pubnub Client API (INITIALIZATION)
|
27
|
-
## ---------------------------------------------------------------------------
|
28
|
-
pubnub = Pubnub.new( publish_key, subscribe_key, secret_key,cipher_key, ssl_on=false )
|
29
|
-
channel = 'HelloWorld' + rand().to_s
|
30
|
-
|
31
|
-
|
32
|
-
## ---------------------------------------------------------------------------
|
33
|
-
## Unit Test Function
|
34
|
-
## ---------------------------------------------------------------------------
|
35
|
-
def test( trial, name )
|
36
|
-
trial ? puts('PASS: ' + name) : puts('FAIL: ' + name)
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
## ---------------------------------------------------------------------------
|
41
|
-
## PubNub Server Time
|
42
|
-
## ---------------------------------------------------------------------------
|
43
|
-
timestamp = pubnub.time()
|
44
|
-
test( timestamp > 0, 'PubNub Server Time: ' + timestamp.to_s )
|
45
|
-
|
46
|
-
|
47
|
-
## ---------------------------------------------------------------------------
|
48
|
-
## PUBLISH
|
49
|
-
## ---------------------------------------------------------------------------
|
50
|
-
first_message = 'Hi. (顶顅Ȓ)'
|
51
|
-
pubish_success = pubnub.publish({'channel' => 'HelloWorld' ,'message' => message})
|
52
|
-
test( pubish_success[0] == 1, 'Publish First Message Success' )
|
53
|
-
|
54
|
-
## ---------------------------------------------------------------------------
|
55
|
-
## HISTORY
|
56
|
-
## ---------------------------------------------------------------------------
|
57
|
-
history = pubnub.history({
|
58
|
-
'channel' => 'HelloWorld',
|
59
|
-
'limit' => 20
|
60
|
-
})
|
61
|
-
puts(history)
|
62
|
-
test( history.length >= 1, 'Display History' )
|
63
|
-
|
64
|
-
## ---------------------------------------------------------------------------
|
65
|
-
## Subscribe
|
66
|
-
## ---------------------------------------------------------------------------
|
67
|
-
puts('Listening for new messages with subscribe() Function')
|
68
|
-
puts('Press CTRL+C to quit.')
|
69
|
-
pubnub.subscribe({
|
70
|
-
'channel' => 'HelloWorld',
|
71
|
-
'callback' => lambda do |message|
|
72
|
-
puts(message) ## print message
|
73
|
-
return true ## keep listening?
|
74
|
-
end
|
75
|
-
})
|