Class: Dickburt::Room
Instance Attribute Summary collapse
-
#campfire ⇒ Object
Returns the value of attribute campfire.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#find_user(user_id) ⇒ Object
Looks up the user by user_id for the current users in the room.
- #handle_failure ⇒ Object
-
#initialize(room, campfire) ⇒ Room
constructor
A new instance of Room.
- #join ⇒ Object
- #leave ⇒ Object
- #speak(response) ⇒ Object
- #stream ⇒ Object
-
#users ⇒ Object
Returns an Array of current users for the room.
Methods included from Logger
Constructor Details
#initialize(room, campfire) ⇒ Room
Returns a new instance of Room.
6 7 8 9 |
# File 'lib/dickburt/room.rb', line 6 def initialize(room, campfire) super(room) @campfire = campfire end |
Instance Attribute Details
#campfire ⇒ Object
Returns the value of attribute campfire.
3 4 5 |
# File 'lib/dickburt/room.rb', line 3 def campfire @campfire end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/dickburt/room.rb', line 4 def response @response end |
Instance Method Details
#find_user(user_id) ⇒ Object
Looks up the user by user_id for the current users in the room
user_id - String 37signals user id
Returns a Dickburt::User if it finds that user in the room Raises an error if they can’t be found.
53 54 55 56 57 |
# File 'lib/dickburt/room.rb', line 53 def find_user(user_id) user = users.detect{|u| u.id == user_id} raise Dickburt::Error, "user #{user_id} not found" unless user User.new(user.to_json, campfire) end |
#handle_failure ⇒ Object
59 60 61 |
# File 'lib/dickburt/room.rb', line 59 def handle_failure end |
#join ⇒ Object
24 25 26 |
# File 'lib/dickburt/room.rb', line 24 def join response = @campfire.http.post("/room/#{id}/join.json", {}) end |
#leave ⇒ Object
28 29 30 |
# File 'lib/dickburt/room.rb', line 28 def leave response = @campfire.http.post("/room/#{id}/leave.json", {}) end |
#speak(response) ⇒ Object
20 21 22 |
# File 'lib/dickburt/room.rb', line 20 def speak(response) response = @campfire.http.post("/room/#{id}/speak.json", response.to_json) end |
#stream ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/dickburt/room.rb', line 32 def stream Twitter::JSONStream.connect( :path => "/room/#{id}/live.json", :host => 'streaming.campfirenow.com', :auth => "#{campfire.token}:x" ) end |
#users ⇒ Object
Returns an Array of current users for the room.
41 42 43 44 45 |
# File 'lib/dickburt/room.rb', line 41 def users response = @campfire.http.get("/room/#{id}.json") room = Map.new(JSON.parse(response.body)["room"]) room.users end |