pusher 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 529c89c30b29ce1e8ba4558f0efbab8e2983e898
4
+ data.tar.gz: 328df39b09ed4f244a2a8576de2d4c16d7c6d53b
5
+ SHA512:
6
+ metadata.gz: 7d38ac2d891c4c5772f2f37511ff132a9258bff1fed9a2c23edddda00c034b3bca4b3d0d6673b45d3787271ac1366bf1d17382b7487167e3db9d87a2eff2d8cc
7
+ data.tar.gz: e9ff5af00c144d87fbe2de78f88b7b5d54b82a16968b01377c75154950ba1eb4efc15a5e10c0df99f2acb2016adbd43980af97481ff5c8c97dbff44c2276d670
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Pusher
1
+ Copyright (c) 2010-2013 Pusher
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -73,26 +73,22 @@ Errors are logged to `Pusher.logger`. It will by default log at info level to ST
73
73
 
74
74
  ### Publishing events
75
75
 
76
- An event can be sent to Pusher in in the following ways:
76
+ An event can be published to one or more channels (limited to 100) in one API call:
77
77
 
78
- # on the Pusher class
79
- Pusher.trigger('channel_name', 'event_name', {some: 'data'})
80
- Pusher.trigger(['channel_1', 'channel_2'], 'event_name', {some: 'data'})
81
-
82
- # or on a pusher_client
83
- pusher_client.trigger(['your_channels'], 'your_event_name', {some: 'data'})
78
+ Pusher.trigger('channel', 'event', {foo: 'bar'})
79
+ Pusher.trigger(['channel_1', 'channel_2'], 'event_name', {foo: 'bar'})
84
80
 
85
- Note: the first `channels` argument can contain multiple channels you'd like your event and data payload to go to. There is a limit of 100 on the number of channels this can contain.
81
+ An optional fourth argument may be used to send additional parameters to the API, for example to [exclude a single connection from receiving the event](http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients).
86
82
 
87
- An optional fourth argument of this method can specify a `socket_id` that will be excluded from receiving the event (generally the user where the event originated -- see <http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients> for more info).
83
+ Pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
88
84
 
89
- #### Original publisher API
85
+ #### Deprecated publisher API
90
86
 
91
87
  Most examples and documentation will refer to the following syntax for triggering an event:
92
88
 
93
89
  Pusher['a_channel'].trigger('an_event', {:some => 'data'})
94
90
 
95
- This will continue to work, but will be replaced as the canonical version by `Pusher.trigger` which supports multiple channels.
91
+ This will continue to work, but has been replaced by `Pusher.trigger` which supports one or multiple channels.
96
92
 
97
93
  ### Generic requests to the Pusher REST API
98
94
 
@@ -142,7 +138,7 @@ A HTTP error or an error response from pusher will cause the errback to be calle
142
138
 
143
139
  #### Without eventmachine
144
140
 
145
- If the eventmachine reactor is not running, async requests will be make using threads (managed by the httpclient gem).
141
+ If the eventmachine reactor is not running, async requests will be made using threads (managed by the httpclient gem).
146
142
 
147
143
  An `HTTPClient::Connection` object is returned immediately which can be [interrogated](http://rubydoc.info/gems/httpclient/HTTPClient/Connection) to discover the status of the request. The usual response checking and processing is not done when the request completes, and frankly this method is most useful when you're not interested in waiting for the response.
148
144
 
@@ -5,9 +5,14 @@ module Pusher
5
5
  # Trigger events on Channels
6
6
  class Channel
7
7
  attr_reader :name
8
-
8
+ INVALID_CHANNEL_REGEX = /[^A-Za-z0-9_\-=@,.;]/
9
9
  def initialize(base_url, name, client = Pusher)
10
10
  @uri = base_url.dup
11
+ if Pusher::Channel::INVALID_CHANNEL_REGEX.match(name)
12
+ raise Pusher::Error, "Illegal channel name '#{name}'"
13
+ elsif name.length > 200
14
+ raise Pusher::Error, "Channel name too long (limit 100 characters) '#{name}'"
15
+ end
11
16
  @uri.path = @uri.path + "/channels/#{name}/"
12
17
  @name = name
13
18
  @client = client
@@ -168,7 +168,9 @@ module Pusher
168
168
  # Pusher['my-channel']
169
169
  # @return [Channel]
170
170
  # @raise [ConfigurationError] unless key, secret and app_id have been
171
- # configured
171
+ # configured. Channel names should be less than 200 characters, and
172
+ # should not contain anything other than letters, numbers, or the
173
+ # characters "_\-=@,.;"
172
174
  def channel(channel_name)
173
175
  raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
174
176
  Channel.new(url, channel_name, self)
@@ -195,7 +197,7 @@ module Pusher
195
197
  #
196
198
  # GET /apps/[id]/channels/[channel_name]
197
199
  #
198
- # @param channel_name [String] Channel name
200
+ # @param channel_name [String] Channel name (max 200 characters)
199
201
  # @param params [Hash] Hash of parameters for the API - see REST API docs
200
202
  #
201
203
  # @return [Hash] See Pusher API docs
@@ -211,7 +213,7 @@ module Pusher
211
213
  #
212
214
  # POST /apps/[app_id]/events
213
215
  #
214
- # @param channels [String or Array] One of more channel names
216
+ # @param channels [String or Array] 1-10 channel names
215
217
  # @param event_name [String]
216
218
  # @param data [Object] Event data to be triggered in javascript.
217
219
  # Objects other than strings will be converted to JSON
@@ -279,6 +281,7 @@ module Pusher
279
281
 
280
282
  def trigger_params(channels, event_name, data, params)
281
283
  channels = Array(channels).map(&:to_s)
284
+ raise Pusher::Error, "Too many channels (#{channels.length}), max 10" if channels.length > 10
282
285
 
283
286
  encoded_data = case data
284
287
  when String
@@ -53,7 +53,7 @@ module Pusher
53
53
  :query => @params, :head => @head
54
54
  })
55
55
  else
56
- raise "Unsuported verb"
56
+ raise "Unsupported verb"
57
57
  end
58
58
  http.callback {
59
59
  begin
@@ -3,13 +3,14 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pusher"
6
- s.version = "0.12.0"
6
+ s.version = "0.14.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Pusher"]
9
9
  s.email = ["support@pusher.com"]
10
10
  s.homepage = "http://github.com/pusher/pusher-gem"
11
11
  s.summary = %q{Pusher API client}
12
12
  s.description = %q{Wrapper for pusher.com REST api}
13
+ s.license = "MIT"
13
14
 
14
15
  s.add_dependency "multi_json", "~> 1.0"
15
16
  s.add_dependency 'signature', "~> 0.1.6"
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Pusher::Channel do
@@ -51,6 +52,16 @@ describe Pusher::Channel do
51
52
  end
52
53
  end
53
54
 
55
+ describe "#initialization" do
56
+ it "should not be too long" do
57
+ lambda { @client['b'*201] }.should raise_error(Pusher::Error)
58
+ end
59
+
60
+ it "should not use bad characters" do
61
+ lambda { @client['*^!±`/""'] }.should raise_error(Pusher::Error)
62
+ end
63
+ end
64
+
54
65
  describe "#trigger_async" do
55
66
  it "should use @client.trigger_async internally" do
56
67
  @client.should_receive(:trigger_async)
@@ -22,6 +22,10 @@ describe Pusher do
22
22
  @client2.secret = 'bbbbbbbb'
23
23
  end
24
24
 
25
+ it "default should be configured automatically from environment variable" do
26
+ Pusher.default_client.url.host.should == "api.secret.pusherapp.com"
27
+ end
28
+
25
29
  it "should send scheme messages to different objects" do
26
30
  @client1.scheme.should_not == @client2.scheme
27
31
  end
@@ -129,6 +133,10 @@ describe Pusher do
129
133
  @client.scheme.should == 'https'
130
134
  @client.port.should == 443
131
135
  end
136
+
137
+ it "should fail on bad urls" do
138
+ expect { @client.url = "gopher/somekey:somesecret@://api.staging.pusherapp.co://m:8080\apps\87" }.to raise_error
139
+ end
132
140
  end
133
141
 
134
142
  describe 'configuring a http proxy' do
@@ -213,6 +221,14 @@ describe Pusher do
213
221
  should == {}
214
222
  end
215
223
 
224
+ it "should not allow too many channels" do
225
+ lambda {
226
+ @client.trigger((0..11).map{|i| 'mychannel#{i}'},
227
+ 'event', {'some' => 'data'}, {
228
+ :socket_id => "1234"
229
+ })}.should raise_error(Pusher::Error)
230
+ end
231
+
216
232
  it "should pass any parameters in the body of the request" do
217
233
  @client.trigger(['mychannel', 'c2'], 'event', {'some' => 'data'}, {
218
234
  :socket_id => "1234"
@@ -4,6 +4,8 @@ rescue LoadError
4
4
  puts 'although not required, it is recommended that you use bundler when running the tests'
5
5
  end
6
6
 
7
+ ENV['PUSHER_URL']= 'http://some:secret@api.secret.pusherapp.com:441/apps/54'
8
+
7
9
  require 'rspec'
8
10
  require 'rspec/autorun'
9
11
  require 'em-http' # As of webmock 1.4.0, em-http must be loaded first
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
5
- prerelease:
4
+ version: 0.14.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pusher
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-05 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: multi_json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: signature
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: httpclient
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,23 +69,20 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: webmock
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: em-http-request
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,33 +97,29 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rake
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rack
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  description: Wrapper for pusher.com REST api
@@ -168,34 +151,28 @@ files:
168
151
  - spec/spec_helper.rb
169
152
  - spec/web_hook_spec.rb
170
153
  homepage: http://github.com/pusher/pusher-gem
171
- licenses: []
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
172
157
  post_install_message:
173
158
  rdoc_options: []
174
159
  require_paths:
175
160
  - lib
176
161
  required_ruby_version: !ruby/object:Gem::Requirement
177
- none: false
178
162
  requirements:
179
- - - ! '>='
163
+ - - '>='
180
164
  - !ruby/object:Gem::Version
181
165
  version: '0'
182
- segments:
183
- - 0
184
- hash: -1060459840263191989
185
166
  required_rubygems_version: !ruby/object:Gem::Requirement
186
- none: false
187
167
  requirements:
188
- - - ! '>='
168
+ - - '>='
189
169
  - !ruby/object:Gem::Version
190
170
  version: '0'
191
- segments:
192
- - 0
193
- hash: -1060459840263191989
194
171
  requirements: []
195
172
  rubyforge_project:
196
- rubygems_version: 1.8.25
173
+ rubygems_version: 2.1.11
197
174
  signing_key:
198
- specification_version: 3
175
+ specification_version: 4
199
176
  summary: Pusher API client
200
177
  test_files:
201
178
  - spec/channel_spec.rb