Skip to content

Commit 51797ca

Browse files
committed
Add example responses for channel.info
1 parent a4b3b02 commit 51797ca

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/pusher/channel.rb

Lines changed: 4 additions & 1 deletion
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

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

0 commit comments

Comments
 (0)