shove 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shove.rb CHANGED
@@ -8,6 +8,7 @@ require "em-ws-client"
8
8
  require "yajl"
9
9
  require "yaml"
10
10
  require "confstruct"
11
+ require "digest/sha1"
11
12
 
12
13
  ##
13
14
  # Shove
@@ -17,7 +18,7 @@ require "confstruct"
17
18
  # See https://github.com/shove/shove for client documentation
18
19
  module Shove
19
20
 
20
- Version = "1.0.3"
21
+ Version = "1.0.4"
21
22
 
22
23
  class ShoveException < Exception; end
23
24
 
@@ -80,6 +81,17 @@ module Shove
80
81
  @app.connect
81
82
  end
82
83
 
84
+ # Create a channel key
85
+ # +channel+ the name of the channel
86
+ def channel_key channel, key=nil
87
+ if key.nil?
88
+ key = @config.app_key
89
+ end
90
+ digest = Digest::SHA1.hexdigest "#{key}-#{channel}"
91
+ end
92
+
93
+
94
+
83
95
  end
84
96
  end
85
97
 
@@ -66,6 +66,11 @@ module Shove
66
66
  @conn.send_data :opcode => UNSUBSCRIBE, :channel => @name
67
67
  end
68
68
 
69
+ # authorize pub/sub on this channel
70
+ def authorize channel_key
71
+ @conn.send_data :opcode => AUTHORIZE, :channel => @name, :data => channel_key
72
+ end
73
+
69
74
  private
70
75
 
71
76
  def emit event, *args
data/shove.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "shove"
3
- s.version = "1.0.3"
3
+ s.version = "1.0.4"
4
4
  s.date = "2012-02-08"
5
5
  s.summary = "Ruby gem for leveraging shove.io, the web push platform"
6
6
  s.email = "dan@shove.io"
@@ -0,0 +1,26 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://:test@api.shove.dev:8080/apps/test/hosts
6
+ body: ''
7
+ headers:
8
+ Accept:
9
+ - ! '*/*'
10
+ User-Agent:
11
+ - Ruby
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Content-Type:
18
+ - application/json
19
+ Content-Length:
20
+ - '2'
21
+ Connection:
22
+ - keep-alive
23
+ body: ! '[]'
24
+ http_version:
25
+ recorded_at: Fri, 06 Apr 2012 04:15:48 GMT
26
+ recorded_with: VCR 2.0.0.rc1
@@ -191,4 +191,22 @@ describe Shove::Client do
191
191
  $queue.last()["opcode"].should == Shove::Protocol::PUBLISH
192
192
  end
193
193
 
194
+ it "should generate a channel key" do
195
+ key = Shove.channel_key "money", "key"
196
+ key.should == "e627e0e305c60b6ccb164f8baafdbc8d84f0d032"
197
+ end
198
+
199
+ it "should authorize on a channel" do
200
+ @client = Shove.app.connect
201
+ @channel = @client.channel("channel")
202
+ @channel.authorize "key"
203
+
204
+ item = $queue.last()
205
+
206
+ item["opcode"].should == Shove::Protocol::AUTHORIZE
207
+ item["data"].should == "key"
208
+ item["channel"].should == "channel"
209
+
210
+ end
211
+
194
212
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shove
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-08 00:00:00.000000000Z
12
+ date: 2012-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &22523120 !ruby/object:Gem::Requirement
16
+ requirement: &70199512602620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22523120
24
+ version_requirements: *70199512602620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-ws-client
27
- requirement: &22522380 !ruby/object:Gem::Requirement
27
+ requirement: &70199512546900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.1.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22522380
35
+ version_requirements: *70199512546900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yajl-ruby
38
- requirement: &22521920 !ruby/object:Gem::Requirement
38
+ requirement: &70199508320220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *22521920
46
+ version_requirements: *70199508320220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: confstruct
49
- requirement: &22521440 !ruby/object:Gem::Requirement
49
+ requirement: &70199508298620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.2.1
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *22521440
57
+ version_requirements: *70199508298620
58
58
  description: Client side implementation for the shove.io API. See http://shove.io/documentation
59
59
  email: dan@shove.io
60
60
  executables:
@@ -81,6 +81,7 @@ files:
81
81
  - lib/shove/protocol.rb
82
82
  - shove.gemspec
83
83
  - spec/app_directory_spec.rb
84
+ - spec/cassettes/should_authorize_on_a_channel.yml
84
85
  - spec/cassettes/should_authorize_oneself.yml
85
86
  - spec/cassettes/should_be_able_to_authorize_with_the_server.yml
86
87
  - spec/cassettes/should_cancel_a_binding.yml
@@ -139,8 +140,48 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  requirements: []
141
142
  rubyforge_project:
142
- rubygems_version: 1.8.10
143
+ rubygems_version: 1.8.11
143
144
  signing_key:
144
145
  specification_version: 3
145
146
  summary: Ruby gem for leveraging shove.io, the web push platform
146
- test_files: []
147
+ test_files:
148
+ - spec/app_directory_spec.rb
149
+ - spec/cassettes/should_authorize_on_a_channel.yml
150
+ - spec/cassettes/should_authorize_oneself.yml
151
+ - spec/cassettes/should_be_able_to_authorize_with_the_server.yml
152
+ - spec/cassettes/should_cancel_a_binding.yml
153
+ - spec/cassettes/should_configure_the_default.yml
154
+ - spec/cassettes/should_configure_the_from_the_previous_test.yml
155
+ - spec/cassettes/should_create_a_channel_context.yml
156
+ - spec/cassettes/should_deny_a_connection.yml
157
+ - spec/cassettes/should_deny_a_control_to_a_client.yml
158
+ - spec/cassettes/should_deny_a_publishing_to_a_client.yml
159
+ - spec/cassettes/should_deny_a_subscriptions_to_a_client.yml
160
+ - spec/cassettes/should_deny_publishing_on_a_channel_context.yml
161
+ - spec/cassettes/should_deny_subscriptions_on_a_channel_context.yml
162
+ - spec/cassettes/should_get_a_set_of_nodes_for_the_network.yml
163
+ - spec/cassettes/should_get_a_subscribe_granted_event.yml
164
+ - spec/cassettes/should_grant_a_connection.yml
165
+ - spec/cassettes/should_grant_a_control_to_a_client.yml
166
+ - spec/cassettes/should_grant_a_publishing_to_a_client.yml
167
+ - spec/cassettes/should_grant_a_subscriptions_to_a_client.yml
168
+ - spec/cassettes/should_grant_publishing_on_a_channel_context.yml
169
+ - spec/cassettes/should_grant_subscriptions_on_a_channel_context.yml
170
+ - spec/cassettes/should_publish.yml
171
+ - spec/cassettes/should_publish_on_a_channel_context.yml
172
+ - spec/cassettes/should_publish_to_a_client.yml
173
+ - spec/cassettes/should_receive_an_unsubscribe_event.yml
174
+ - spec/cassettes/should_receive_messages_on_a_channel.yml
175
+ - spec/cassettes/should_send_a_connect_op.yml
176
+ - spec/cassettes/should_send_a_connect_op_with_an_id.yml
177
+ - spec/cassettes/should_spawn_a_client.yml
178
+ - spec/cassettes/should_subscribe_to_a_channel.yml
179
+ - spec/cassettes/should_trigger_a_connect_denied_event.yml
180
+ - spec/cassettes/should_trigger_a_connect_event.yml
181
+ - spec/cassettes/should_trigger_a_disconnect_event.yml
182
+ - spec/cassettes/should_trigger_an_error_event.yml
183
+ - spec/cassettes/should_unsubscribe_from_a_channel.yml
184
+ - spec/cassettes/should_update_the_default_app.yml
185
+ - spec/helper.rb
186
+ - spec/shove_client_spec.rb
187
+ - spec/shove_http_spec.rb