pusher-client 0.2.0 → 0.2.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/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.rdoc +23 -18
- data/VERSION +1 -1
- data/examples/hello_pusher.rb +4 -2
- data/examples/hello_pusher_async.rb +4 -2
- data/lib/pusher-client/socket.rb +2 -0
- data/pusher-client.gemspec +11 -6
- data/test/pusherclient_test.rb +9 -0
- metadata +8 -7
- data/pkg/pusher-client-0.1.1.gem +0 -0
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -1,30 +1,34 @@
|
|
1
|
-
=
|
1
|
+
= pusher-client (Ruby)
|
2
2
|
|
3
|
-
pusher-client is a ruby gem for consuming WebSockets from the Pusher
|
3
|
+
pusher-client is a ruby gem for consuming WebSockets from the Pusher[http://pusherapp.com] web service.
|
4
4
|
|
5
|
-
The connection to Pusher can optionally be maintained in its own thread (see Asynchronous Usage)
|
5
|
+
The connection to Pusher can optionally be maintained in its own thread (see Asynchronous Usage).
|
6
6
|
|
7
|
-
This gem no longer depends on em-http, and is compatible with jruby
|
7
|
+
This gem no longer depends on em-http, and is compatible with jruby since 0.2.
|
8
|
+
|
9
|
+
When binding to a global event, note that you still must be subscribed to the channels the event
|
10
|
+
may be sent on. You can't just bind a global event without subscribing to any channels and call it a day.
|
8
11
|
|
9
12
|
== Installation
|
10
13
|
gem install pusher-client
|
11
|
-
==
|
14
|
+
== Single-Threaded Usage
|
12
15
|
The application will pause at socket.connect and handle events from Pusher as they happen.
|
13
16
|
|
14
17
|
require 'pusher-client'
|
15
18
|
PusherClient.logger = Logger.new(STDOUT)
|
16
19
|
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
17
20
|
|
18
|
-
#
|
21
|
+
# Subscribe to two channels
|
22
|
+
socket.subscribe('channel1')
|
23
|
+
socket.subscribe('channel2')
|
24
|
+
|
25
|
+
# Bind to a global event (can occur on either channel1 or channel2)
|
19
26
|
socket.bind('globalevent') do |data|
|
20
27
|
puts data
|
21
28
|
end
|
22
29
|
|
23
|
-
#
|
24
|
-
socket.
|
25
|
-
|
26
|
-
# Bind to a channel event
|
27
|
-
socket['mychannel'].bind('channelevent') do |data|
|
30
|
+
# Bind to a channel event (can only occur on channel1)
|
31
|
+
socket['channel1'].bind('channelevent') do |data|
|
28
32
|
puts data
|
29
33
|
end
|
30
34
|
|
@@ -39,21 +43,22 @@ and you can continue to subscribe/unsubscribe to channels and bind new events.
|
|
39
43
|
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
40
44
|
socket.connect(true) # Connect asynchronously
|
41
45
|
|
42
|
-
#
|
46
|
+
# Subscribe to two channels
|
47
|
+
socket.subscribe('channel1')
|
48
|
+
socket.subscribe('channel2')
|
49
|
+
|
50
|
+
# Bind to a global event (can occur on either channel1 or channel2)
|
43
51
|
socket.bind('globalevent') do |data|
|
44
52
|
puts data
|
45
53
|
end
|
46
54
|
|
47
|
-
#
|
48
|
-
socket.
|
49
|
-
|
50
|
-
# Bind to a channel event
|
51
|
-
socket['mychannel'].bind('channelevent') do |data|
|
55
|
+
# Bind to a channel event (can only occur on channel1)
|
56
|
+
socket['channel1'].bind('channelevent') do |data|
|
52
57
|
puts data
|
53
58
|
end
|
54
59
|
|
55
60
|
loop do
|
56
|
-
sleep(1)
|
61
|
+
sleep(1) # Keep your main thread running
|
57
62
|
end
|
58
63
|
|
59
64
|
For further documentation, read the source & test suite. Some features of the JavaScript client
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/examples/hello_pusher.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# Usage: $ PUSHER_KEY=YOURKEY ruby examples/hello_pusher.rb
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require './lib/pusher-client.rb'
|
3
5
|
require 'pp'
|
4
6
|
|
5
|
-
|
7
|
+
APP_KEY = ENV['PUSHER_KEY'] # || "YOUR_APPLICATION_KEY"
|
6
8
|
|
7
9
|
PusherClient.logger = Logger.new('/dev/null')
|
8
|
-
socket = PusherClient::Socket.new(
|
10
|
+
socket = PusherClient::Socket.new(APP_KEY)
|
9
11
|
|
10
12
|
# Subscribe to a channel
|
11
13
|
socket.subscribe('hellopusher')
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# Usage: $ PUSHER_KEY=YOURKEY ruby examples/hello_pusher.rb
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require './lib/pusher-client.rb'
|
3
5
|
require 'pp'
|
4
6
|
|
5
|
-
|
7
|
+
APP_KEY = ENV['PUSHER_KEY'] # || "YOUR_APPLICATION_KEY"
|
6
8
|
|
7
9
|
PusherClient.logger = Logger.new('/dev/null')
|
8
|
-
socket = PusherClient::Socket.new(
|
10
|
+
socket = PusherClient::Socket.new(APP_KEY)
|
9
11
|
socket.connect(true)
|
10
12
|
|
11
13
|
# Subscribe to a channel
|
data/lib/pusher-client/socket.rb
CHANGED
@@ -12,6 +12,8 @@ module PusherClient
|
|
12
12
|
|
13
13
|
def initialize(application_key, options={})
|
14
14
|
|
15
|
+
raise ArgumentError if (!application_key.is_a?(String) || application_key.size < 1)
|
16
|
+
|
15
17
|
@path = "/app/#{application_key}?client=#{CLIENT_ID}&version=#{VERSION}"
|
16
18
|
@key = application_key
|
17
19
|
@socket_id = nil
|
data/pusher-client.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pusher-client}
|
8
|
-
s.version = "0.1
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Logan Koester"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-07}
|
13
13
|
s.description = %q{Ruby client for consuming WebSockets from http://pusherapp.com}
|
14
14
|
s.email = %q{logan@logankoester.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
".bundle/config",
|
21
20
|
".document",
|
22
21
|
"Gemfile",
|
23
22
|
"Gemfile.lock",
|
@@ -25,10 +24,14 @@ Gem::Specification.new do |s|
|
|
25
24
|
"README.rdoc",
|
26
25
|
"Rakefile",
|
27
26
|
"VERSION",
|
27
|
+
"examples/hello_pusher.rb",
|
28
|
+
"examples/hello_pusher_async.rb",
|
28
29
|
"lib/pusher-client.rb",
|
29
30
|
"lib/pusher-client/channel.rb",
|
30
31
|
"lib/pusher-client/channels.rb",
|
31
32
|
"lib/pusher-client/socket.rb",
|
33
|
+
"lib/pusher-client/websocket.rb",
|
34
|
+
"pusher-client.gemspec",
|
32
35
|
"test/pusherclient_test.rb",
|
33
36
|
"test/test.watchr",
|
34
37
|
"test/teststrap.rb"
|
@@ -39,6 +42,8 @@ Gem::Specification.new do |s|
|
|
39
42
|
s.rubygems_version = %q{1.3.7}
|
40
43
|
s.summary = %q{Ruby client for consuming WebSockets from http://pusherapp.com}
|
41
44
|
s.test_files = [
|
45
|
+
"examples/hello_pusher.rb",
|
46
|
+
"examples/hello_pusher_async.rb",
|
42
47
|
"test/pusherclient_test.rb",
|
43
48
|
"test/teststrap.rb"
|
44
49
|
]
|
@@ -49,14 +54,14 @@ Gem::Specification.new do |s|
|
|
49
54
|
|
50
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
56
|
s.add_runtime_dependency(%q<eventmachine>, ["~> 0.12.10"])
|
52
|
-
s.add_runtime_dependency(%q<
|
57
|
+
s.add_runtime_dependency(%q<libwebsocket>, ["~> 0.1.0"])
|
53
58
|
s.add_development_dependency(%q<bacon>, [">= 0"])
|
54
59
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
60
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
61
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
62
|
else
|
58
63
|
s.add_dependency(%q<eventmachine>, ["~> 0.12.10"])
|
59
|
-
s.add_dependency(%q<
|
64
|
+
s.add_dependency(%q<libwebsocket>, ["~> 0.1.0"])
|
60
65
|
s.add_dependency(%q<bacon>, [">= 0"])
|
61
66
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
67
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -64,7 +69,7 @@ Gem::Specification.new do |s|
|
|
64
69
|
end
|
65
70
|
else
|
66
71
|
s.add_dependency(%q<eventmachine>, ["~> 0.12.10"])
|
67
|
-
s.add_dependency(%q<
|
72
|
+
s.add_dependency(%q<libwebsocket>, ["~> 0.1.0"])
|
68
73
|
s.add_dependency(%q<bacon>, [">= 0"])
|
69
74
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
75
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
data/test/pusherclient_test.rb
CHANGED
@@ -71,6 +71,15 @@ describe "A PusherClient::Socket" do
|
|
71
71
|
@socket.connected.should.equal false
|
72
72
|
end
|
73
73
|
|
74
|
+
it 'should raise ArgumentError if TEST_APP_KEY is not a nonempty string' do
|
75
|
+
lambda {
|
76
|
+
@broken_socket = PusherClient::Socket.new('')
|
77
|
+
}.should.raise(ArgumentError)
|
78
|
+
lambda {
|
79
|
+
@broken_socket = PusherClient::Socket.new(555)
|
80
|
+
}.should.raise(ArgumentError)
|
81
|
+
end
|
82
|
+
|
74
83
|
describe "...when connected" do
|
75
84
|
before do
|
76
85
|
@socket.connect
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Logan Koester
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-07 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -37,11 +37,13 @@ dependencies:
|
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
segments:
|
43
43
|
- 0
|
44
|
-
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
version: 0.1.0
|
45
47
|
type: :runtime
|
46
48
|
prerelease: false
|
47
49
|
version_requirements: *id002
|
@@ -125,7 +127,6 @@ files:
|
|
125
127
|
- lib/pusher-client/channels.rb
|
126
128
|
- lib/pusher-client/socket.rb
|
127
129
|
- lib/pusher-client/websocket.rb
|
128
|
-
- pkg/pusher-client-0.1.1.gem
|
129
130
|
- pusher-client.gemspec
|
130
131
|
- test/pusherclient_test.rb
|
131
132
|
- test/test.watchr
|
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
requirements:
|
145
146
|
- - ">="
|
146
147
|
- !ruby/object:Gem::Version
|
147
|
-
hash:
|
148
|
+
hash: 3350793472905548965
|
148
149
|
segments:
|
149
150
|
- 0
|
150
151
|
version: "0"
|
data/pkg/pusher-client-0.1.1.gem
DELETED
Binary file
|