Class: Hobostove::Campfire
- Inherits:
-
Object
- Object
- Hobostove::Campfire
- Defined in:
- lib/hobostove/campfire.rb
Instance Attribute Summary collapse
-
#room_id ⇒ Object
readonly
Returns the value of attribute room_id.
Instance Method Summary collapse
- #current_users ⇒ Object
-
#initialize ⇒ Campfire
constructor
A new instance of Campfire.
- #join ⇒ Object
- #leave ⇒ Object
- #recent_messages ⇒ Object
- #send_message(message) ⇒ Object
Constructor Details
#initialize ⇒ Campfire
Returns a new instance of Campfire.
5 6 7 8 9 |
# File 'lib/hobostove/campfire.rb', line 5 def initialize load_current_room @users = {} end |
Instance Attribute Details
#room_id ⇒ Object (readonly)
Returns the value of attribute room_id.
3 4 5 |
# File 'lib/hobostove/campfire.rb', line 3 def room_id @room_id end |
Instance Method Details
#current_users ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/hobostove/campfire.rb', line 39 def current_users room = connection.get("/room/#{room_id}.json").body room = JSON.parse(room)["room"] room["users"].map do |user| @users[user["id"]] = Hobostove::Models::User.new(user["id"], user["name"]) end end |
#join ⇒ Object
47 48 49 |
# File 'lib/hobostove/campfire.rb', line 47 def join connection.post("/room/#{room_id}/join.json") end |
#leave ⇒ Object
51 52 53 |
# File 'lib/hobostove/campfire.rb', line 51 def leave connection.post("/room/#{room_id}/leave.json") end |
#recent_messages ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hobostove/campfire.rb', line 11 def = connection.get("/room/#{room_id}/recent.json?limit=10").body = JSON.parse()["messages"] .map do || = Hobostove::Models::Message.new( ["id"], Time.parse(["created_at"]), ["type"], user(["user_id"]), ["body"] ) = handle_upload() if .type == "UploadMessage" end end |
#send_message(message) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hobostove/campfire.rb', line 27 def () connection.post("/room/#{room_id}/speak.json") do |req| req.headers["Content-Type"] = "application/json" req.body = { :message => { :type => "TextMessage", :body => , } }.to_json end end |