Class: Tinder::Room
- Inherits:
-
Object
- Object
- Tinder::Room
- Defined in:
- lib/tinder/room.rb
Overview
A campfire room
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#available_transcripts ⇒ Object
Get the dates for the available transcripts for this room.
- #destroy ⇒ Object
-
#files(count = 5) ⇒ Object
Get the list of latest files for this room.
- #guest_access_enabled? ⇒ Boolean
-
#guest_invite_code ⇒ Object
The invite code use for guest.
-
#guest_url ⇒ Object
Get the url for guest access.
-
#initialize(campfire, attributes = {}) ⇒ Room
constructor
A new instance of Room.
-
#join(force = false) ⇒ Object
Join the room.
-
#leave ⇒ Object
Leave a room.
-
#listen(interval = 5) ⇒ Object
Get and array of the messages that have been posted to the room.
-
#lock ⇒ Object
Lock the room to prevent new users from entering and to disable logging.
- #paste(message) ⇒ Object
- #ping(force = false) ⇒ Object
-
#speak(message, options = {}) ⇒ Object
Post a new message to the chat room.
-
#toggle_guest_access ⇒ Object
Toggle guest access on or off.
-
#topic ⇒ Object
Get the current topic.
-
#topic=(topic) ⇒ Object
Change the topic.
-
#transcript(transcript_date) ⇒ Object
Get the transcript for the given date (Returns a hash in the same format as #listen).
-
#unlock ⇒ Object
Unlock the room.
- #upload(filename) ⇒ Object
-
#users ⇒ Object
Get the list of users currently chatting for this room.
Constructor Details
#initialize(campfire, attributes = {}) ⇒ Room
Returns a new instance of Room.
6 7 8 9 10 11 |
# File 'lib/tinder/room.rb', line 6 def initialize(campfire, attributes = {}) @campfire = campfire @id = attributes['id'] @name = attributes['name'] @loaded = false end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/tinder/room.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/tinder/room.rb', line 4 def name @name end |
Instance Method Details
#available_transcripts ⇒ Object
Get the dates for the available transcripts for this room
129 130 131 |
# File 'lib/tinder/room.rb', line 129 def available_transcripts raise NotImplementedError end |
#destroy ⇒ Object
79 80 81 |
# File 'lib/tinder/room.rb', line 79 def destroy raise NotImplementedError end |
#files(count = 5) ⇒ Object
Get the list of latest files for this room
162 163 164 |
# File 'lib/tinder/room.rb', line 162 def files(count = 5) connection.get(room_url_for(:uploads))['uploads'].map { |u| u['full_url'] } end |
#guest_access_enabled? ⇒ Boolean
37 38 39 40 |
# File 'lib/tinder/room.rb', line 37 def guest_access_enabled? load @open_to_guests ? true : false end |
#guest_invite_code ⇒ Object
The invite code use for guest
43 44 45 46 |
# File 'lib/tinder/room.rb', line 43 def guest_invite_code load @active_token_value end |
#guest_url ⇒ Object
Get the url for guest access
29 30 31 32 33 34 35 |
# File 'lib/tinder/room.rb', line 29 def guest_url if guest_access_enabled? "http://#{@campfire.subdomain}.campfirenow.com/#{guest_invite_code}" else nil end end |
#join(force = false) ⇒ Object
Join the room. Pass true
to join even if you’ve already joined.
14 15 16 |
# File 'lib/tinder/room.rb', line 14 def join(force = false) post 'join' end |
#leave ⇒ Object
Leave a room
19 20 21 |
# File 'lib/tinder/room.rb', line 19 def leave post 'leave' end |
#listen(interval = 5) ⇒ Object
Get and array of the messages that have been posted to the room. Each messages is a hash with:
-
:person
: the display name of the person that posted the message -
:message
: the body of the message -
:user_id
: Campfire user id -
:id
: Campfire message idroom.listen #=> [:message=>“I’m getting very sleepy”, :user_id=>“148583”, :id=>“16434003”]
Called without a block, listen will return an array of messages that have been posted since you joined. listen also takes an optional block, which then polls for new messages every 5 seconds and calls the block for each message.
room.listen do |m|
room.speak "#{m[:person]}, Go away!" if m[:message] =~ /Java/i
end
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tinder/room.rb', line 116 def listen(interval = 5) require 'yajl/http_stream' auth = connection.[:basic_auth] url = URI.parse("http://#{auth[:username]}:#{auth[:password]}@streaming.#{Campfire::HOST}/room/#{@id}/live.json") Yajl::HttpStream.get(url) do || { :id => ['id'], :user_id => ['user_id'], :message => ['body'] } end end |
#lock ⇒ Object
Lock the room to prevent new users from entering and to disable logging
66 67 68 |
# File 'lib/tinder/room.rb', line 66 def lock post :lock end |
#paste(message) ⇒ Object
88 89 90 |
# File 'lib/tinder/room.rb', line 88 def paste() (, 'PasteMessage') end |
#ping(force = false) ⇒ Object
75 76 77 |
# File 'lib/tinder/room.rb', line 75 def ping(force = false) raise NotImplementedError end |
#speak(message, options = {}) ⇒ Object
Post a new message to the chat room
84 85 86 |
# File 'lib/tinder/room.rb', line 84 def speak(, = {}) () end |
#toggle_guest_access ⇒ Object
Toggle guest access on or off
24 25 26 |
# File 'lib/tinder/room.rb', line 24 def toggle_guest_access raise NotImplementedError end |
#topic ⇒ Object
Get the current topic
60 61 62 63 |
# File 'lib/tinder/room.rb', line 60 def topic load @topic end |
#topic=(topic) ⇒ Object
Change the topic
55 56 57 |
# File 'lib/tinder/room.rb', line 55 def topic=(topic) connection.post("/room/#{@id}.json", :body => { :room => { :topic => name } }) end |
#transcript(transcript_date) ⇒ Object
Get the transcript for the given date (Returns a hash in the same format as #listen)
room.transcript(room.available_transcripts.first)
#=> [{:message=>"foobar!",
:user_id=>"99999",
:person=>"Brandon",
:id=>"18659245",
:timestamp=>=>Tue May 05 07:15:00 -0700 2009}]
The timestamp slot will typically have a granularity of five minutes.
144 145 146 147 148 149 150 151 152 |
# File 'lib/tinder/room.rb', line 144 def transcript(transcript_date) url = "/room/#{@id}/transcript/#{transcript_date.to_date.strftime('%Y/%m/%d')}.json" connection.get(url)['messages'].map do |room| { :id => room['id'], :user_id => room['user_id'], :message => room['body'], :timestamp => Time.parse(room['created_at']) } end end |
#unlock ⇒ Object
Unlock the room
71 72 73 |
# File 'lib/tinder/room.rb', line 71 def unlock post :unlock end |
#upload(filename) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/tinder/room.rb', line 154 def upload(filename) File.open(filename, "rb") do |file| params = Multipart::MultipartPost.new('upload' => file) connection.post("/room/#{@id}/uploads.json", :body => params.query) end end |
#users ⇒ Object
Get the list of users currently chatting for this room
93 94 95 96 |
# File 'lib/tinder/room.rb', line 93 def users reload! @users end |