pusher 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -18,6 +18,7 @@ coverage
18
18
  rdoc
19
19
  pkg
20
20
  .yardoc
21
+ Gemfile.lock
21
22
 
22
23
  ## PROJECT::SPECIFIC
23
24
  .bundle
data/README.md CHANGED
@@ -10,7 +10,7 @@ After registering at <http://pusherapp.com> configure your app with the security
10
10
  Pusher.key = 'your-pusher-key'
11
11
  Pusher.secret = 'your-pusher-secret'
12
12
 
13
- Trigger an event
13
+ Trigger an event with {Pusher::Channel#trigger!}
14
14
 
15
15
  Pusher['a_channel'].trigger!('an_event', {:some => 'data'})
16
16
 
@@ -26,7 +26,7 @@ Optionally a socket id may be provided. This will exclude the event from being t
26
26
 
27
27
  Pusher['a_channel'].trigger!('an_event', {:some => 'data'}, socket_id)
28
28
 
29
- If you don't need to handle failure cases, then you can simply use the `trigger` method, which will rescue and log any errors for you
29
+ If you don't need to handle failure cases, then you can simply use the {Pusher::Channel#trigger} method, which will rescue and log any errors for you
30
30
 
31
31
  Pusher['a_channel'].trigger('an_event', {:some => 'data'})
32
32
 
@@ -40,7 +40,7 @@ Errors are logged to `Pusher.logger`. It will by default use `Logger` from stdli
40
40
  Asynchronous triggering
41
41
  -----------------------
42
42
 
43
- To avoid blocking in a typical web application, you may wish to use the `trigger_async` method which uses the makes asynchronous API requests to Pusher. `trigger_async` returns a deferrable which you can optionally bind to with success and failure callbacks.
43
+ To avoid blocking in a typical web application, you may wish to use the {Pusher::Channel#trigger_async} method which makes asynchronous API requests. `trigger_async` returns a deferrable which you can optionally bind to with success and failure callbacks.
44
44
 
45
45
  You need to be running eventmachine to make use of this functionality. This is already the case if, for example, you're deploying to Heroku or using the Thin web server. You will also need to add `em-http-request` to your Gemfile.
46
46
 
@@ -64,7 +64,7 @@ The Pusher Gem also deals with signing requests for authenticated private channe
64
64
  reponse = Pusher['private-my_channel'].authenticate(params[:socket_id])
65
65
  render :json => response
66
66
 
67
- Read more about private channels in [the docs](http://pusherapp.com/docs/private_channels).
67
+ Read more about private channels in [the docs](http://pusherapp.com/docs/private_channels) and under {Pusher::Channel#authenticate}.
68
68
 
69
69
  Developing
70
70
  ----------
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |s|
7
+ s.pattern = 'spec/**/*.rb'
8
+ end
9
+
10
+ task :default => :spec
11
+ task :test => :spec
data/lib/pusher.rb CHANGED
@@ -26,12 +26,12 @@ module Pusher
26
26
  # @private
27
27
  def logger
28
28
  @logger ||= begin
29
- log = Logger.new(STDOUT)
29
+ log = Logger.new($stdout)
30
30
  log.level = Logger::INFO
31
31
  log
32
32
  end
33
33
  end
34
-
34
+
35
35
  # @private
36
36
  def authentication_token
37
37
  Signature::Token.new(@key, @secret)
@@ -103,6 +103,5 @@ module Pusher
103
103
  end
104
104
  end
105
105
 
106
- require 'pusher/json'
107
106
  require 'pusher/channel'
108
- require 'pusher/request'
107
+ require 'pusher/request'
@@ -1,5 +1,6 @@
1
1
  require 'crack/core_extensions' # Used for Hash#to_params
2
2
  require 'hmac-sha2'
3
+ require 'multi_json'
3
4
 
4
5
  module Pusher
5
6
  # Trigger events on Channels
@@ -69,8 +70,8 @@ module Pusher
69
70
  # @param socket_id Allows excluding a given socket_id from receiving the
70
71
  # event - see http://pusherapp.com/docs/duplicates for more info
71
72
  #
72
- # @raise [Pusher::Error] on invalid Pusher response
73
- # @raise any Net::HTTP related errors
73
+ # @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
74
+ # @raise [Pusher::HTTPError] on any error raised inside Net::HTTP - the original error is available in the original_error attribute
74
75
  #
75
76
  def trigger!(event_name, data, socket_id = nil)
76
77
  require 'net/http' unless defined?(Net::HTTP)
@@ -139,15 +140,27 @@ module Pusher
139
140
 
140
141
  # Generate an authentication endpoint response
141
142
  #
142
- # @example
143
+ # @example Private channels
143
144
  # render :json => Pusher['private-my_channel'].authenticate(params[:socket_id])
144
145
  #
146
+ # @example Presence channels
147
+ # render :json => Pusher['private-my_channel'].authenticate(params[:socket_id], {
148
+ # :user_id => current_user.id, # => required
149
+ # :user_info => { # => optional - for example
150
+ # :name => current_user.name,
151
+ # :email => current_user.email
152
+ # }
153
+ # })
154
+ #
155
+ # @param socket_id [String]
156
+ # @param custom_data [Hash] used for example by private channels
157
+ #
145
158
  # @return [Hash]
146
159
  #
147
160
  # @private Custom data is sent to server as JSON-encoded string
148
161
  #
149
162
  def authenticate(socket_id, custom_data = nil)
150
- custom_data = Pusher::JSON.generate(custom_data) if custom_data
163
+ custom_data = MultiJson.encode(custom_data) if custom_data
151
164
  auth = socket_auth(socket_id, custom_data)
152
165
  r = {:auth => auth}
153
166
  r[:channel_data] = custom_data if custom_data
@@ -1,5 +1,6 @@
1
1
  require 'signature'
2
2
  require 'digest/md5'
3
+ require 'multi_json'
3
4
 
4
5
  module Pusher
5
6
  class Request
@@ -16,8 +17,8 @@ module Pusher
16
17
  data
17
18
  else
18
19
  begin
19
- Pusher::JSON.generate(data)
20
- rescue => e
20
+ MultiJson.encode(data)
21
+ rescue MultiJson::DecodeError => e
21
22
  Pusher.logger.error("Could not convert #{data.inspect} into JSON")
22
23
  raise e
23
24
  end
data/pusher.gemspec CHANGED
@@ -3,19 +3,19 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pusher"
6
- s.version = "0.8.0"
6
+ s.version = "0.8.1"
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["New Bamboo"]
9
- s.email = ["support@pusherapp.com"]
8
+ s.authors = ["Pusher"]
9
+ s.email = ["support@pusher.com"]
10
10
  s.homepage = "http://github.com/newbamboo/pusher-gem"
11
- s.summary = %q{Pusherapp client}
12
- s.description = %q{Wrapper for pusherapp.com REST api}
13
-
14
- s.add_dependency "json", "~> 1.4.0"
15
- s.add_dependency "crack", "~> 0.1.0"
11
+ s.summary = %q{Pusher API client}
12
+ s.description = %q{Wrapper for pusher.com REST api}
13
+
14
+ s.add_dependency "multi_json", "~> 1.0"
15
+ s.add_dependency "crack", "~> 0.1.0"
16
16
  s.add_dependency "ruby-hmac", "~> 0.4.0"
17
17
  s.add_dependency 'signature', "~> 0.1.2"
18
-
18
+
19
19
  s.add_development_dependency "rspec", "~> 2.0"
20
20
  s.add_development_dependency "webmock"
21
21
  s.add_development_dependency "em-http-request", "~> 0.2.7"
data/spec/channel_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Pusher::Channel do
4
4
  before do
@@ -20,7 +20,7 @@ describe Pusher::Channel do
20
20
  Pusher.key = nil
21
21
  Pusher.secret = nil
22
22
  end
23
-
23
+
24
24
  describe 'trigger!' do
25
25
  before :each do
26
26
  WebMock.stub_request(:post, @pusher_url_regexp).
@@ -50,7 +50,7 @@ describe Pusher::Channel do
50
50
  query_hash["auth_key"].should == Pusher.key
51
51
  query_hash["auth_timestamp"].should_not be_nil
52
52
 
53
- parsed = JSON.parse(req.body)
53
+ parsed = MultiJson.decode(req.body)
54
54
  parsed.should == {
55
55
  "name" => 'Pusher',
56
56
  "last_name" => 'App'
@@ -68,12 +68,6 @@ describe Pusher::Channel do
68
68
  end
69
69
  end
70
70
 
71
- it "should raise error on non string values with cannot be jsonified" do
72
- lambda {
73
- @channel.trigger!('new_event', Object.new)
74
- }.should raise_error(JSON::GeneratorError)
75
- end
76
-
77
71
  it "should catch all Net::HTTP exceptions and raise a Pusher::HTTPError, exposing the original error if required" do
78
72
  WebMock.stub_request(
79
73
  :post, %r{/apps/20/channels/test_channel/events}
@@ -92,7 +86,7 @@ describe Pusher::Channel do
92
86
 
93
87
  it "should raise AuthenticationError if pusher returns 401" do
94
88
  WebMock.stub_request(
95
- :post,
89
+ :post,
96
90
  %r{/apps/20/channels/test_channel/events}
97
91
  ).to_return(:status => 401)
98
92
  lambda {
@@ -211,48 +205,48 @@ describe Pusher::Channel do
211
205
  }.should raise_error
212
206
  end
213
207
  end
214
-
208
+
215
209
  describe 'with extra string argument' do
216
-
210
+
217
211
  it 'should be a string or nil' do
218
212
  lambda {
219
213
  @channel.socket_auth('socketid', 'boom')
220
214
  }.should_not raise_error
221
-
215
+
222
216
  lambda {
223
217
  @channel.socket_auth('socketid', 123)
224
218
  }.should raise_error
225
-
219
+
226
220
  lambda {
227
221
  @channel.socket_auth('socketid', nil)
228
222
  }.should_not raise_error
229
-
223
+
230
224
  lambda {
231
225
  @channel.socket_auth('socketid', {})
232
226
  }.should raise_error
233
227
  end
234
-
228
+
235
229
  it "should return an authentication string given a socket id and custom args" do
236
230
  auth = @channel.socket_auth('socketid', 'foobar')
237
231
 
238
232
  auth.should == "12345678900000001:#{HMAC::SHA256.hexdigest(Pusher.secret, "socketid:test_channel:foobar")}"
239
233
  end
240
-
234
+
241
235
  end
242
236
  end
243
-
237
+
244
238
  describe '#authenticate' do
245
-
239
+
246
240
  before :each do
247
241
  @channel = Pusher['test_channel']
248
242
  @custom_data = {:uid => 123, :info => {:name => 'Foo'}}
249
243
  end
250
-
244
+
251
245
  it 'should return a hash with signature including custom data and data as json string' do
252
- Pusher::JSON.stub!(:generate).with(@custom_data).and_return 'a json string'
253
-
246
+ MultiJson.stub!(:encode).with(@custom_data).and_return 'a json string'
247
+
254
248
  response = @channel.authenticate('socketid', @custom_data)
255
-
249
+
256
250
  response.should == {
257
251
  :auth => "12345678900000001:#{HMAC::SHA256.hexdigest(Pusher.secret, "socketid:test_channel:a json string")}",
258
252
  :channel_data => 'a json string'
data/spec/pusher_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  require 'em-http'
4
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,13 @@
1
- require 'rubygems'
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'although not required, it is recommended that you use bundler when running the tests'
5
+ end
2
6
 
3
7
  require 'rspec'
4
8
  require 'rspec/autorun'
5
9
  require 'em-http' # As of webmock 1.4.0, em-http must be loaded first
6
10
  require 'webmock/rspec'
7
11
 
8
- $LOAD_PATH.unshift(File.dirname(__FILE__))
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
-
11
12
  require 'pusher'
12
13
  require 'eventmachine'
13
-
14
- RSpec.configure do |config|
15
- config.include WebMock::API
16
- end
metadata CHANGED
@@ -1,35 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 8
8
- - 0
9
- version: 0.8.0
4
+ prerelease:
5
+ version: 0.8.1
10
6
  platform: ruby
11
7
  authors:
12
- - New Bamboo
8
+ - Pusher
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-17 00:00:00 +00:00
13
+ date: 2011-05-17 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: json
17
+ name: multi_json
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
24
20
  none: false
25
21
  requirements:
26
22
  - - ~>
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 4
31
- - 0
32
- version: 1.4.0
24
+ version: "1.0"
33
25
  type: :runtime
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
@@ -40,10 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ~>
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 1
46
- - 0
47
35
  version: 0.1.0
48
36
  type: :runtime
49
37
  version_requirements: *id002
@@ -55,10 +43,6 @@ dependencies:
55
43
  requirements:
56
44
  - - ~>
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 4
61
- - 0
62
46
  version: 0.4.0
63
47
  type: :runtime
64
48
  version_requirements: *id003
@@ -70,10 +54,6 @@ dependencies:
70
54
  requirements:
71
55
  - - ~>
72
56
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- - 1
76
- - 2
77
57
  version: 0.1.2
78
58
  type: :runtime
79
59
  version_requirements: *id004
@@ -85,9 +65,6 @@ dependencies:
85
65
  requirements:
86
66
  - - ~>
87
67
  - !ruby/object:Gem::Version
88
- segments:
89
- - 2
90
- - 0
91
68
  version: "2.0"
92
69
  type: :development
93
70
  version_requirements: *id005
@@ -99,8 +76,6 @@ dependencies:
99
76
  requirements:
100
77
  - - ">="
101
78
  - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
79
  version: "0"
105
80
  type: :development
106
81
  version_requirements: *id006
@@ -112,16 +87,12 @@ dependencies:
112
87
  requirements:
113
88
  - - ~>
114
89
  - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- - 2
118
- - 7
119
90
  version: 0.2.7
120
91
  type: :development
121
92
  version_requirements: *id007
122
- description: Wrapper for pusherapp.com REST api
93
+ description: Wrapper for pusher.com REST api
123
94
  email:
124
- - support@pusherapp.com
95
+ - support@pusher.com
125
96
  executables: []
126
97
 
127
98
  extensions: []
@@ -130,16 +101,15 @@ extra_rdoc_files: []
130
101
 
131
102
  files:
132
103
  - .document
104
+ - .gemtest
133
105
  - .gitignore
134
106
  - .travis.yml
135
107
  - Gemfile
136
- - Gemfile.lock
137
108
  - LICENSE
138
109
  - README.md
139
110
  - Rakefile
140
111
  - lib/pusher.rb
141
112
  - lib/pusher/channel.rb
142
- - lib/pusher/json.rb
143
113
  - lib/pusher/request.rb
144
114
  - pusher.gemspec
145
115
  - spec/channel_spec.rb
@@ -159,24 +129,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
129
  requirements:
160
130
  - - ">="
161
131
  - !ruby/object:Gem::Version
162
- segments:
163
- - 0
164
132
  version: "0"
165
133
  required_rubygems_version: !ruby/object:Gem::Requirement
166
134
  none: false
167
135
  requirements:
168
136
  - - ">="
169
137
  - !ruby/object:Gem::Version
170
- segments:
171
- - 0
172
138
  version: "0"
173
139
  requirements: []
174
140
 
175
141
  rubyforge_project:
176
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.6.2
177
143
  signing_key:
178
144
  specification_version: 3
179
- summary: Pusherapp client
145
+ summary: Pusher API client
180
146
  test_files:
181
147
  - spec/channel_spec.rb
182
148
  - spec/pusher_spec.rb
data/Gemfile.lock DELETED
@@ -1,43 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- pusher (0.7.0)
5
- crack (~> 0.1.0)
6
- json (~> 1.4.0)
7
- ruby-hmac (~> 0.4.0)
8
- signature (~> 0.1.2)
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- addressable (2.2.4)
14
- crack (0.1.8)
15
- diff-lcs (1.1.2)
16
- em-http-request (0.2.15)
17
- addressable (>= 2.0.0)
18
- eventmachine (>= 0.12.9)
19
- eventmachine (0.12.10)
20
- json (1.4.6)
21
- rspec (2.5.0)
22
- rspec-core (~> 2.5.0)
23
- rspec-expectations (~> 2.5.0)
24
- rspec-mocks (~> 2.5.0)
25
- rspec-core (2.5.1)
26
- rspec-expectations (2.5.0)
27
- diff-lcs (~> 1.1.2)
28
- rspec-mocks (2.5.0)
29
- ruby-hmac (0.4.0)
30
- signature (0.1.2)
31
- ruby-hmac
32
- webmock (1.6.2)
33
- addressable (>= 2.2.2)
34
- crack (>= 0.1.7)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- em-http-request (~> 0.2.7)
41
- pusher!
42
- rspec (~> 2.0)
43
- webmock
data/lib/pusher/json.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'json'
2
-
3
- module Pusher
4
- module JSON
5
-
6
- def self.generate(data)
7
- if Object.const_defined?('ActiveSupport')
8
- ActiveSupport::JSON.encode(data)
9
- else
10
- ::JSON.generate(data)
11
- end
12
- end
13
-
14
- end
15
- end