pusher 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +8 -2
- data/lib/pusher/client.rb +15 -5
- data/lib/pusher.rb +9 -6
- data/pusher.gemspec +1 -1
- data/spec/client_spec.rb +27 -7
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6445dc1dff7034c9fa013bb13c06d797a3d508d3
|
4
|
+
data.tar.gz: cbadd3ea95efed035d3c8f87af33b76d7315b14c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f512577534b021e70ffe2d87838c7be5437139d6f0a38d90d4ef467d8e0d738192033fcdfd21aad3a9c88370908417bf03cb7450d887ccf9cfe05130d29c068
|
7
|
+
data.tar.gz: 3ca887136f17144e1fa3ca1fa8c35a12ce82ee5d0f16711da327c0429f4042f041d2df6b2e6f02f0f3a2a3eaba0ed0f0db0ace46eecff914d330b264ebcf20dd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -55,10 +55,16 @@ pusher_client = Pusher::Client.new(
|
|
55
55
|
|
56
56
|
This will set the `host` to `api-<cluster>.pusher.com`. If you pass both `host` and `cluster` options, the `host` will take precendence and `cluster` will be ignored.
|
57
57
|
|
58
|
-
|
58
|
+
Finally, if you have the configuration set in an `PUSHER_URL` environment
|
59
|
+
variable, you can use:
|
60
|
+
|
61
|
+
``` ruby
|
62
|
+
pusher_client = Pusher::Client.from_env
|
63
|
+
```
|
64
|
+
|
65
|
+
### Global
|
59
66
|
|
60
67
|
Configuring Pusher can also be done globally on the Pusher class.
|
61
|
-
*NOTE! This is a deprecated feature and will be removed in future versions of this library!*
|
62
68
|
|
63
69
|
``` ruby
|
64
70
|
Pusher.app_id = 'your-pusher-app-id'
|
data/lib/pusher/client.rb
CHANGED
@@ -9,6 +9,14 @@ module Pusher
|
|
9
9
|
|
10
10
|
## CONFIGURATION ##
|
11
11
|
|
12
|
+
# Loads the configuration from an url in the environment
|
13
|
+
def self.from_env(key = 'PUSHER_URL')
|
14
|
+
url = ENV[key] || raise(ConfigurationError, key)
|
15
|
+
client = new
|
16
|
+
client.url = url
|
17
|
+
client
|
18
|
+
end
|
19
|
+
|
12
20
|
def initialize(options = {})
|
13
21
|
default_options = {
|
14
22
|
:scheme => 'http',
|
@@ -40,11 +48,14 @@ module Pusher
|
|
40
48
|
|
41
49
|
# @private Returns the authentication token for the client
|
42
50
|
def authentication_token
|
51
|
+
raise ConfigurationError, :key unless @key
|
52
|
+
raise ConfigurationError, :secret unless @secret
|
43
53
|
Pusher::Signature::Token.new(@key, @secret)
|
44
54
|
end
|
45
55
|
|
46
56
|
# @private Builds a url for this app, optionally appending a path
|
47
57
|
def url(path = nil)
|
58
|
+
raise ConfigurationError, :app_id unless @app_id
|
48
59
|
URI::Generic.build({
|
49
60
|
:scheme => @scheme,
|
50
61
|
:host => @host,
|
@@ -133,7 +144,7 @@ module Pusher
|
|
133
144
|
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
|
134
145
|
#
|
135
146
|
def get(path, params = {})
|
136
|
-
|
147
|
+
resource(path).get(params)
|
137
148
|
end
|
138
149
|
|
139
150
|
# GET arbitrary REST API resource using an asynchronous http client.
|
@@ -149,20 +160,20 @@ module Pusher
|
|
149
160
|
# @return Either an EM::DefaultDeferrable or a HTTPClient::Connection
|
150
161
|
#
|
151
162
|
def get_async(path, params = {})
|
152
|
-
|
163
|
+
resource(path).get_async(params)
|
153
164
|
end
|
154
165
|
|
155
166
|
# POST arbitrary REST API resource using a synchronous http client.
|
156
167
|
# Works identially to get method, but posts params as JSON in post body.
|
157
168
|
def post(path, params = {})
|
158
|
-
|
169
|
+
resource(path).post(params)
|
159
170
|
end
|
160
171
|
|
161
172
|
# POST arbitrary REST API resource using an asynchronous http client.
|
162
173
|
# Works identially to get_async method, but posts params as JSON in post
|
163
174
|
# body.
|
164
175
|
def post_async(path, params = {})
|
165
|
-
|
176
|
+
resource(path).post_async(params)
|
166
177
|
end
|
167
178
|
|
168
179
|
## HELPER METHODS ##
|
@@ -186,7 +197,6 @@ module Pusher
|
|
186
197
|
# should not contain anything other than letters, numbers, or the
|
187
198
|
# characters "_\-=@,.;"
|
188
199
|
def channel(channel_name)
|
189
|
-
raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
|
190
200
|
Channel.new(url, channel_name, self)
|
191
201
|
end
|
192
202
|
|
data/lib/pusher.rb
CHANGED
@@ -17,7 +17,11 @@ module Pusher
|
|
17
17
|
# end
|
18
18
|
class Error < RuntimeError; end
|
19
19
|
class AuthenticationError < Error; end
|
20
|
-
class ConfigurationError < Error
|
20
|
+
class ConfigurationError < Error
|
21
|
+
def initialize(key)
|
22
|
+
super "missing key `#{key}' in the client configuration"
|
23
|
+
end
|
24
|
+
end
|
21
25
|
class HTTPError < Error; attr_accessor :original_error; end
|
22
26
|
|
23
27
|
class << self
|
@@ -45,13 +49,12 @@ module Pusher
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def default_client
|
48
|
-
@default_client ||=
|
52
|
+
@default_client ||= begin
|
53
|
+
cli = Pusher::Client
|
54
|
+
ENV['PUSHER_URL'] ? cli.from_env : cli.new
|
55
|
+
end
|
49
56
|
end
|
50
57
|
end
|
51
|
-
|
52
|
-
if ENV['PUSHER_URL']
|
53
|
-
self.url = ENV['PUSHER_URL']
|
54
|
-
end
|
55
58
|
end
|
56
59
|
|
57
60
|
require 'pusher/channel'
|
data/pusher.gemspec
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -58,6 +58,14 @@ describe Pusher do
|
|
58
58
|
it "should fail on bad urls" do
|
59
59
|
expect { @client.url = "gopher/somekey:somesecret@://api.staging.pusherapp.co://m:8080\apps\87" }.to raise_error(URI::InvalidURIError)
|
60
60
|
end
|
61
|
+
|
62
|
+
it "should raise exception if app_id is not configured" do
|
63
|
+
@client.app_id = nil
|
64
|
+
expect {
|
65
|
+
@client.url
|
66
|
+
}.to raise_error(Pusher::ConfigurationError)
|
67
|
+
end
|
68
|
+
|
61
69
|
end
|
62
70
|
|
63
71
|
describe 'configuring the cluster' do
|
@@ -100,6 +108,20 @@ describe Pusher do
|
|
100
108
|
end
|
101
109
|
end
|
102
110
|
|
111
|
+
describe 'configuring from env' do
|
112
|
+
it "works" do
|
113
|
+
url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
|
114
|
+
ENV['PUSHER_URL'] = url
|
115
|
+
|
116
|
+
client = Pusher::Client.from_env
|
117
|
+
expect(client.key).to eq("somekey")
|
118
|
+
expect(client.secret).to eq("somesecret")
|
119
|
+
expect(client.app_id).to eq("87")
|
120
|
+
expect(client.url.to_s).to eq("http://api.staging.pusherapp.com:8080/apps/87")
|
121
|
+
ENV['PUSHER_URL'] = nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
103
125
|
describe 'when configured' do
|
104
126
|
before :each do
|
105
127
|
@client.app_id = '20'
|
@@ -116,13 +138,11 @@ describe Pusher do
|
|
116
138
|
expect(@channel).to be_kind_of(Pusher::Channel)
|
117
139
|
end
|
118
140
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}.to raise_error(Pusher::ConfigurationError)
|
125
|
-
end
|
141
|
+
it "should raise exception if app_id is not configured" do
|
142
|
+
@client.app_id = nil
|
143
|
+
expect {
|
144
|
+
@client['test_channel']
|
145
|
+
}.to raise_error(Pusher::ConfigurationError)
|
126
146
|
end
|
127
147
|
end
|
128
148
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pusher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -184,8 +184,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.6.2
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Pusher API client
|
191
|
-
test_files:
|
191
|
+
test_files:
|
192
|
+
- spec/channel_spec.rb
|
193
|
+
- spec/client_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
- spec/web_hook_spec.rb
|