Skip to content

Commit 5346547

Browse files
committed
Add #channel_users
1 parent 007dc98 commit 5346547

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/pusher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class << self
3131
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
3232

3333
def_delegators :default_client, :get, :get_async, :post, :post_async
34-
def_delegators :default_client, :channels, :channel_info, :trigger, :trigger_async
34+
def_delegators :default_client, :channels, :channel_info, :channel_users, :trigger, :trigger_async
3535
def_delegators :default_client, :authenticate, :webhook, :channel, :[]
3636

3737
attr_writer :logger

lib/pusher/client.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ def channel_info(channel_name, params = {})
209209
get("/channels/#{channel_name}", params)
210210
end
211211

212+
# Request info for users of a channel
213+
#
214+
# GET /apps/[id]/channels/[channel_name]/users
215+
#
216+
# @param channel_name [String] Channel name (max 200 characters)
217+
# @param params [Hash] Hash of parameters for the API - see REST API docs
218+
#
219+
# @return [Hash] See Pusher API docs
220+
#
221+
# @raise [Pusher::Error] Unsuccessful response - see the error message
222+
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
223+
#
224+
def channel_users(channel_name, params = {})
225+
get("/channels/#{channel_name}/users", params)
226+
end
227+
212228
# Trigger an event on one or more channels
213229
#
214230
# POST /apps/[app_id]/events

spec/client_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@
128128
end
129129
end
130130

131+
describe '#channel_users' do
132+
it "should call correct URL and symbolise response" do
133+
api_path = %r{/apps/20/channels/mychannel/users}
134+
stub_request(:get, api_path).to_return({
135+
:status => 200,
136+
:body => MultiJson.encode({
137+
'users': [{ 'id' => 1 }]
138+
})
139+
})
140+
expect(@client.channel_users('mychannel')).to eq({
141+
:users => [{ 'id' => 1}]
142+
})
143+
end
144+
end
145+
131146
describe '#authenticate' do
132147
before :each do
133148
@custom_data = {:uid => 123, :info => {:name => 'Foo'}}

0 commit comments

Comments
 (0)