wamp-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/wamp/client/version.rb +2 -1
- data/lib/wamp/client.rb +3 -2
- data/test/support/wamp_server.py +27 -0
- data/test/test_helper.rb +3 -0
- data/test/unit/client_spec.rb +77 -0
- data/wamp-client.gemspec +7 -3
- metadata +68 -14
data/.gitignore
CHANGED
data/lib/wamp/client/version.rb
CHANGED
data/lib/wamp/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require "wamp/client/version"
|
2
3
|
require "net/ws"
|
3
|
-
require "
|
4
|
+
require "yajl/json_gem"
|
4
5
|
require "timeout"
|
5
6
|
|
6
7
|
|
@@ -70,7 +71,7 @@ module WAMP
|
|
70
71
|
|
71
72
|
def publish(uri_or_curie, data)
|
72
73
|
payload = [TYPEID_PUBLISH, uri_or_curie, data]
|
73
|
-
@ws.send_text(JSON.dump(payload))
|
74
|
+
@ws.send_text(JSON.dump(payload).force_encoding("utf-8"))
|
74
75
|
end
|
75
76
|
|
76
77
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import sys
|
2
|
+
|
3
|
+
from twisted.internet import reactor
|
4
|
+
from twisted.python import log
|
5
|
+
from autobahn.wamp import WampServerFactory, \
|
6
|
+
WampServerProtocol, \
|
7
|
+
exportRpc
|
8
|
+
from autobahn.websocket import listenWS
|
9
|
+
|
10
|
+
class RpcServerProtocol(WampServerProtocol):
|
11
|
+
|
12
|
+
@exportRpc
|
13
|
+
def add(self, x, y):
|
14
|
+
return x + y
|
15
|
+
|
16
|
+
def onSessionOpen(self):
|
17
|
+
self.registerForPubSub("/mpd/test")
|
18
|
+
|
19
|
+
if __name__ == '__main__':
|
20
|
+
factory = WampServerFactory("ws://localhost:9001", debug=True)
|
21
|
+
factory.protocol = RpcServerProtocol
|
22
|
+
log.startLogging(sys.stdout)
|
23
|
+
listenWS(factory)
|
24
|
+
print "Here we go"
|
25
|
+
sys.stdout.flush() # flush the line so that tests know we're up
|
26
|
+
sys.stderr.flush()
|
27
|
+
reactor.run()
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path("../test_helper", File.dirname(__FILE__))
|
3
|
+
require "open3"
|
4
|
+
require File.expand_path("../../../rmpd/lib/rmpd", File.dirname(__FILE__))
|
5
|
+
|
6
|
+
|
7
|
+
describe WAMP::Client do
|
8
|
+
|
9
|
+
def with_echo_server(&block)
|
10
|
+
echo_server_path = File.expand_path("../support/echo_server.py",
|
11
|
+
File.dirname(__FILE__))
|
12
|
+
|
13
|
+
Open3.popen3(echo_server_path) do |stdin, stdout, stderr|
|
14
|
+
stdout.readline # the readline tells us the server is up
|
15
|
+
yield "localhost", 9001
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# it "should be sane" do
|
20
|
+
# true.must_equal true
|
21
|
+
# end
|
22
|
+
|
23
|
+
it "can send and receive message" do
|
24
|
+
CHANNEL = "/mpd/test"
|
25
|
+
|
26
|
+
host = "localhost"; port = 9001
|
27
|
+
|
28
|
+
listener = WAMP::Client.new("ws://#{host}:#{port}",
|
29
|
+
:subprotocols => ["wamp"])
|
30
|
+
listener.open
|
31
|
+
listener.subscribe(CHANNEL, proc {|x| $stderr.puts "Rx: %p" % [x]})
|
32
|
+
|
33
|
+
puts "listener subscribed"
|
34
|
+
|
35
|
+
|
36
|
+
client = WAMP::Client.new("ws://#{host}:#{port}",
|
37
|
+
:subprotocols => ["wamp"])
|
38
|
+
puts client.open
|
39
|
+
client.publish(CHANNEL, "testing 1 2 3")
|
40
|
+
|
41
|
+
puts "checking..."
|
42
|
+
listener.check(0.1)
|
43
|
+
|
44
|
+
client.publish(CHANNEL, "∆AIMON")
|
45
|
+
|
46
|
+
puts "checking..."
|
47
|
+
listener.check(0.1)
|
48
|
+
|
49
|
+
client.publish(CHANNEL, {"file" => "∆AIMON"})
|
50
|
+
|
51
|
+
puts "checking..."
|
52
|
+
listener.check(0.1)
|
53
|
+
|
54
|
+
config = StringIO.new <<EOF
|
55
|
+
development:
|
56
|
+
hostname: admin@localhost
|
57
|
+
port: 6601
|
58
|
+
|
59
|
+
test:
|
60
|
+
hostname: admin@localhost
|
61
|
+
port: 6601
|
62
|
+
EOF
|
63
|
+
|
64
|
+
rmpd = Rmpd::Connection.new(config)
|
65
|
+
pi = rmpd.search("artist", "aimon", "title", "current")
|
66
|
+
client.publish(CHANNEL, pi)
|
67
|
+
|
68
|
+
puts "checking..."
|
69
|
+
listener.check(0.1)
|
70
|
+
|
71
|
+
puts "closing"
|
72
|
+
client.close
|
73
|
+
listener.close
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/wamp-client.gemspec
CHANGED
@@ -15,10 +15,14 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = WAMP::Client::VERSION
|
17
17
|
|
18
|
+
gem.add_dependency("yajl-ruby")
|
19
|
+
gem.add_dependency("net-ws", "~> 0.0.3")
|
20
|
+
|
21
|
+
gem.add_development_dependency("debugger")
|
18
22
|
gem.add_development_dependency("rake")
|
19
23
|
gem.add_development_dependency("pry")
|
20
|
-
gem.add_development_dependency("
|
24
|
+
gem.add_development_dependency("minitest")
|
25
|
+
gem.add_development_dependency("minitest-spec")
|
26
|
+
gem.add_development_dependency("minitest-rg")
|
21
27
|
|
22
|
-
gem.add_dependency("json")
|
23
|
-
gem.add_dependency("net-ws", "~> 0.0.2")
|
24
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wamp-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,56 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: net-ws
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: debugger
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
14
62
|
- !ruby/object:Gem::Dependency
|
15
63
|
name: rake
|
16
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,7 +92,7 @@ dependencies:
|
|
44
92
|
- !ruby/object:Gem::Version
|
45
93
|
version: '0'
|
46
94
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
95
|
+
name: minitest
|
48
96
|
requirement: !ruby/object:Gem::Requirement
|
49
97
|
none: false
|
50
98
|
requirements:
|
@@ -60,14 +108,14 @@ dependencies:
|
|
60
108
|
- !ruby/object:Gem::Version
|
61
109
|
version: '0'
|
62
110
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
111
|
+
name: minitest-spec
|
64
112
|
requirement: !ruby/object:Gem::Requirement
|
65
113
|
none: false
|
66
114
|
requirements:
|
67
115
|
- - ! '>='
|
68
116
|
- !ruby/object:Gem::Version
|
69
117
|
version: '0'
|
70
|
-
type: :
|
118
|
+
type: :development
|
71
119
|
prerelease: false
|
72
120
|
version_requirements: !ruby/object:Gem::Requirement
|
73
121
|
none: false
|
@@ -76,21 +124,21 @@ dependencies:
|
|
76
124
|
- !ruby/object:Gem::Version
|
77
125
|
version: '0'
|
78
126
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
127
|
+
name: minitest-rg
|
80
128
|
requirement: !ruby/object:Gem::Requirement
|
81
129
|
none: false
|
82
130
|
requirements:
|
83
|
-
- -
|
131
|
+
- - ! '>='
|
84
132
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0
|
86
|
-
type: :
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
87
135
|
prerelease: false
|
88
136
|
version_requirements: !ruby/object:Gem::Requirement
|
89
137
|
none: false
|
90
138
|
requirements:
|
91
|
-
- -
|
139
|
+
- - ! '>='
|
92
140
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0
|
141
|
+
version: '0'
|
94
142
|
description: WAMP client
|
95
143
|
email:
|
96
144
|
- ericw@xmtp.net
|
@@ -105,6 +153,9 @@ files:
|
|
105
153
|
- Rakefile
|
106
154
|
- lib/wamp/client.rb
|
107
155
|
- lib/wamp/client/version.rb
|
156
|
+
- test/support/wamp_server.py
|
157
|
+
- test/test_helper.rb
|
158
|
+
- test/unit/client_spec.rb
|
108
159
|
- wamp-client.gemspec
|
109
160
|
homepage: ''
|
110
161
|
licenses: []
|
@@ -120,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
171
|
version: '0'
|
121
172
|
segments:
|
122
173
|
- 0
|
123
|
-
hash:
|
174
|
+
hash: 4170054363117719336
|
124
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
176
|
none: false
|
126
177
|
requirements:
|
@@ -129,11 +180,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
180
|
version: '0'
|
130
181
|
segments:
|
131
182
|
- 0
|
132
|
-
hash:
|
183
|
+
hash: 4170054363117719336
|
133
184
|
requirements: []
|
134
185
|
rubyforge_project:
|
135
186
|
rubygems_version: 1.8.23
|
136
187
|
signing_key:
|
137
188
|
specification_version: 3
|
138
189
|
summary: WAMP client
|
139
|
-
test_files:
|
190
|
+
test_files:
|
191
|
+
- test/support/wamp_server.py
|
192
|
+
- test/test_helper.rb
|
193
|
+
- test/unit/client_spec.rb
|