Class: Dickburt::Room

Inherits:
Map
  • Object
show all
Includes:
Logger
Defined in:
lib/dickburt/room.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#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

#campfireObject

Returns the value of attribute campfire.



3
4
5
# File 'lib/dickburt/room.rb', line 3

def campfire
  @campfire
end

#responseObject

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.

Raises:



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_failureObject



59
60
61
# File 'lib/dickburt/room.rb', line 59

def handle_failure

end

#joinObject



24
25
26
# File 'lib/dickburt/room.rb', line 24

def join
  response = @campfire.http.post("/room/#{id}/join.json", {})
end

#leaveObject



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

#streamObject



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

#usersObject

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