shove 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -2
- data/README.markdown +57 -91
- data/Rakefile +0 -23
- data/lib/shove.rb +3 -70
- data/lib/shove/app.rb +40 -33
- data/lib/shove/client/channel.rb +4 -0
- data/lib/shove/client/connection.rb +32 -14
- data/lib/shove/http/request.rb +2 -2
- data/lib/shove/protocol.rb +3 -1
- data/shove.gemspec +1 -3
- data/spec/cassettes/should_be_able_to_authorize_with_the_server.yml +10 -6
- data/spec/cassettes/should_deny_a_connection.yml +10 -6
- data/spec/cassettes/should_deny_a_control_to_a_client.yml +10 -6
- data/spec/cassettes/should_deny_a_publishing_to_a_client.yml +10 -6
- data/spec/cassettes/should_deny_a_subscriptions_to_a_client.yml +10 -6
- data/spec/cassettes/should_deny_publishing_on_a_channel_context.yml +10 -6
- data/spec/cassettes/should_deny_subscriptions_on_a_channel_context.yml +10 -6
- data/spec/cassettes/should_get_a_set_of_nodes_for_the_network.yml +11 -7
- data/spec/cassettes/should_grant_a_connection.yml +10 -6
- data/spec/cassettes/should_grant_a_control_to_a_client.yml +11 -7
- data/spec/cassettes/should_grant_a_publishing_to_a_client.yml +10 -6
- data/spec/cassettes/should_grant_a_subscriptions_to_a_client.yml +10 -6
- data/spec/cassettes/should_grant_publishing_on_a_channel_context.yml +10 -6
- data/spec/cassettes/should_grant_subscriptions_on_a_channel_context.yml +10 -6
- data/spec/cassettes/should_publish_on_a_channel_context.yml +10 -6
- data/spec/cassettes/should_publish_to_a_client.yml +10 -6
- data/spec/helper.rb +0 -2
- data/spec/shove_client_spec.rb +39 -30
- data/spec/shove_http_spec.rb +27 -31
- metadata +20 -40
- data/bin/shove +0 -169
- data/lib/shove/app_directory.rb +0 -103
- data/spec/app_directory_spec.rb +0 -66
- data/spec/cassettes/should_authorize_on_a_channel.yml +0 -26
- data/spec/cassettes/should_authorize_oneself.yml +0 -24
- data/spec/cassettes/should_cancel_a_binding.yml +0 -24
- data/spec/cassettes/should_configure_the_default.yml +0 -24
- data/spec/cassettes/should_configure_the_from_the_previous_test.yml +0 -24
- data/spec/cassettes/should_create_a_channel_context.yml +0 -24
- data/spec/cassettes/should_get_a_subscribe_granted_event.yml +0 -24
- data/spec/cassettes/should_publish.yml +0 -24
- data/spec/cassettes/should_receive_an_unsubscribe_event.yml +0 -24
- data/spec/cassettes/should_receive_messages_on_a_channel.yml +0 -24
- data/spec/cassettes/should_send_a_connect_op.yml +0 -24
- data/spec/cassettes/should_send_a_connect_op_with_an_id.yml +0 -24
- data/spec/cassettes/should_spawn_a_client.yml +0 -24
- data/spec/cassettes/should_subscribe_to_a_channel.yml +0 -24
- data/spec/cassettes/should_trigger_a_connect_denied_event.yml +0 -24
- data/spec/cassettes/should_trigger_a_connect_event.yml +0 -24
- data/spec/cassettes/should_trigger_a_disconnect_event.yml +0 -24
- data/spec/cassettes/should_trigger_an_error_event.yml +0 -24
- data/spec/cassettes/should_unsubscribe_from_a_channel.yml +0 -24
- data/spec/cassettes/should_update_the_default_app.yml +0 -24
data/lib/shove/client/channel.rb
CHANGED
@@ -8,12 +8,9 @@ module Shove
|
|
8
8
|
|
9
9
|
# Create a Publisher
|
10
10
|
# +app+ the app
|
11
|
-
def initialize app
|
12
|
-
@id = id
|
11
|
+
def initialize app
|
13
12
|
@app = app
|
14
13
|
@parser = Yajl::Parser.new(:symbolize_keys => true)
|
15
|
-
@config = app.config
|
16
|
-
@hosts = app.hosts
|
17
14
|
@channels = {}
|
18
15
|
@events = {}
|
19
16
|
@queue = []
|
@@ -21,10 +18,14 @@ module Shove
|
|
21
18
|
@connected = false
|
22
19
|
end
|
23
20
|
|
24
|
-
|
25
|
-
|
21
|
+
# helper to auth on all channels if app_key is supplied
|
22
|
+
def auth!
|
23
|
+
if @app.app_key
|
24
|
+
channel("*").auth @app.channel_key("*")
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
|
+
|
28
29
|
# Enable or disable debugging
|
29
30
|
# +on+ true to enable debugging
|
30
31
|
def debug on=true
|
@@ -32,7 +33,8 @@ module Shove
|
|
32
33
|
end
|
33
34
|
|
34
35
|
# Connect to the shove stream server
|
35
|
-
def connect
|
36
|
+
def connect connect_key=nil
|
37
|
+
@connect_key = connect_key
|
36
38
|
|
37
39
|
if @connected
|
38
40
|
return
|
@@ -49,13 +51,18 @@ module Shove
|
|
49
51
|
|
50
52
|
@socket.onopen do
|
51
53
|
@connected = true
|
52
|
-
send_data :opcode => CONNECT, :data => @
|
54
|
+
send_data :opcode => CONNECT, :data => (connect_key || @app.connect_key)
|
55
|
+
auth!
|
53
56
|
until @queue.empty? do
|
54
57
|
send_data @queue.shift
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
@socket.onmessage do |m, binary|
|
62
|
+
if @debug
|
63
|
+
puts "DEBUG RECV #{m}"
|
64
|
+
end
|
65
|
+
|
59
66
|
process(Yajl::Parser.parse(m))
|
60
67
|
end
|
61
68
|
|
@@ -88,21 +95,27 @@ module Shove
|
|
88
95
|
end
|
89
96
|
|
90
97
|
def url
|
91
|
-
if @
|
92
|
-
@url = "#{@
|
98
|
+
if @app.ws_url
|
99
|
+
@url = "#{@app.ws_url}/#{@app.app_id}"
|
93
100
|
else
|
94
|
-
if @hosts.empty?
|
101
|
+
if @app.hosts.empty?
|
95
102
|
raise "Error fetching hosts for app #{@app_id}"
|
96
103
|
end
|
97
|
-
@url = "ws://#{@hosts.
|
104
|
+
@url = "ws://#{@app.hosts.sample}/#{@app.app_id}"
|
98
105
|
end
|
99
106
|
@url
|
100
107
|
end
|
101
108
|
|
102
109
|
def send_data data
|
103
110
|
if @connected
|
111
|
+
if @debug
|
112
|
+
puts "DEBUG SEND #{data}"
|
113
|
+
end
|
104
114
|
@socket.send_message(Yajl::Encoder.encode(data))
|
105
115
|
else
|
116
|
+
if @debug
|
117
|
+
puts "DEBUG QUEUE #{data}"
|
118
|
+
end
|
106
119
|
@queue << data
|
107
120
|
end
|
108
121
|
end
|
@@ -110,7 +123,12 @@ module Shove
|
|
110
123
|
protected
|
111
124
|
|
112
125
|
def reconnect
|
113
|
-
@
|
126
|
+
unless @forcedc
|
127
|
+
@reconnecting = true
|
128
|
+
EM.add_timer(1) do
|
129
|
+
connect @connect_key
|
130
|
+
end
|
131
|
+
end
|
114
132
|
end
|
115
133
|
|
116
134
|
def emit event, *args
|
@@ -174,7 +192,7 @@ module Shove
|
|
174
192
|
end
|
175
193
|
|
176
194
|
def host
|
177
|
-
@hosts.
|
195
|
+
@app.hosts.sample
|
178
196
|
end
|
179
197
|
|
180
198
|
end
|
data/lib/shove/http/request.rb
CHANGED
data/lib/shove/protocol.rb
CHANGED
data/shove.gemspec
CHANGED
@@ -14,9 +14,7 @@ spec = Gem::Specification.new do |s|
|
|
14
14
|
s.add_dependency("em-http-request", ">= 1.0.0")
|
15
15
|
s.add_dependency("em-ws-client", ">= 0.2.0")
|
16
16
|
s.add_dependency("yajl-ruby", ">= 1.1.0")
|
17
|
-
|
18
|
-
|
19
|
-
s.bindir = "bin"
|
17
|
+
|
20
18
|
s.authors = ["Dan Simpson"]
|
21
19
|
|
22
20
|
s.files = `git ls-files`.split("\n")
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/validate
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '32'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"200 Ok","details":"Ok"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/deny_connect?client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '36'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"400","error":"Invalid URL"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/deny_control?client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '36'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"400","error":"Invalid URL"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/deny_publish?channel=channel&client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '36'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"400","error":"Invalid URL"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/deny_subscribe?channel=channel&client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '36'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"400","error":"Invalid URL"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/deny_publish?channel=test&client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '36'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"400","error":"Invalid URL"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/deny_subscribe?channel=test&client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '36'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"400","error":"Invalid URL"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/hosts
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -17,8 +19,10 @@ http_interactions:
|
|
17
19
|
Content-Type:
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
|
-
- '
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
- '17'
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '["thor.shove.io"]'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/grant_connect?client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '32'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"200 Ok","details":"Ok"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/grant_control?client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -17,8 +19,10 @@ http_interactions:
|
|
17
19
|
Content-Type:
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
|
-
- '
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
- '32'
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"200 Ok","details":"Ok"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|
@@ -2,8 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://:test@api.shove.dev:
|
6
|
-
body:
|
5
|
+
uri: http://:test@api.shove.dev:8000/apps/test/grant_publish?channel=channel&client=dan
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
7
9
|
headers:
|
8
10
|
Accept:
|
9
11
|
- ! '*/*'
|
@@ -18,7 +20,9 @@ http_interactions:
|
|
18
20
|
- application/json; charset=UTF-8
|
19
21
|
Content-Length:
|
20
22
|
- '32'
|
21
|
-
body:
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"code":"200 Ok","details":"Ok"}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Wed, 23 May 2012 02:35:38 GMT
|
28
|
+
recorded_with: VCR 2.0.1
|