shove 1.0.7 → 1.0.8

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.
Files changed (53) hide show
  1. data/Gemfile +1 -2
  2. data/README.markdown +57 -91
  3. data/Rakefile +0 -23
  4. data/lib/shove.rb +3 -70
  5. data/lib/shove/app.rb +40 -33
  6. data/lib/shove/client/channel.rb +4 -0
  7. data/lib/shove/client/connection.rb +32 -14
  8. data/lib/shove/http/request.rb +2 -2
  9. data/lib/shove/protocol.rb +3 -1
  10. data/shove.gemspec +1 -3
  11. data/spec/cassettes/should_be_able_to_authorize_with_the_server.yml +10 -6
  12. data/spec/cassettes/should_deny_a_connection.yml +10 -6
  13. data/spec/cassettes/should_deny_a_control_to_a_client.yml +10 -6
  14. data/spec/cassettes/should_deny_a_publishing_to_a_client.yml +10 -6
  15. data/spec/cassettes/should_deny_a_subscriptions_to_a_client.yml +10 -6
  16. data/spec/cassettes/should_deny_publishing_on_a_channel_context.yml +10 -6
  17. data/spec/cassettes/should_deny_subscriptions_on_a_channel_context.yml +10 -6
  18. data/spec/cassettes/should_get_a_set_of_nodes_for_the_network.yml +11 -7
  19. data/spec/cassettes/should_grant_a_connection.yml +10 -6
  20. data/spec/cassettes/should_grant_a_control_to_a_client.yml +11 -7
  21. data/spec/cassettes/should_grant_a_publishing_to_a_client.yml +10 -6
  22. data/spec/cassettes/should_grant_a_subscriptions_to_a_client.yml +10 -6
  23. data/spec/cassettes/should_grant_publishing_on_a_channel_context.yml +10 -6
  24. data/spec/cassettes/should_grant_subscriptions_on_a_channel_context.yml +10 -6
  25. data/spec/cassettes/should_publish_on_a_channel_context.yml +10 -6
  26. data/spec/cassettes/should_publish_to_a_client.yml +10 -6
  27. data/spec/helper.rb +0 -2
  28. data/spec/shove_client_spec.rb +39 -30
  29. data/spec/shove_http_spec.rb +27 -31
  30. metadata +20 -40
  31. data/bin/shove +0 -169
  32. data/lib/shove/app_directory.rb +0 -103
  33. data/spec/app_directory_spec.rb +0 -66
  34. data/spec/cassettes/should_authorize_on_a_channel.yml +0 -26
  35. data/spec/cassettes/should_authorize_oneself.yml +0 -24
  36. data/spec/cassettes/should_cancel_a_binding.yml +0 -24
  37. data/spec/cassettes/should_configure_the_default.yml +0 -24
  38. data/spec/cassettes/should_configure_the_from_the_previous_test.yml +0 -24
  39. data/spec/cassettes/should_create_a_channel_context.yml +0 -24
  40. data/spec/cassettes/should_get_a_subscribe_granted_event.yml +0 -24
  41. data/spec/cassettes/should_publish.yml +0 -24
  42. data/spec/cassettes/should_receive_an_unsubscribe_event.yml +0 -24
  43. data/spec/cassettes/should_receive_messages_on_a_channel.yml +0 -24
  44. data/spec/cassettes/should_send_a_connect_op.yml +0 -24
  45. data/spec/cassettes/should_send_a_connect_op_with_an_id.yml +0 -24
  46. data/spec/cassettes/should_spawn_a_client.yml +0 -24
  47. data/spec/cassettes/should_subscribe_to_a_channel.yml +0 -24
  48. data/spec/cassettes/should_trigger_a_connect_denied_event.yml +0 -24
  49. data/spec/cassettes/should_trigger_a_connect_event.yml +0 -24
  50. data/spec/cassettes/should_trigger_a_disconnect_event.yml +0 -24
  51. data/spec/cassettes/should_trigger_an_error_event.yml +0 -24
  52. data/spec/cassettes/should_unsubscribe_from_a_channel.yml +0 -24
  53. data/spec/cassettes/should_update_the_default_app.yml +0 -24
@@ -82,6 +82,10 @@ module Shove
82
82
  @conn.send_data :opcode => AUTHORIZE, :channel => @name, :data => channel_key.to_s
83
83
  end
84
84
 
85
+ def auth channel_key
86
+ authorize channel_key
87
+ end
88
+
85
89
  private
86
90
 
87
91
  def emit event, *args
@@ -8,12 +8,9 @@ module Shove
8
8
 
9
9
  # Create a Publisher
10
10
  # +app+ the app
11
- def initialize app, id
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
- def authorize app_key=nil
25
- send_data :opcode => AUTHORIZE, :data => (app_key || @config.app_key)
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 => @id
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 @config.ws_url
92
- @url = "#{@config.ws_url}/#{@config.app_id}"
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.first}/#{@config.app_id}"
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
- @reconnecting = true
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.first
195
+ @app.hosts.sample
178
196
  end
179
197
 
180
198
  end
@@ -6,9 +6,9 @@ module Shove
6
6
 
7
7
  attr_accessor :url, :key, :headers
8
8
 
9
- def initialize url, config
9
+ def initialize url, app
10
10
  @url = url
11
- @key = config.app_key
11
+ @key = app.app_key
12
12
  end
13
13
 
14
14
  # HTTP Delete request
@@ -9,7 +9,9 @@ module Shove
9
9
  CONNECT_DENIED = 0x03
10
10
  DISCONNECT = 0x04
11
11
  DISCONNECT_COMPLETE = 0x06
12
-
12
+ REDIRECT = 0x07
13
+ SET_IDENTITY = 0x08
14
+
13
15
  # Subscribe Ops
14
16
  SUBSCRIBE = 0x10
15
17
  SUBSCRIBE_GRANTED = 0x11
@@ -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
- s.add_dependency("confstruct", ">= 0.2.1")
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:8080/apps/test/validate
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: ! '{"code":"200 Ok","details":"Ok"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/deny_connect?client=dan
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: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/deny_control?client=dan
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: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/deny_publish?channel=channel&client=dan
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: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/deny_subscribe?channel=channel&client=dan
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: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/deny_publish?channel=test&client=dan
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: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/deny_subscribe?channel=test&client=dan
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: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/hosts
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
- - '19'
21
- body: ! '["test-1","test-2"]'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/grant_connect?client=dan
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: ! '{"code":"200 Ok","details":"Ok"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/grant_control?client=dan
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
- - '36'
21
- body: ! '{"code":"400","error":"Invalid URL"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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:8080/apps/test/grant_publish?channel=channel&client=dan
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: ! '{"code":"200 Ok","details":"Ok"}'
22
- http_version: !!null
23
- recorded_at: Fri, 17 Feb 2012 01:53:24 GMT
24
- recorded_with: VCR 2.0.0.rc1
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