pusher 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7cf7936626783961750faf09d38ea22db710f5f
4
- data.tar.gz: bf85e0ba476d7abdeef2eb4ab96f7fc4ca7ce8d0
3
+ metadata.gz: c321a0933bab4b4ccfbefa2c9e83eadab92d622c
4
+ data.tar.gz: ecb892017e868a125e8a11bdb130c8f9069d9dcb
5
5
  SHA512:
6
- metadata.gz: d4fcd557bde9a7f50583bd50bd72675a836ab83eed677b5bf89526e9e0d5bda9fbbb10f12127b8ecf5d509d9ead34ac556dd55d838088445b27782e0cdaa1dc5
7
- data.tar.gz: b3a3ef764d730434b45d5046b4974a1e7ca2a1e41e00fea8a2570f30b4331314e02b80756652b76ce27ff672e6deeed25ceb9d169866a4668964370edc6995b6
6
+ metadata.gz: 9db9cd31686cab8565d2fc2a0b4c57270728b69dc592c2dbb5baaa7c7df509b1c40836e3f9d550703e2e330b5c5198defc7935e5033ab7039bba91015ea3c5b7
7
+ data.tar.gz: cea7de20ba9b57db2ff5e58fbc8bed35dfd8cf02ca88fb31b3929ba34b7a6036fef6b94fba0e244e0cc3b0549c288b5d3bf8d3d348e9acee0587542c31ab2e87
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.17.0 / 2016-02-22
2
+ ==================
3
+
4
+ * Introduce the `cluster` option.
1
5
 
2
6
  0.16.0 / 2016-01-21
3
7
  ==================
data/README.md CHANGED
@@ -19,9 +19,46 @@ gem install pusher
19
19
 
20
20
  After registering at <http://pusher.com> configure your app with the security credentials.
21
21
 
22
- ### Global
22
+ ### Instantiating a Pusher client
23
+
24
+ Creating a new Pusher `client` can be done as follows.
25
+
26
+ ``` ruby
27
+ pusher_client = Pusher::Client.new(
28
+ app_id: 'your-pusher-app-id',
29
+ key: 'your-pusher-key',
30
+ secret: 'your-pusher-secret'
31
+ )
32
+ ```
33
+
34
+ If you want to set a custom `host` value for your client then you can do so when instantiating a Pusher client like so:
35
+
36
+ ``` ruby
37
+ pusher_client = Pusher::Client.new(
38
+ app_id: 'your-pusher-app-id',
39
+ key: 'your-pusher-key',
40
+ secret: 'your-pusher-secret',
41
+ host: 'your-pusher-host'
42
+ )
43
+ ```
44
+
45
+ If you created your app in a different cluster to the default cluster, you must pass the `cluster` option as follows:
46
+
47
+ ``` ruby
48
+ pusher_client = Pusher::Client.new(
49
+ app_id: 'your-pusher-app-id',
50
+ key: 'your-pusher-key',
51
+ secret: 'your-pusher-secret',
52
+ cluster: 'your-app-cluster'
53
+ )
54
+ ```
55
+
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
+
58
+ ### Global (Deprecated)
23
59
 
24
- The most standard way of configuring Pusher is to do it globally on the Pusher class.
60
+ 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!*
25
62
 
26
63
  ``` ruby
27
64
  Pusher.app_id = 'your-pusher-app-id'
@@ -49,33 +86,6 @@ As of version 0.12, SSL certificates are verified when using the synchronous htt
49
86
  Pusher.default_client.sync_http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
87
  ```
51
88
 
52
- ### Instantiating a Pusher client
53
-
54
- Sometimes you may have multiple sets of API keys, or want different configuration in different parts of your application. In these scenarios, a pusher `client` may be configured:
55
-
56
- ``` ruby
57
- pusher_client = Pusher::Client.new({
58
- app_id: 'your-pusher-app-id',
59
- key: 'your-pusher-key',
60
- secret: 'your-pusher-secret'
61
- })
62
- ```
63
-
64
- This `client` will have all the functionality listed on the main Pusher class (which proxies to a client internally).
65
-
66
- If you want to set the `host` value for your client then you can do so when instantiating a Pusher client like so:
67
-
68
- ``` ruby
69
- pusher_client = Pusher::Client.new({
70
- app_id: 'your-pusher-app-id',
71
- key: 'your-pusher-key',
72
- secret: 'your-pusher-secret',
73
- host: 'your-pusher-host'
74
- })
75
- ```
76
-
77
- This is useful if, for example, you've created an app on the EU cluster and wish to set the host to be `api-eu.pusher.com`.
78
-
79
89
  ## Interacting with the Pusher service
80
90
 
81
91
  The Pusher gem contains a number of helpers for interacting with the service. As a general rule, the library adheres to a set of conventions that we have aimed to make universal.
@@ -86,7 +96,7 @@ Handle errors by rescuing `Pusher::Error` (all errors are descendants of this er
86
96
 
87
97
  ``` ruby
88
98
  begin
89
- Pusher.trigger('a_channel', 'an_event', {:some => 'data'})
99
+ Pusher.trigger('a_channel', 'an_event', :some => 'data')
90
100
  rescue Pusher::Error => e
91
101
  # (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
92
102
  end
@@ -105,8 +115,8 @@ Pusher.logger = Rails.logger
105
115
  An event can be published to one or more channels (limited to 10) in one API call:
106
116
 
107
117
  ``` ruby
108
- Pusher.trigger('channel', 'event', {foo: 'bar'})
109
- Pusher.trigger(['channel_1', 'channel_2'], 'event_name', {foo: 'bar'})
118
+ Pusher.trigger('channel', 'event', foo: 'bar')
119
+ Pusher.trigger(['channel_1', 'channel_2'], 'event_name', foo: 'bar')
110
120
  ```
111
121
 
112
122
  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).
@@ -120,7 +130,7 @@ Pusher.trigger('channel', 'event', {foo: 'bar'}, {socket_id: '123.456'})
120
130
  Most examples and documentation will refer to the following syntax for triggering an event:
121
131
 
122
132
  ``` ruby
123
- Pusher['a_channel'].trigger('an_event', {:some => 'data'})
133
+ Pusher['a_channel'].trigger('an_event', :some => 'data')
124
134
  ```
125
135
 
126
136
  This will continue to work, but has been replaced by `Pusher.trigger` which supports one or multiple channels.
@@ -193,10 +203,10 @@ Pusher.authenticate('private-my_channel', params[:socket_id])
193
203
  These work in a very similar way, but require a unique identifier for the user being authenticated, and optionally some attributes that are provided to clients via presence events:
194
204
 
195
205
  ``` ruby
196
- Pusher.authenticate('presence-my_channel', params[:socket_id], {
206
+ Pusher.authenticate('presence-my_channel', params[:socket_id],
197
207
  user_id: 'user_id',
198
208
  user_info: {} # optional
199
- })
209
+ )
200
210
  ```
201
211
 
202
212
  ## Receiving WebHooks
data/lib/pusher.rb CHANGED
@@ -27,7 +27,7 @@ module Pusher
27
27
  def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
28
28
 
29
29
  def_delegators :default_client, :authentication_token, :url
30
- def_delegators :default_client, :encrypted=, :url=
30
+ def_delegators :default_client, :encrypted=, :url=, :cluster=
31
31
  def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
32
32
 
33
33
  def_delegators :default_client, :get, :get_async, :post, :post_async
data/lib/pusher/client.rb CHANGED
@@ -10,14 +10,24 @@ module Pusher
10
10
  ## CONFIGURATION ##
11
11
 
12
12
  def initialize(options = {})
13
- options = {
13
+ default_options = {
14
14
  :scheme => 'http',
15
- :host => 'api.pusherapp.com',
16
15
  :port => 80,
17
- }.merge(options)
18
- @scheme, @host, @port, @app_id, @key, @secret = options.values_at(
16
+ }
17
+ merged_options = default_options.merge(options)
18
+
19
+ if options.has_key?(:host)
20
+ merged_options[:host] = options[:host]
21
+ elsif options.has_key?(:cluster)
22
+ merged_options[:host] = "api-#{options[:cluster]}.pusher.com"
23
+ else
24
+ merged_options[:host] = "api.pusherapp.com"
25
+ end
26
+
27
+ @scheme, @host, @port, @app_id, @key, @secret = merged_options.values_at(
19
28
  :scheme, :host, :port, :app_id, :key, :secret
20
29
  )
30
+
21
31
  @http_proxy = nil
22
32
  self.http_proxy = options[:http_proxy] if options[:http_proxy]
23
33
 
@@ -88,6 +98,10 @@ module Pusher
88
98
  @scheme == 'https'
89
99
  end
90
100
 
101
+ def cluster=(cluster)
102
+ @host = "api-#{cluster}.pusher.com"
103
+ end
104
+
91
105
  # Convenience method to set all timeouts to the same value (in seconds).
92
106
  # For more control, use the individual writers.
93
107
  def timeout=(value)
data/pusher.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pusher"
6
- s.version = "0.16.0"
6
+ s.version = "0.17.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Pusher"]
9
9
  s.email = ["support@pusher.com"]
data/spec/client_spec.rb CHANGED
@@ -60,6 +60,38 @@ describe Pusher do
60
60
  end
61
61
  end
62
62
 
63
+ describe 'configuring the cluster' do
64
+ it 'should set a new default host' do
65
+ @client.cluster = 'eu'
66
+ expect(@client.host).to eq('api-eu.pusher.com')
67
+ end
68
+
69
+ it 'should be overridden by host if it comes after' do
70
+ @client.cluster = 'eu'
71
+ @client.host = 'api.staging.pusher.com'
72
+ expect(@client.host).to eq('api.staging.pusher.com')
73
+ end
74
+
75
+ it 'should be overridden by url if it comes after' do
76
+ @client.cluster = 'eu'
77
+ @client.url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
78
+
79
+ expect(@client.host).to eq('api.staging.pusherapp.com')
80
+ end
81
+
82
+ it 'should get override the url configuration if it comes after' do
83
+ @client.url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
84
+ @client.cluster = 'eu'
85
+ expect(@client.host).to eq('api-eu.pusher.com')
86
+ end
87
+
88
+ it 'should overrie by the host configuration if it comes after' do
89
+ @client.host = 'api.staging.pusher.com'
90
+ @client.cluster = 'eu'
91
+ expect(@client.host).to eq('api-eu.pusher.com')
92
+ end
93
+ end
94
+
63
95
  describe 'configuring a http proxy' do
64
96
  it "should be possible to configure everything by setting the http_proxy" do
65
97
  @client.http_proxy = 'http://someuser:somepassword@proxy.host.com:8080'
@@ -431,4 +463,26 @@ describe Pusher do
431
463
  end
432
464
  end
433
465
  end
466
+
467
+ describe 'configuring cluster' do
468
+ it 'should allow clients to specify the cluster only with the default host' do
469
+ client = Pusher::Client.new({
470
+ :scheme => 'http',
471
+ :cluster => 'eu',
472
+ :port => 80
473
+ })
474
+ expect(client.host).to eq('api-eu.pusher.com')
475
+ end
476
+
477
+ it 'should always have host override any supplied cluster value' do
478
+ client = Pusher::Client.new({
479
+ :scheme => 'http',
480
+ :host => 'api.staging.pusherapp.com',
481
+ :cluster => 'eu',
482
+ :port => 80
483
+ })
484
+ expect(client.host).to eq('api.staging.pusherapp.com')
485
+ end
486
+ end
434
487
  end
488
+
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.16.0
4
+ version: 0.17.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-01-21 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -184,12 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 2.5.1
187
+ rubygems_version: 2.4.5.1
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: Pusher API client
191
- test_files:
192
- - spec/channel_spec.rb
193
- - spec/client_spec.rb
194
- - spec/spec_helper.rb
195
- - spec/web_hook_spec.rb
191
+ test_files: []