Class: Pyre::Room
- Inherits:
-
Object
- Object
- Pyre::Room
- Defined in:
- lib/pyre/room.rb
Overview
Pyre::Room is for interacting with a room!
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, url, id, campfire) ⇒ Room
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#join ⇒ Object
Enter the room.
-
#joined? ⇒ Boolean
If you’re in the room right now.
-
#leave ⇒ Object
Leave the room.
-
#paste(message) ⇒ Object
Paste
message
to the room. -
#speak(message) ⇒ Object
Send
message
to the room. -
#upload(filename) ⇒ Object
Upload a file (named
filename
) to the room.
Constructor Details
#initialize(name, url, id, campfire) ⇒ Room
:nodoc:
6 7 8 9 10 11 |
# File 'lib/pyre/room.rb', line 6 def initialize(name, url, id, campfire) #:nodoc: @name = name @url = url @id = id @campfire = campfire end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/pyre/room.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/pyre/room.rb', line 4 def name @name end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
60 61 62 |
# File 'lib/pyre/room.rb', line 60 def inspect #:nodoc: "#<#{self.class} \"#{@name}\" \"#{@url}\">" end |
#join ⇒ Object
Enter the room. Returns true on success.
14 15 16 17 |
# File 'lib/pyre/room.rb', line 14 def join @campfire.agent.get(@url) joined? or raise NavigationError end |
#joined? ⇒ Boolean
If you’re in the room right now.
29 30 31 |
# File 'lib/pyre/room.rb', line 29 def joined? @campfire.agent.current_page.at('h1[@id="room_name"]').inner_text == @name rescue false end |
#leave ⇒ Object
Leave the room. Returns true on success.
20 21 22 23 24 25 26 |
# File 'lib/pyre/room.rb', line 20 def leave if joined? leave = @campfire.agent.current_page.links.detect {|link| link.text == 'Leave'} @campfire.agent.post(leave.uri) not joined? or raise NavigationError end end |
#paste(message) ⇒ Object
Paste message
to the room. Joins the room if necessary. Returns true on success.
42 43 44 45 46 47 |
# File 'lib/pyre/room.rb', line 42 def paste() result = submit_chat_form(, 'paste' => 'true') success = (result.links.detect {|link| link.text == 'View paste'} and result.uri.to_s == "#{@url}/speak") join success or raise CommunicationError end |
#speak(message) ⇒ Object
Send message
to the room. Joins the room if necessary. Returns true on success.
34 35 36 37 38 39 |
# File 'lib/pyre/room.rb', line 34 def speak() result = submit_chat_form() success = (result.uri.to_s == "#{@url}/speak") join success or raise CommunicationError end |
#upload(filename) ⇒ Object
Upload a file (named filename
) to the room. Joins the room if necessary. Returns true on success.
50 51 52 53 54 55 56 57 58 |
# File 'lib/pyre/room.rb', line 50 def upload(filename) join unless joined? upload_form = @campfire.agent.current_page.forms.detect {|form| form.form_node[:id] == 'upload_form_tag'} upload_form.file_uploads.first.file_name = filename result = @campfire.agent.submit(upload_form) join success = @campfire.agent.current_page.search(%Q{ul[@id="file_list"]//a[@href$="/#{File.basename(filename)}"]}).size > 0 success or raise UploadError end |