Skip to content

Commit

Permalink
Add request to list presence rooms only
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jan 12, 2011
1 parent 96178ac commit 0673505
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/campfire/manager.rb
Expand Up @@ -5,7 +5,17 @@ def initialize(options)
end

def rooms
@connection.get("/rooms.json")["rooms"].map do |room|
find_rooms 'rooms'
end

def presence
find_rooms 'presence'
end

private

def find_rooms(path)
@connection.get("/#{path}.json")["rooms"].map do |room|
Room.new(self, room)
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/campfire/manager_test.rb
Expand Up @@ -4,6 +4,7 @@ class TestManager < MiniTest::Unit::TestCase
def test_rooms
manager = Campfire::Manager.new(:subdomain => "foo", :token => "123")
rooms = manager.rooms
assert_equal 2, rooms.size

room = rooms[0]
assert_equal "Room 1", room.name
Expand All @@ -15,4 +16,15 @@ def test_rooms
assert_equal 214395, room.id
assert_equal "RMU", room.topic
end

def test_rooms
manager = Campfire::Manager.new(:subdomain => "foo", :token => "123")
rooms = manager.presence
assert_equal 1, rooms.size

room = rooms[0]
assert_equal "Room 2", room.name
assert_equal 214395, room.id
assert_equal "RMU", room.topic
end
end
13 changes: 13 additions & 0 deletions test/fixtures/presence.json
@@ -0,0 +1,13 @@
{
"rooms": [
{
"name": "Room 2",
"created_at": "2010/01/09 23:25:15 +0000",
"updated_at": "2010/01/09 23:25:15 +0000",
"topic": "RMU",
"id": 214395,
"membership_limit": 4,
"locked": false
}
]
}
2 changes: 2 additions & 0 deletions test/test_helper.rb
Expand Up @@ -14,3 +14,5 @@ def read_fixture(file_name)
WebMock.disable_net_connect!
WebMock.stub_request(:get, %r[https://123:X@.*\.campfirenow\.com/rooms\.json]).
to_return(:body => read_fixture("rooms.json"))
WebMock.stub_request(:get, %r[https://123:X@.*\.campfirenow\.com/presence\.json]).
to_return(:body => read_fixture("presence.json"))

0 comments on commit 0673505

Please sign in to comment.