pusher 0.10.0 → 0.11.0

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.
@@ -70,6 +70,12 @@ describe Pusher do
70
70
  it "should send [] messages to different objects" do
71
71
  @client1['test'].should_not == @client2['test']
72
72
  end
73
+
74
+ it "should send http_proxy messages to different objects" do
75
+ @client1.http_proxy = 'http://oneuser:onepassword@onehost:8080'
76
+ @client2.http_proxy = 'http://twouser:twopassword@twohost:8880'
77
+ @client1.http_proxy.should_not == @client2.http_proxy
78
+ end
73
79
  end
74
80
 
75
81
  # The behaviour should be the same when using the Client object, or the
@@ -125,6 +131,14 @@ describe Pusher do
125
131
  end
126
132
  end
127
133
 
134
+ describe 'configuring a http proxy' do
135
+ it "should be possible to configure everything by setting the http_proxy" do
136
+ @client.http_proxy = 'http://someuser:somepassword@proxy.host.com:8080'
137
+
138
+ @client.proxy.should == {:scheme => 'http', :host => 'proxy.host.com', :port => 8080, :user => 'someuser', :password => 'somepassword'}
139
+ end
140
+ end
141
+
128
142
  describe 'when configured' do
129
143
  before :each do
130
144
  @client.app_id = '20'
@@ -141,12 +155,6 @@ describe Pusher do
141
155
  @channel.should be_kind_of(Pusher::Channel)
142
156
  end
143
157
 
144
- it "should reuse the same channel objects" do
145
- channel1, channel2 = @client['test_channel'], @client['test_channel']
146
-
147
- channel1.object_id.should == channel2.object_id
148
- end
149
-
150
158
  %w{app_id key secret}.each do |config|
151
159
  it "should raise exception if #{config} not configured" do
152
160
  @client.send("#{config}=", nil)
@@ -160,7 +168,7 @@ describe Pusher do
160
168
  describe '#channels' do
161
169
  it "should call the correct URL and symbolise response correctly" do
162
170
  api_path = %r{/apps/20/channels}
163
- WebMock.stub_request(:get, api_path).to_return({
171
+ stub_request(:get, api_path).to_return({
164
172
  :status => 200,
165
173
  :body => MultiJson.encode('channels' => {
166
174
  "channel1" => {},
@@ -179,7 +187,7 @@ describe Pusher do
179
187
  describe '#channel_info' do
180
188
  it "should call correct URL and symbolise response" do
181
189
  api_path = %r{/apps/20/channels/mychannel}
182
- WebMock.stub_request(:get, api_path).to_return({
190
+ stub_request(:get, api_path).to_return({
183
191
  :status => 200,
184
192
  :body => MultiJson.encode({
185
193
  'occupied' => false,
@@ -194,32 +202,218 @@ describe Pusher do
194
202
  describe '#trigger' do
195
203
  before :each do
196
204
  @api_path = %r{/apps/20/events}
197
- WebMock.stub_request(:post, @api_path).to_return({
205
+ stub_request(:post, @api_path).to_return({
198
206
  :status => 200,
199
207
  :body => MultiJson.encode({})
200
208
  })
201
209
  end
202
210
 
203
211
  it "should call correct URL" do
204
- @client.trigger('mychannel', 'event', {'some' => 'data'}).
212
+ @client.trigger(['mychannel'], 'event', {'some' => 'data'}).
205
213
  should == {}
206
214
  end
207
215
 
208
- it "should pass any options in the body of the request" do
209
- @client.trigger('mychannel', 'event', {'some' => 'data'}, {
216
+ it "should pass any parameters in the body of the request" do
217
+ @client.trigger(['mychannel', 'c2'], 'event', {'some' => 'data'}, {
210
218
  :socket_id => "1234"
211
219
  })
212
220
  WebMock.should have_requested(:post, @api_path).with { |req|
213
- MultiJson.decode(req.body)["socket_id"].should == '1234'
221
+ parsed = MultiJson.decode(req.body)
222
+ parsed["name"].should == 'event'
223
+ parsed["channels"].should == ["mychannel", "c2"]
224
+ parsed["socket_id"].should == '1234'
214
225
  }
215
226
  end
216
227
 
217
228
  it "should convert non string data to JSON before posting" do
218
- @client.trigger('mychannel', 'event', {'some' => 'data'})
229
+ @client.trigger(['mychannel'], 'event', {'some' => 'data'})
219
230
  WebMock.should have_requested(:post, @api_path).with { |req|
220
231
  MultiJson.decode(req.body)["data"].should == '{"some":"data"}'
221
232
  }
222
233
  end
234
+
235
+ it "should accept a single channel as well as an array" do
236
+ @client.trigger('mychannel', 'event', {'some' => 'data'})
237
+ WebMock.should have_requested(:post, @api_path).with { |req|
238
+ MultiJson.decode(req.body)["channels"].should == ['mychannel']
239
+ }
240
+ end
241
+ end
242
+
243
+ describe '#trigger_async' do
244
+ before :each do
245
+ @api_path = %r{/apps/20/events}
246
+ stub_request(:post, @api_path).to_return({
247
+ :status => 200,
248
+ :body => MultiJson.encode({})
249
+ })
250
+ end
251
+
252
+ it "should call correct URL" do
253
+ EM.run {
254
+ @client.trigger_async('mychannel', 'event', {'some' => 'data'}).callback { |r|
255
+ r.should == {}
256
+ EM.stop
257
+ }
258
+ }
259
+ end
260
+
261
+ it "should pass any parameters in the body of the request" do
262
+ EM.run {
263
+ @client.trigger_async('mychannel', 'event', {'some' => 'data'}, {
264
+ :socket_id => "1234"
265
+ }).callback {
266
+ WebMock.should have_requested(:post, @api_path).with { |req|
267
+ MultiJson.decode(req.body)["socket_id"].should == '1234'
268
+ }
269
+ EM.stop
270
+ }
271
+ }
272
+ end
273
+
274
+ it "should convert non string data to JSON before posting" do
275
+ EM.run {
276
+ @client.trigger_async('mychannel', 'event', {'some' => 'data'}).callback {
277
+ WebMock.should have_requested(:post, @api_path).with { |req|
278
+ MultiJson.decode(req.body)["data"].should == '{"some":"data"}'
279
+ }
280
+ EM.stop
281
+ }
282
+ }
283
+ end
284
+ end
285
+
286
+ [:get, :post].each do |verb|
287
+ describe "##{verb}" do
288
+ before :each do
289
+ @url_regexp = %r{api.pusherapp.com}
290
+ stub_request(verb, @url_regexp).
291
+ to_return(:status => 200, :body => "{}")
292
+ end
293
+
294
+ let(:call_api) { @client.send(verb, '/path') }
295
+
296
+ it "should use http by default" do
297
+ call_api
298
+ WebMock.should have_requested(verb, %r{http://api.pusherapp.com/apps/20/path})
299
+ end
300
+
301
+ it "should use https if configured" do
302
+ @client.encrypted = true
303
+ call_api
304
+ WebMock.should have_requested(verb, %r{https://api.pusherapp.com})
305
+ end
306
+
307
+ it "should format the respose hash with symbols at first level" do
308
+ stub_request(verb, @url_regexp).to_return({
309
+ :status => 200,
310
+ :body => MultiJson.encode({'something' => {'a' => 'hash'}})
311
+ })
312
+ call_api.should == {
313
+ :something => {'a' => 'hash'}
314
+ }
315
+ end
316
+
317
+ it "should catch all Net::HTTP exceptions and raise a Pusher::HTTPError wrapping the original error" do
318
+ stub_request(verb, @url_regexp).to_raise(Timeout::Error)
319
+
320
+ error = nil
321
+ begin
322
+ call_api
323
+ rescue => e
324
+ error = e
325
+ end
326
+
327
+ error.class.should == Pusher::HTTPError
328
+ error.should be_kind_of(Pusher::Error)
329
+ error.message.should == 'Exception from WebMock (Timeout::Error)'
330
+ error.original_error.class.should == Timeout::Error
331
+ end
332
+
333
+ it "should raise Pusher::Error if call returns 400" do
334
+ stub_request(verb, @url_regexp).to_return({:status => 400})
335
+ lambda { call_api }.should raise_error(Pusher::Error)
336
+ end
337
+
338
+ it "should raise AuthenticationError if pusher returns 401" do
339
+ stub_request(verb, @url_regexp).to_return({:status => 401})
340
+ lambda { call_api }.should raise_error(Pusher::AuthenticationError)
341
+ end
342
+
343
+ it "should raise Pusher::Error if pusher returns 404" do
344
+ stub_request(verb, @url_regexp).to_return({:status => 404})
345
+ lambda { call_api }.should raise_error(Pusher::Error, '404 Not found (/apps/20/path)')
346
+ end
347
+
348
+ it "should raise Pusher::Error if pusher returns 407" do
349
+ stub_request(verb, @url_regexp).to_return({:status => 407})
350
+ lambda { call_api }.should raise_error(Pusher::Error, 'Proxy Authentication Required')
351
+ end
352
+
353
+ it "should raise Pusher::Error if pusher returns 500" do
354
+ stub_request(verb, @url_regexp).to_return({:status => 500, :body => "some error"})
355
+ lambda { call_api }.should raise_error(Pusher::Error, 'Unknown error (status code 500): some error')
356
+ end
357
+ end
358
+ end
359
+
360
+ [[:get, :get_async], [:post, :post_async]].each do |verb, method|
361
+ describe "##{method}" do
362
+ before :each do
363
+ @url_regexp = %r{api.pusherapp.com}
364
+ stub_request(verb, @url_regexp).
365
+ to_return(:status => 200, :body => "{}")
366
+ end
367
+
368
+ let(:call_api) { @client.send(method, '/path') }
369
+
370
+ it "should use http by default" do
371
+ EM.run {
372
+ call_api.callback {
373
+ WebMock.should have_requested(verb, %r{http://api.pusherapp.com/apps/20/path})
374
+ EM.stop
375
+ }
376
+ }
377
+ end
378
+
379
+ it "should use https if configured" do
380
+ EM.run {
381
+ @client.encrypted = true
382
+ call_api.callback {
383
+ WebMock.should have_requested(verb, %r{https://api.pusherapp.com})
384
+ EM.stop
385
+ }
386
+ }
387
+ end
388
+
389
+ it "should format the respose hash with symbols at first level" do
390
+ EM.run {
391
+ stub_request(verb, @url_regexp).to_return({
392
+ :status => 200,
393
+ :body => MultiJson.encode({'something' => {'a' => 'hash'}})
394
+ })
395
+ call_api.callback { |response|
396
+ response.should == {
397
+ :something => {'a' => 'hash'}
398
+ }
399
+ EM.stop
400
+ }
401
+ }
402
+ end
403
+
404
+ it "should errback with Pusher::Error on unsuccessful response" do
405
+ EM.run {
406
+ stub_request(verb, @url_regexp).to_return({:status => 400})
407
+
408
+ call_api.errback { |e|
409
+ e.class.should == Pusher::Error
410
+ EM.stop
411
+ }.callback {
412
+ fail
413
+ }
414
+ }
415
+ end
416
+ end
223
417
  end
224
418
  end
225
419
  end
@@ -12,7 +12,14 @@ require 'webmock/rspec'
12
12
  require 'pusher'
13
13
  require 'eventmachine'
14
14
 
15
+ RSpec.configure do |config|
16
+ config.before(:each) do
17
+ WebMock.reset!
18
+ WebMock.disable_net_connect!
19
+ end
20
+ end
21
+
15
22
  def hmac(key, data)
16
23
  digest = OpenSSL::Digest::SHA256.new
17
24
  expected = OpenSSL::HMAC.hexdigest(digest, key, data)
18
- end
25
+ end
@@ -43,12 +43,12 @@ describe Pusher::WebHook do
43
43
 
44
44
  describe "after initialization" do
45
45
  before :each do
46
- body = MultiJson.encode(@hook_data)
46
+ @body = MultiJson.encode(@hook_data)
47
47
  request = {
48
48
  :key => '1234',
49
- :signature => hmac('asdf', body),
49
+ :signature => hmac('asdf', @body),
50
50
  :content_type => 'application/json',
51
- :body => body
51
+ :body => @body
52
52
  }
53
53
 
54
54
  @client = Pusher::Client.new
@@ -71,7 +71,9 @@ describe Pusher::WebHook do
71
71
  it "should not validate if secret is wrong" do
72
72
  @client.key = '1234'
73
73
  @client.secret = 'asdfxxx'
74
- Pusher.logger.should_receive(:warn).with("Received WebHook with invalid signature: got a18bd1374b3b198ec457fb11d636ee2024d8077fc542829443729988bd1e4aa4, expected bb81a112a46dee1e4154ee4f328621f32558192c7af12adfc0395082cfcd3c6c")
74
+ digest = OpenSSL::Digest::SHA256.new
75
+ expected = OpenSSL::HMAC.hexdigest(digest, @client.secret, @body)
76
+ Pusher.logger.should_receive(:warn).with("Received WebHook with invalid signature: got #{@wh.signature}, expected #{expected}")
75
77
  @wh.should_not be_valid
76
78
  end
77
79
 
@@ -112,4 +114,4 @@ describe Pusher::WebHook do
112
114
  @wh.time.should == Time.at(123.456)
113
115
  end
114
116
  end
115
- end
117
+ end
metadata CHANGED
@@ -1,136 +1,135 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pusher
3
- version: !ruby/object:Gem::Version
4
- hash: 55
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 0
10
- version: 0.10.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Pusher
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-28 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: multi_json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 15
29
- segments:
30
- - 1
31
- - 0
32
- version: "1.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: signature
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
39
25
  none: false
40
- requirements:
26
+ requirements:
41
27
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 19
44
- segments:
45
- - 0
46
- - 1
47
- - 4
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: signature
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
48
37
  version: 0.1.4
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rspec
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
55
49
  none: false
56
- requirements:
50
+ requirements:
57
51
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 2
62
- - 0
63
- version: "2.0"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
64
54
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: webmock
68
55
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ requirement: !ruby/object:Gem::Requirement
70
65
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
78
70
  type: :development
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: em-http-request
82
71
  prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: em-http-request
80
+ requirement: !ruby/object:Gem::Requirement
84
81
  none: false
85
- requirements:
82
+ requirements:
86
83
  - - ~>
87
- - !ruby/object:Gem::Version
88
- hash: 23
89
- segments:
90
- - 1
91
- - 0
92
- - 0
84
+ - !ruby/object:Gem::Version
93
85
  version: 1.0.0
94
86
  type: :development
95
- version_requirements: *id005
96
- - !ruby/object:Gem::Dependency
97
- name: rake
98
87
  prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
100
89
  none: false
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- hash: 3
105
- segments:
106
- - 0
107
- version: "0"
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
108
102
  type: :development
109
- version_requirements: *id006
110
- - !ruby/object:Gem::Dependency
111
- name: rack
112
103
  prerelease: false
113
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rack
112
+ requirement: !ruby/object:Gem::Requirement
114
113
  none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- hash: 3
119
- segments:
120
- - 0
121
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
122
118
  type: :development
123
- version_requirements: *id007
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
124
126
  description: Wrapper for pusher.com REST api
125
- email:
127
+ email:
126
128
  - support@pusher.com
127
129
  executables: []
128
-
129
130
  extensions: []
130
-
131
131
  extra_rdoc_files: []
132
-
133
- files:
132
+ files:
134
133
  - .document
135
134
  - .gemtest
136
135
  - .gitignore
@@ -144,7 +143,9 @@ files:
144
143
  - lib/pusher.rb
145
144
  - lib/pusher/channel.rb
146
145
  - lib/pusher/client.rb
146
+ - lib/pusher/query_encoder.rb
147
147
  - lib/pusher/request.rb
148
+ - lib/pusher/resource.rb
148
149
  - lib/pusher/webhook.rb
149
150
  - pusher.gemspec
150
151
  - spec/channel_spec.rb
@@ -153,38 +154,35 @@ files:
153
154
  - spec/web_hook_spec.rb
154
155
  homepage: http://github.com/pusher/pusher-gem
155
156
  licenses: []
156
-
157
157
  post_install_message:
158
158
  rdoc_options: []
159
-
160
- require_paths:
159
+ require_paths:
161
160
  - lib
162
- required_ruby_version: !ruby/object:Gem::Requirement
161
+ required_ruby_version: !ruby/object:Gem::Requirement
163
162
  none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ segments:
169
168
  - 0
170
- version: "0"
171
- required_rubygems_version: !ruby/object:Gem::Requirement
169
+ hash: -545190286375519249
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
171
  none: false
173
- requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- hash: 3
177
- segments:
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ segments:
178
177
  - 0
179
- version: "0"
178
+ hash: -545190286375519249
180
179
  requirements: []
181
-
182
180
  rubyforge_project:
183
- rubygems_version: 1.8.6
181
+ rubygems_version: 1.8.24
184
182
  signing_key:
185
183
  specification_version: 3
186
184
  summary: Pusher API client
187
- test_files:
185
+ test_files:
188
186
  - spec/channel_spec.rb
189
187
  - spec/client_spec.rb
190
188
  - spec/spec_helper.rb