pusher-client 0.1.0 → 0.1.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/README.rdoc +31 -7
- data/VERSION +1 -1
- data/examples/hello_pusher.rb +18 -0
- data/examples/hello_pusher_async.rb +21 -0
- data/lib/pusher-client/socket.rb +12 -4
- data/pkg/pusher-client-0.1.0.gem +0 -0
- data/pkg/pusher-client-0.1.1.gem +0 -0
- data/pusher-client.gemspec +74 -0
- data/test/teststrap.rb +3 -1
- metadata +10 -3
data/README.rdoc
CHANGED
@@ -2,21 +2,44 @@
|
|
2
2
|
|
3
3
|
pusher-client is a ruby gem for consuming WebSockets from the Pusher webservice[http://pusherapp.com]
|
4
4
|
|
5
|
-
It is driven by event-machine and maintains a connection to Pusher in its own thread.
|
5
|
+
It is driven by event-machine and maintains a connection to Pusher, optionally in its own thread.
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
gem install pusher-client
|
9
|
-
== Usage
|
9
|
+
== Evented Usage
|
10
|
+
The application will pause at socket.connect and handle events from Pusher as they happen.
|
10
11
|
|
11
|
-
# Configuration
|
12
12
|
require 'pusher-client'
|
13
13
|
PusherClient.logger = Logger.new(STDOUT)
|
14
14
|
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
15
|
+
|
16
|
+
# Bind to a global event
|
17
|
+
socket.bind('globalevent') do |data|
|
18
|
+
puts data
|
19
|
+
end
|
20
|
+
|
21
|
+
# Subscribe to a channel
|
22
|
+
socket.subscribe('mychannel')
|
23
|
+
|
24
|
+
# Bind to a channel event
|
25
|
+
socket['mychannel'].bind('channelevent') do |data|
|
26
|
+
puts data
|
27
|
+
end
|
28
|
+
|
15
29
|
socket.connect
|
16
30
|
|
31
|
+
== Asynchronous Usage
|
32
|
+
The socket will remain open in the background as long as your main application thread is running,
|
33
|
+
and you can continue to subscribe/unsubscribe to channels and bind new events.
|
34
|
+
|
35
|
+
require 'pusher-client'
|
36
|
+
PusherClient.logger = Logger.new(STDOUT)
|
37
|
+
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
38
|
+
socket.connect(true) # Connect asynchronously
|
39
|
+
|
17
40
|
# Bind to a global event
|
18
41
|
socket.bind('globalevent') do |data|
|
19
|
-
|
42
|
+
puts data
|
20
43
|
end
|
21
44
|
|
22
45
|
# Subscribe to a channel
|
@@ -24,11 +47,12 @@ It is driven by event-machine and maintains a connection to Pusher in its own th
|
|
24
47
|
|
25
48
|
# Bind to a channel event
|
26
49
|
socket['mychannel'].bind('channelevent') do |data|
|
27
|
-
|
50
|
+
puts data
|
28
51
|
end
|
29
52
|
|
30
|
-
|
31
|
-
|
53
|
+
loop do
|
54
|
+
sleep(1)
|
55
|
+
end
|
32
56
|
|
33
57
|
For further documentation, read the source & test suite. Some features of the JavaScript client
|
34
58
|
are not yet implemented.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pusher-client'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
YOUR_APPLICATION_KEY = ''
|
6
|
+
|
7
|
+
PusherClient.logger = Logger.new('/dev/null')
|
8
|
+
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
9
|
+
|
10
|
+
# Subscribe to a channel
|
11
|
+
socket.subscribe('hellopusher')
|
12
|
+
|
13
|
+
# Bind to a channel event
|
14
|
+
socket['hellopusher'].bind('hello') do |data|
|
15
|
+
pp data
|
16
|
+
end
|
17
|
+
|
18
|
+
socket.connect
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pusher-client'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
YOUR_APPLICATION_KEY = ''
|
6
|
+
|
7
|
+
PusherClient.logger = Logger.new('/dev/null')
|
8
|
+
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
9
|
+
socket.connect(true)
|
10
|
+
|
11
|
+
# Subscribe to a channel
|
12
|
+
socket.subscribe('hellopusher')
|
13
|
+
|
14
|
+
# Bind to a channel event
|
15
|
+
socket['hellopusher'].bind('hello') do |data|
|
16
|
+
pp data
|
17
|
+
end
|
18
|
+
|
19
|
+
loop do
|
20
|
+
sleep 1
|
21
|
+
end
|
data/lib/pusher-client/socket.rb
CHANGED
@@ -39,7 +39,7 @@ module PusherClient
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def connect
|
42
|
+
def connect(async = false)
|
43
43
|
@connection_thread = Thread.new do
|
44
44
|
EventMachine.run {
|
45
45
|
if @encrypted || @secure
|
@@ -77,12 +77,18 @@ module PusherClient
|
|
77
77
|
}
|
78
78
|
end
|
79
79
|
@connection_thread.run
|
80
|
+
if async
|
81
|
+
sleep(1)
|
82
|
+
else
|
83
|
+
@connection_thread.join
|
84
|
+
end
|
85
|
+
return self
|
80
86
|
end
|
81
87
|
|
82
88
|
def disconnect
|
83
89
|
if @connected
|
84
90
|
PusherClient.logger.debug "Pusher : disconnecting"
|
85
|
-
@connection_thread.kill
|
91
|
+
@connection_thread.kill if @connection_thread
|
86
92
|
@connected = false
|
87
93
|
else
|
88
94
|
PusherClient.logger.warn "Disconnect attempted... not connected"
|
@@ -93,7 +99,7 @@ module PusherClient
|
|
93
99
|
channel = @channels << channel_name
|
94
100
|
if @connected
|
95
101
|
send_event('pusher:subscribe', {
|
96
|
-
'channel' =>
|
102
|
+
'channel' => channel.name
|
97
103
|
})
|
98
104
|
channel.acknowledge_subscription(nil)
|
99
105
|
end
|
@@ -124,7 +130,9 @@ module PusherClient
|
|
124
130
|
end
|
125
131
|
|
126
132
|
def subscribe_all
|
127
|
-
@channels.channels.
|
133
|
+
@channels.channels.clone.each{ |k,v|
|
134
|
+
subscribe(k)
|
135
|
+
}
|
128
136
|
end
|
129
137
|
|
130
138
|
# For compatibility with JavaScript client API
|
Binary file
|
Binary file
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pusher-client}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Logan Koester"]
|
12
|
+
s.date = %q{2010-12-29}
|
13
|
+
s.description = %q{Ruby client for consuming WebSockets from http://pusherapp.com}
|
14
|
+
s.email = %q{logan@logankoester.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".bundle/config",
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/pusher-client.rb",
|
29
|
+
"lib/pusher-client/channel.rb",
|
30
|
+
"lib/pusher-client/channels.rb",
|
31
|
+
"lib/pusher-client/socket.rb",
|
32
|
+
"test/pusherclient_test.rb",
|
33
|
+
"test/test.watchr",
|
34
|
+
"test/teststrap.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/logankoester/pusher-client}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{Ruby client for consuming WebSockets from http://pusherapp.com}
|
41
|
+
s.test_files = [
|
42
|
+
"test/pusherclient_test.rb",
|
43
|
+
"test/teststrap.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<eventmachine>, ["~> 0.12.10"])
|
52
|
+
s.add_runtime_dependency(%q<em-http-request>, ["~> 0.2.15"])
|
53
|
+
s.add_development_dependency(%q<bacon>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<eventmachine>, ["~> 0.12.10"])
|
59
|
+
s.add_dependency(%q<em-http-request>, ["~> 0.2.15"])
|
60
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<eventmachine>, ["~> 0.12.10"])
|
67
|
+
s.add_dependency(%q<em-http-request>, ["~> 0.2.15"])
|
68
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
data/test/teststrap.rb
CHANGED
@@ -29,13 +29,15 @@ module PusherClient
|
|
29
29
|
|
30
30
|
class Socket
|
31
31
|
# Simulate a connection being established
|
32
|
-
def connect
|
32
|
+
def connect(async = false)
|
33
33
|
@connection_thread = Thread.new do
|
34
34
|
@connection = TestConnection.new
|
35
35
|
@global_channel.dispatch('pusher:connection_established', {'socket_id' => '123abc'})
|
36
36
|
end
|
37
37
|
@connection_thread.run
|
38
|
+
@connection_thread.join unless async
|
38
39
|
sleep(1)
|
40
|
+
return self
|
39
41
|
end
|
40
42
|
|
41
43
|
def simulate_received(event_name, event_data, channel_name)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Logan Koester
|
@@ -121,10 +121,15 @@ files:
|
|
121
121
|
- README.rdoc
|
122
122
|
- Rakefile
|
123
123
|
- VERSION
|
124
|
+
- examples/hello_pusher.rb
|
125
|
+
- examples/hello_pusher_async.rb
|
124
126
|
- lib/pusher-client.rb
|
125
127
|
- lib/pusher-client/channel.rb
|
126
128
|
- lib/pusher-client/channels.rb
|
127
129
|
- lib/pusher-client/socket.rb
|
130
|
+
- pkg/pusher-client-0.1.0.gem
|
131
|
+
- pkg/pusher-client-0.1.1.gem
|
132
|
+
- pusher-client.gemspec
|
128
133
|
- test/pusherclient_test.rb
|
129
134
|
- test/test.watchr
|
130
135
|
- test/teststrap.rb
|
@@ -142,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
147
|
requirements:
|
143
148
|
- - ">="
|
144
149
|
- !ruby/object:Gem::Version
|
145
|
-
hash:
|
150
|
+
hash: -4529769101084018713
|
146
151
|
segments:
|
147
152
|
- 0
|
148
153
|
version: "0"
|
@@ -162,5 +167,7 @@ signing_key:
|
|
162
167
|
specification_version: 3
|
163
168
|
summary: Ruby client for consuming WebSockets from http://pusherapp.com
|
164
169
|
test_files:
|
170
|
+
- examples/hello_pusher.rb
|
171
|
+
- examples/hello_pusher_async.rb
|
165
172
|
- test/pusherclient_test.rb
|
166
173
|
- test/teststrap.rb
|