shove 0.52 → 1.0.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.
Files changed (63) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +63 -0
  4. data/README.markdown +263 -0
  5. data/Rakefile +47 -0
  6. data/bin/shove +128 -106
  7. data/lib/shove/app.rb +78 -0
  8. data/lib/shove/app_directory.rb +104 -0
  9. data/lib/shove/client/callback.rb +24 -0
  10. data/lib/shove/client/channel.rb +81 -0
  11. data/lib/shove/client/connection.rb +167 -0
  12. data/lib/shove/http/channel_context.rb +60 -0
  13. data/lib/shove/http/client_context.rb +82 -0
  14. data/lib/shove/http/request.rb +94 -0
  15. data/lib/shove/http/response.rb +30 -0
  16. data/lib/shove/protocol.rb +53 -0
  17. data/lib/shove.rb +60 -78
  18. data/shove.gemspec +11 -20
  19. data/spec/app_directory_spec.rb +66 -0
  20. data/spec/cassettes/should_authorize_oneself.yml +24 -0
  21. data/spec/cassettes/should_be_able_to_authorize_with_the_server.yml +24 -0
  22. data/spec/cassettes/should_cancel_a_binding.yml +24 -0
  23. data/spec/cassettes/should_configure_the_default.yml +24 -0
  24. data/spec/cassettes/should_configure_the_from_the_previous_test.yml +24 -0
  25. data/spec/cassettes/should_create_a_channel_context.yml +24 -0
  26. data/spec/cassettes/should_deny_a_connection.yml +24 -0
  27. data/spec/cassettes/should_deny_a_control_to_a_client.yml +24 -0
  28. data/spec/cassettes/should_deny_a_publishing_to_a_client.yml +24 -0
  29. data/spec/cassettes/should_deny_a_subscriptions_to_a_client.yml +24 -0
  30. data/spec/cassettes/should_deny_publishing_on_a_channel_context.yml +24 -0
  31. data/spec/cassettes/should_deny_subscriptions_on_a_channel_context.yml +24 -0
  32. data/spec/cassettes/should_get_a_set_of_nodes_for_the_network.yml +24 -0
  33. data/spec/cassettes/should_get_a_subscribe_granted_event.yml +24 -0
  34. data/spec/cassettes/should_grant_a_connection.yml +24 -0
  35. data/spec/cassettes/should_grant_a_control_to_a_client.yml +24 -0
  36. data/spec/cassettes/should_grant_a_publishing_to_a_client.yml +24 -0
  37. data/spec/cassettes/should_grant_a_subscriptions_to_a_client.yml +24 -0
  38. data/spec/cassettes/should_grant_publishing_on_a_channel_context.yml +24 -0
  39. data/spec/cassettes/should_grant_subscriptions_on_a_channel_context.yml +24 -0
  40. data/spec/cassettes/should_publish.yml +24 -0
  41. data/spec/cassettes/should_publish_on_a_channel_context.yml +24 -0
  42. data/spec/cassettes/should_publish_to_a_client.yml +24 -0
  43. data/spec/cassettes/should_receive_an_unsubscribe_event.yml +24 -0
  44. data/spec/cassettes/should_receive_messages_on_a_channel.yml +24 -0
  45. data/spec/cassettes/should_send_a_connect_op.yml +24 -0
  46. data/spec/cassettes/should_send_a_connect_op_with_an_id.yml +24 -0
  47. data/spec/cassettes/should_spawn_a_client.yml +24 -0
  48. data/spec/cassettes/should_subscribe_to_a_channel.yml +24 -0
  49. data/spec/cassettes/should_trigger_a_connect_denied_event.yml +24 -0
  50. data/spec/cassettes/should_trigger_a_connect_event.yml +24 -0
  51. data/spec/cassettes/should_trigger_a_disconnect_event.yml +24 -0
  52. data/spec/cassettes/should_trigger_an_error_event.yml +24 -0
  53. data/spec/cassettes/should_unsubscribe_from_a_channel.yml +24 -0
  54. data/spec/cassettes/should_update_the_default_app.yml +24 -0
  55. data/spec/helper.rb +60 -0
  56. data/spec/shove_client_spec.rb +194 -0
  57. data/spec/shove_http_spec.rb +142 -0
  58. metadata +111 -81
  59. data/README.md +0 -71
  60. data/lib/shove/client.rb +0 -54
  61. data/lib/shove/request.rb +0 -80
  62. data/lib/shove/response.rb +0 -23
  63. data/spec/shove_spec.rb +0 -40
@@ -0,0 +1,194 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ describe Shove::Client do
4
+
5
+ before(:all) do
6
+ Shove.configure do
7
+ app_id "test"
8
+ app_key "test"
9
+ api_url "http://api.shove.dev:8080"
10
+ ws_url "ws://shove.dev:9000"
11
+ end
12
+ end
13
+
14
+ before do |context|
15
+ VCR.insert_cassette context.example.metadata[:description_args].first
16
+ $queue.clear
17
+ end
18
+
19
+ after do |context|
20
+ VCR.eject_cassette
21
+ end
22
+
23
+ it "should spawn a client" do
24
+ @client = Shove.app.connect
25
+ @client.should_not == nil
26
+ @client.url.should == "#{Shove.config.ws_url}/test"
27
+ end
28
+
29
+ it "should send a connect op" do
30
+ @client = Shove.app.connect
31
+ message = $queue.pop
32
+ message["opcode"].should == Shove::Protocol::CONNECT
33
+ end
34
+
35
+ it "should send a connect op with an id" do
36
+ @client = Shove.app.connect("monkey")
37
+ message = $queue.pop
38
+ message["opcode"].should == Shove::Protocol::CONNECT
39
+ message["data"].should == "monkey"
40
+ end
41
+
42
+ it "should trigger a connect event" do
43
+ @client = Shove.app.connect
44
+ @client.on("connect") do |client_id|
45
+ @triggered = true
46
+ @id = client_id
47
+ end
48
+
49
+ backdoor :opcode => Shove::Protocol::CONNECT_GRANTED, :data => "tid"
50
+
51
+ @id.should == "tid"
52
+ @triggered.should == true
53
+ end
54
+
55
+ it "should trigger a connect_denied event" do
56
+ @client = Shove.app.connect
57
+ @client.on("connect_denied") do |client_id|
58
+ @triggered = true
59
+ @id = client_id
60
+ end
61
+
62
+ backdoor :opcode => Shove::Protocol::CONNECT_DENIED, :data => "tid"
63
+
64
+ @id.should == "tid"
65
+ @triggered.should == true
66
+ end
67
+
68
+
69
+ it "should trigger a disconnect event" do
70
+ @client = Shove.app.connect
71
+ @client.on("disconnect") do
72
+ @triggered = true
73
+ end
74
+
75
+ backdoor :opcode => Shove::Protocol::DISCONNECT
76
+
77
+ @triggered.should == true
78
+ end
79
+
80
+ it "should trigger an error event" do
81
+ @client = Shove.app.connect
82
+ @client.on("error") do |error|
83
+ @error = error
84
+ end
85
+
86
+ backdoor :opcode => Shove::Protocol::ERROR, :data => "Test Error"
87
+
88
+ @error.should == "Test Error"
89
+ end
90
+
91
+ it "should authorize oneself" do
92
+ @client = Shove.app.connect
93
+ @client.authorize("test")
94
+ $queue.last()["opcode"].should == Shove::Protocol::AUTHORIZE
95
+ end
96
+
97
+ it "should create a channel context" do
98
+ @client = Shove.app.connect
99
+ @channel = @client.channel("channel")
100
+
101
+ @channel.should_not == nil
102
+ @channel.should == @client.channel("channel")
103
+ end
104
+
105
+ it "should subscribe to a channel" do
106
+ @client = Shove.app.connect
107
+ @channel = @client.channel("channel")
108
+ @message = $queue.last
109
+ @message["opcode"].should == Shove::Protocol::SUBSCRIBE
110
+ end
111
+
112
+ it "should get a subscribe granted event" do
113
+ @client = Shove.app.connect
114
+ @channel = @client.channel("channel")
115
+ @channel.on("subscribe") do
116
+ @triggered = true
117
+ end
118
+
119
+ backdoor :opcode => Shove::Protocol::SUBSCRIBE_GRANTED, :channel => "channel"
120
+
121
+ @triggered.should == true
122
+ end
123
+
124
+ it "should receive messages on a channel" do
125
+ @messages = 0
126
+ @message = nil
127
+
128
+ @client = Shove.app.connect
129
+ @channel = @client.channel("channel")
130
+ @channel.on("message") do |msg|
131
+ @messages += 1
132
+ @message = msg
133
+ end
134
+
135
+ backdoor :opcode => Shove::Protocol::PUBLISH, :channel => "channel", :data => "test"
136
+
137
+ @messages.should == 1
138
+ @message.should == "test"
139
+ end
140
+
141
+ it "should cancel a binding" do
142
+ @messages = 0
143
+
144
+ @client = Shove.app.connect
145
+ @channel = @client.channel("channel")
146
+ binding = @channel.on("message") do |msg|
147
+ @messages += 1
148
+ end
149
+
150
+ message = {
151
+ :opcode => Shove::Protocol::PUBLISH,
152
+ :channel => "channel",
153
+ :data => "test"
154
+ }
155
+
156
+ backdoor message
157
+ backdoor message
158
+ binding.cancel
159
+ backdoor message
160
+
161
+ @messages.should == 2
162
+ end
163
+
164
+ it "should unsubscribe from a channel" do
165
+ @client = Shove.app.connect
166
+ @channel = @client.channel("channel")
167
+ @channel.unsubscribe
168
+ @message = $queue.last
169
+ @message["opcode"].should == Shove::Protocol::UNSUBSCRIBE
170
+ end
171
+
172
+ it "should receive an unsubscribe event" do
173
+ @client = Shove.app.connect
174
+ @channel = @client.channel("channel")
175
+ @channel.unsubscribe
176
+ @channel.on("unsubscribe") do
177
+ @triggered = true
178
+ end
179
+
180
+ backdoor :opcode => Shove::Protocol::UNSUBSCRIBE_COMPLETE, :channel => "channel"
181
+
182
+ @triggered.should == true
183
+ end
184
+
185
+
186
+ it "should publish" do
187
+ @client = Shove.app.connect
188
+ @channel = @client.channel("channel")
189
+ @channel.publish "test"
190
+
191
+ $queue.last()["opcode"].should == Shove::Protocol::PUBLISH
192
+ end
193
+
194
+ end
@@ -0,0 +1,142 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ describe Shove:Http do
4
+
5
+ before(:all) do
6
+ Shove.configure do
7
+ app_id "test"
8
+ app_key "test"
9
+ api_url "http://api.shove.dev:8080"
10
+ ws_url "ws://shove.dev:9000"
11
+ end
12
+ end
13
+
14
+ before do |context|
15
+ VCR.insert_cassette context.example.metadata[:description_args].first
16
+ end
17
+
18
+ after do |context|
19
+ VCR.eject_cassette
20
+ end
21
+
22
+ it "should have a version" do
23
+ Shove.const_defined?("Version").should == true
24
+ end
25
+
26
+ it "should have config" do
27
+ Shove.config.app_id.should == "test"
28
+ Shove.config.app_key.should == "test"
29
+ end
30
+
31
+ it "should be able to authorize with the server" do
32
+ valid = Shove.valid?
33
+ valid.should == true
34
+ end
35
+
36
+ it "should get a set of nodes for the network" do
37
+ hosts = Shove.hosts
38
+ hosts.size.should > 0
39
+ end
40
+
41
+ # Channel context tests, basic plumbing
42
+
43
+ it "should spawn a channel context" do
44
+ chan = Shove.channel("test")
45
+ chan.channel.should == "test"
46
+ chan.app.should == Shove.app
47
+ end
48
+
49
+ it "should publish on a channel context" do
50
+ Shove.channel("test").publish("hi") do |response|
51
+ response.error?.should == false
52
+ end
53
+ end
54
+
55
+ it "should grant subscriptions on a channel context" do
56
+ Shove.channel("test").grant_subscribe("dan") do |response|
57
+ response.error?.should == false
58
+ end
59
+ end
60
+
61
+ it "should grant publishing on a channel context" do
62
+ Shove.channel("test").grant_publish("dan") do |response|
63
+ response.error?.should == false
64
+ end
65
+ end
66
+
67
+ it "should deny subscriptions on a channel context" do
68
+ Shove.channel("test").deny_subscribe("dan") do |response|
69
+ response.error?.should == false
70
+ end
71
+ end
72
+
73
+ it "should deny publishing on a channel context" do
74
+ Shove.channel("test").deny_publish("dan") do |response|
75
+ response.error?.should == false
76
+ end
77
+ end
78
+
79
+ # Client context tests, basic plumbing
80
+
81
+ it "should spawn a client context" do
82
+ chan = Shove.client("dan")
83
+ chan.id.should == "dan"
84
+ chan.app.should == Shove.app
85
+ end
86
+
87
+ it "should grant a connection" do
88
+ Shove.client("dan").grant_connect do |response|
89
+ response.error?.should == false
90
+ end
91
+ end
92
+
93
+ it "should deny a connection" do
94
+ Shove.client("dan").deny_connect do |response|
95
+ response.error?.should == false
96
+ end
97
+ end
98
+
99
+ it "should publish to a client" do
100
+ Shove.client("dan").publish("hi") do |response|
101
+ response.error?.should == false
102
+ end
103
+ end
104
+
105
+ it "should grant a subscriptions to a client" do
106
+ Shove.client("dan").grant_subscribe("channel") do |response|
107
+ response.error?.should == false
108
+ end
109
+ end
110
+
111
+ it "should grant a publishing to a client" do
112
+ Shove.client("dan").grant_publish("channel") do |response|
113
+ response.error?.should == false
114
+ end
115
+ end
116
+
117
+ it "should grant a control to a client" do
118
+ Shove.client("dan").grant_control do |response|
119
+ response.error?.should == false
120
+ end
121
+ end
122
+
123
+ it "should deny a subscriptions to a client" do
124
+ Shove.client("dan").deny_subscribe("channel") do |response|
125
+ response.error?.should == false
126
+ end
127
+ end
128
+
129
+ it "should deny a publishing to a client" do
130
+ Shove.client("dan").deny_publish("channel") do |response|
131
+ response.error?.should == false
132
+ end
133
+ end
134
+
135
+ it "should deny a control to a client" do
136
+ Shove.client("dan").deny_control do |response|
137
+ response.error?.should == false
138
+ end
139
+ end
140
+
141
+
142
+ end
metadata CHANGED
@@ -1,116 +1,146 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: shove
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 52
8
- version: "0.52"
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
9
6
  platform: ruby
10
- authors:
7
+ authors:
11
8
  - Dan Simpson
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
-
16
- date: 2011-03-26 00:00:00 -07:00
17
- default_executable:
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: em-http-request
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &13961220 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - "="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 3
30
- - 0
31
- version: 0.3.0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: commander
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *13961220
25
+ - !ruby/object:Gem::Dependency
26
+ name: em-ws-client
27
+ requirement: &13930020 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 4
44
- - 0
45
- - 3
46
- version: 4.0.3
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.1
47
33
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
34
+ prerelease: false
35
+ version_requirements: *13930020
36
+ - !ruby/object:Gem::Dependency
50
37
  name: yajl-ruby
38
+ requirement: &13924920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.0
44
+ type: :runtime
51
45
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *13924920
47
+ - !ruby/object:Gem::Dependency
48
+ name: confstruct
49
+ requirement: &13918240 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- - 8
60
- - 1
61
- version: 0.8.1
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.1
62
55
  type: :runtime
63
- version_requirements: *id003
56
+ prerelease: false
57
+ version_requirements: *13918240
64
58
  description: Client side implementation for the shove.io API. See http://shove.io/documentation
65
59
  email: dan@shove.io
66
- executables:
60
+ executables:
67
61
  - shove
68
62
  extensions: []
69
-
70
63
  extra_rdoc_files: []
71
-
72
- files:
73
- - README.md
74
- - shove.gemspec
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.markdown
75
69
  - Rakefile
76
- - spec/helper.rb
77
- - spec/shove_spec.rb
78
- - lib/shove.rb
79
- - lib/shove/request.rb
80
- - lib/shove/response.rb
81
- - lib/shove/client.rb
82
70
  - bin/shove
83
- has_rdoc: true
84
- homepage: https://github.com/shove/shover
71
+ - lib/shove.rb
72
+ - lib/shove/app.rb
73
+ - lib/shove/app_directory.rb
74
+ - lib/shove/client/callback.rb
75
+ - lib/shove/client/channel.rb
76
+ - lib/shove/client/connection.rb
77
+ - lib/shove/http/channel_context.rb
78
+ - lib/shove/http/client_context.rb
79
+ - lib/shove/http/request.rb
80
+ - lib/shove/http/response.rb
81
+ - lib/shove/protocol.rb
82
+ - shove.gemspec
83
+ - spec/app_directory_spec.rb
84
+ - spec/cassettes/should_authorize_oneself.yml
85
+ - spec/cassettes/should_be_able_to_authorize_with_the_server.yml
86
+ - spec/cassettes/should_cancel_a_binding.yml
87
+ - spec/cassettes/should_configure_the_default.yml
88
+ - spec/cassettes/should_configure_the_from_the_previous_test.yml
89
+ - spec/cassettes/should_create_a_channel_context.yml
90
+ - spec/cassettes/should_deny_a_connection.yml
91
+ - spec/cassettes/should_deny_a_control_to_a_client.yml
92
+ - spec/cassettes/should_deny_a_publishing_to_a_client.yml
93
+ - spec/cassettes/should_deny_a_subscriptions_to_a_client.yml
94
+ - spec/cassettes/should_deny_publishing_on_a_channel_context.yml
95
+ - spec/cassettes/should_deny_subscriptions_on_a_channel_context.yml
96
+ - spec/cassettes/should_get_a_set_of_nodes_for_the_network.yml
97
+ - spec/cassettes/should_get_a_subscribe_granted_event.yml
98
+ - spec/cassettes/should_grant_a_connection.yml
99
+ - spec/cassettes/should_grant_a_control_to_a_client.yml
100
+ - spec/cassettes/should_grant_a_publishing_to_a_client.yml
101
+ - spec/cassettes/should_grant_a_subscriptions_to_a_client.yml
102
+ - spec/cassettes/should_grant_publishing_on_a_channel_context.yml
103
+ - spec/cassettes/should_grant_subscriptions_on_a_channel_context.yml
104
+ - spec/cassettes/should_publish.yml
105
+ - spec/cassettes/should_publish_on_a_channel_context.yml
106
+ - spec/cassettes/should_publish_to_a_client.yml
107
+ - spec/cassettes/should_receive_an_unsubscribe_event.yml
108
+ - spec/cassettes/should_receive_messages_on_a_channel.yml
109
+ - spec/cassettes/should_send_a_connect_op.yml
110
+ - spec/cassettes/should_send_a_connect_op_with_an_id.yml
111
+ - spec/cassettes/should_spawn_a_client.yml
112
+ - spec/cassettes/should_subscribe_to_a_channel.yml
113
+ - spec/cassettes/should_trigger_a_connect_denied_event.yml
114
+ - spec/cassettes/should_trigger_a_connect_event.yml
115
+ - spec/cassettes/should_trigger_a_disconnect_event.yml
116
+ - spec/cassettes/should_trigger_an_error_event.yml
117
+ - spec/cassettes/should_unsubscribe_from_a_channel.yml
118
+ - spec/cassettes/should_update_the_default_app.yml
119
+ - spec/helper.rb
120
+ - spec/shove_client_spec.rb
121
+ - spec/shove_http_spec.rb
122
+ homepage: https://github.com/shove/shove-ruby
85
123
  licenses: []
86
-
87
124
  post_install_message:
88
125
  rdoc_options: []
89
-
90
- require_paths:
126
+ require_paths:
91
127
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
128
+ required_ruby_version: !ruby/object:Gem::Requirement
93
129
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- segments:
98
- - 0
99
- version: "0"
100
- required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
135
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- segments:
106
- - 0
107
- version: "0"
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
108
140
  requirements: []
109
-
110
141
  rubyforge_project:
111
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.8.10
112
143
  signing_key:
113
144
  specification_version: 3
114
145
  summary: Ruby gem for leveraging shove.io, the web push platform
115
146
  test_files: []
116
-
data/README.md DELETED
@@ -1,71 +0,0 @@
1
- #shover
2
-
3
- * The official ruby gem for shove.io's REST API
4
-
5
- ##Install Step 1
6
-
7
- gem install shove
8
-
9
- ##Install Step 2
10
- Grab your network id and API key from shove at [http://shove.io/customer/network/api_access#ruby][0]
11
-
12
- ##Install Step 3
13
- Configure shover with your credentials
14
-
15
- require "shove"
16
-
17
- Shove.configure(
18
- :network => "network",
19
- :key => "apikey",
20
- :cluster => "cluster"
21
- )
22
-
23
- ##Broadcasting
24
-
25
- # broadcast the "hello" event on the "default" channel with
26
- # Hello World! as the data
27
- Shove.broadcast("default", "hello", "Hello World!") do |response|
28
- puts response.error?
29
- puts response.status
30
- puts response.message
31
- end
32
-
33
- ##Send direct messages
34
-
35
- Shove.direct(userid, "hello", "Hello World!") do |response|
36
- # handle response
37
- end
38
-
39
- ##Subscription Authorization
40
-
41
- # authorize user with id userid on channel "default"
42
- Shove.authorize(userid, "default") do |response|
43
- # handle response
44
- end
45
-
46
- ##Channel Streaming
47
-
48
- # stream all data on channel "default"
49
- Shove.stream("default") do |msg|
50
-
51
- # msg has several properties
52
- puts msg[:channel]
53
- puts msg[:event]
54
- puts msg[:to] # this will either be empty or self
55
- puts msg[:from] # message sender
56
- puts msg[:data] # the payload
57
-
58
- end
59
-
60
- ##Block and Non-blocking
61
- shover does both. If the shover code happens to run inside of an EM.run block, the HTTP calls
62
- will leverage em-http-request. Otherwise, the requests fallback to net/http requests. We recommend
63
- using EM if possible.
64
-
65
- ##CLI (Command line interface)
66
- The shove gem comes with a command line tool for controlling the network.
67
- View documentation @ [http://shove.io/documentation/cli][1]
68
-
69
-
70
- [0]: http://shove.io/customer/network/api_access
71
- [1]: http://shove.io/documentation/cli
data/lib/shove/client.rb DELETED
@@ -1,54 +0,0 @@
1
- module Shove
2
- class Client
3
-
4
- # create an API client
5
- # +network+ the network id
6
- # +key+ the api access key
7
- # +opts+ hash with a few options, such as:
8
- # :secure true or false
9
- # :host leave as default unless you are given a private cluster
10
- def initialize opts={}
11
- @network = opts[:network]
12
- @cluster = opts[:cluster] || "a01"
13
- @secure = opts[:secure] || false
14
- @host = opts[:host] || "api-#{@cluster}.shove.io"
15
- end
16
-
17
- # broadcast a message
18
- # +channel+ the channel to broadcast on
19
- # +event+ the event to trigger
20
- # +message+ the message to send, UTF-8 encoded kthx
21
- def broadcast channel, event, message, &block
22
- Request.new("#{uri}/broadcast/#{channel}/#{event}").post(message, &block)
23
- end
24
-
25
- # direct a message to a specific user
26
- # +uid+ the users id
27
- # +event+ the event to trigger
28
- # +message+ the message to send, UTF-8 encoded kthx
29
- def direct uid, event, message, &block
30
- Request.new("#{uri}/direct/#{event}/#{uid}").post(message, &block)
31
- end
32
-
33
- # authorize a user on a private channel
34
- # +uid+ the users id
35
- # +channel+ the channel to authorize them on
36
- def authorize uid, channel="*", &block
37
- Request.new("#{uri}/authorize/#{channel}/#{uid}").post(&block)
38
- end
39
-
40
- # validate current API settings
41
- def validate
42
- Request.new("#{uri}/validate").post do |response|
43
- return response
44
- end
45
- end
46
-
47
- protected
48
-
49
- def uri
50
- (@secure ? "https" : "http") + "://#{@host}/#{@network}"
51
- end
52
-
53
- end
54
- end