Skip to content

Commit 695d864

Browse files
authored
Merge branch 'master' into pusher-channels
2 parents be5cf73 + 1abd389 commit 695d864

File tree

7 files changed

+41
-16
lines changed

7 files changed

+41
-16
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rvm:
66
- 2.1
77
- 2.2
88
- 2.3.0
9+
- 2.4.1
910
- jruby
1011
- rbx-2
1112

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ If you need to make requests via a HTTP proxy then it can be configured
7878
Pusher.http_proxy = 'http://(user):(password)@(host):(port)'
7979
```
8080

81-
By default API requests are made over HTTP. HTTPS can be used by setting
81+
By default API requests are made over HTTP. HTTPS can be used by setting `encrypted` to `true`.
82+
Issuing this command is going to reset `port` value if it was previously specified.
8283

8384
``` ruby
8485
Pusher.encrypted = true
@@ -136,7 +137,7 @@ events per call on multi-tenant clusters):
136137

137138
``` ruby
138139
channels_client.trigger_batch([
139-
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }}
140+
{channel: 'channel_1', name: 'event_name', data: { foo: 'bar' }},
140141
{channel: 'channel_1', name: 'event_name', data: { hello: 'world' }}
141142
])
142143
```
@@ -153,7 +154,7 @@ This will continue to work, but has been replaced by `channels_client.trigger` w
153154

154155
### Getting information about the channels in your Pusher Channels app
155156

156-
This gem provides methods for accessing information from the [Pusher HTTP API](https://pusher.com/docs/rest_api). The documentation also shows an example of the responses from each of the API endpionts.
157+
This gem provides methods for accessing information from the [Pusher HTTP API](https://pusher.com/docs/rest_api). The documentation also shows an example of the responses from each of the API endpoints.
157158

158159
The following methods are provided by the gem.
159160

@@ -301,4 +302,3 @@ data = {
301302
```
302303

303304
**NOTE:** This is currently a BETA feature and there might be minor bugs and issues. Changes to the API will be kept to a minimum, but changes are expected. If you come across any bugs or issues, please do get in touch via [support](support@pusher.com) or create an issue here.
304-

lib/pusher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class << self
3232
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
3333
def_delegators :default_client, :notification_host=, :notification_scheme=
3434

35-
def_delegators :default_client, :authentication_token, :url
35+
def_delegators :default_client, :authentication_token, :url, :cluster
3636
def_delegators :default_client, :encrypted=, :url=, :cluster=
3737
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
3838

lib/pusher/channel.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def trigger(event_name, data, socket_id = nil)
8686

8787
# Request info for a channel
8888
#
89+
# @example Response
90+
# [{:occupied=>true, :subscription_count => 12}]
91+
#
8992
# @param info [Array] Array of attributes required (as lowercase strings)
9093
# @return [Hash] Hash of requested attributes for this channel
9194
# @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
@@ -99,7 +102,7 @@ def info(attributes = [])
99102
# Only works on presence channels (see: http://pusher.com/docs/client_api_guide/client_presence_channels and https://pusher.com/docs/rest_api)
100103
#
101104
# @example Response
102-
# [{"id"=>"4"}]
105+
# [{:id=>"4"}]
103106
#
104107
# @param params [Hash] Hash of parameters for the API - see REST API docs
105108
# @return [Hash] Array of user hashes for this channel
@@ -146,7 +149,7 @@ def authentication_string(socket_id, custom_string = nil)
146149
# render :json => Pusher['private-my_channel'].authenticate(params[:socket_id])
147150
#
148151
# @example Presence channels
149-
# render :json => Pusher['private-my_channel'].authenticate(params[:socket_id], {
152+
# render :json => Pusher['presence-my_channel'].authenticate(params[:socket_id], {
150153
# :user_id => current_user.id, # => required
151154
# :user_info => { # => optional - for example
152155
# :name => current_user.name,

lib/pusher/client.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class Client
1212
# Loads the configuration from an url in the environment
1313
def self.from_env(key = 'PUSHER_URL')
1414
url = ENV[key] || raise(ConfigurationError, key)
15+
from_url(url)
16+
end
17+
18+
# Loads the configuration from a url
19+
def self.from_url(url)
1520
client = new
1621
client.url = url
1722
client
@@ -127,7 +132,7 @@ def timeout=(value)
127132
@connect_timeout, @send_timeout, @receive_timeout = value, value, value
128133
end
129134

130-
## INTERACE WITH THE API ##
135+
## INTERACT WITH THE API ##
131136

132137
def resource(path)
133138
Resource.new(self, path)

spec/channel_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ def stub_post_to_raise(e)
7171

7272
describe '#info' do
7373
it "should call the Client#channel_info" do
74-
expect(@client).to receive(:get).with("/channels/mychannel", anything)
74+
expect(@client).to receive(:get)
75+
.with("/channels/mychannel", anything)
76+
.and_return({:occupied => true, :subscription_count => 12})
7577
@channel = @client['mychannel']
7678
@channel.info
7779
end
7880

7981
it "should assemble the requested attributes into the info option" do
80-
expect(@client).to receive(:get).with(anything, {
81-
:info => "user_count,connection_count"
82-
})
82+
expect(@client).to receive(:get)
83+
.with(anything, {:info => "user_count,connection_count"})
84+
.and_return({:occupied => true, :subscription_count => 12, :user_count => 12})
8385
@channel = @client['presence-foo']
8486
@channel.info(%w{user_count connection_count})
8587
end

spec/client_spec.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@
8787
expect(@client.host).to eq('api.staging.pusherapp.com')
8888
end
8989

90-
it 'should get override the url configuration if it comes after' do
90+
it 'should override the url configuration if it comes after' do
9191
@client.url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
9292
@client.cluster = 'eu'
9393
expect(@client.host).to eq('api-eu.pusher.com')
9494
end
9595

96-
it 'should overrie by the host configuration if it comes after' do
96+
it 'should override the host configuration if it comes after' do
9797
@client.host = 'api.staging.pusher.com'
9898
@client.cluster = 'eu'
9999
expect(@client.host).to eq('api-eu.pusher.com')
@@ -109,6 +109,10 @@
109109
end
110110

111111
describe 'configuring from env' do
112+
after do
113+
ENV['PUSHER_URL'] = nil
114+
end
115+
112116
it "works" do
113117
url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
114118
ENV['PUSHER_URL'] = url
@@ -118,7 +122,18 @@
118122
expect(client.secret).to eq("somesecret")
119123
expect(client.app_id).to eq("87")
120124
expect(client.url.to_s).to eq("http://api.staging.pusherapp.com:8080/apps/87")
121-
ENV['PUSHER_URL'] = nil
125+
end
126+
end
127+
128+
describe 'configuring from url' do
129+
it "works" do
130+
url = "http://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
131+
132+
client = Pusher::Client.from_url(url)
133+
expect(client.key).to eq("somekey")
134+
expect(client.secret).to eq("somesecret")
135+
expect(client.app_id).to eq("87")
136+
expect(client.url.to_s).to eq("http://api.staging.pusherapp.com:8080/apps/87")
122137
end
123138
end
124139

@@ -612,4 +627,3 @@
612627
end
613628
end
614629
end
615-

0 commit comments

Comments
 (0)