Class: Tinder::Campfire
- Inherits:
-
Object
- Object
- Tinder::Campfire
- Defined in:
- lib/tinder/campfire.rb
Overview
Usage
campfire = Tinder::Campfire.new 'mysubdomain'
campfire.login '[email protected]', 'mypassword'
room = campfire.create_room 'New Room', 'My new campfire room to test tinder'
room.speak 'Hello world!'
room.destroy
Instance Attribute Summary collapse
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#available_transcripts(room = nil) ⇒ Object
Get the dates of the available transcripts by room.
-
#create_room(name, topic = nil) ⇒ Object
Creates and returns a new Room with the given
name
and optionally atopic
. - #find_or_create_room_by_name(name) ⇒ Object
-
#find_room_by_name(name) ⇒ Object
Find a campfire room by name.
-
#host ⇒ Object
Deprecated: only included for backwards compatability.
-
#initialize(subdomain, options = {}) ⇒ Campfire
constructor
Create a new connection to the campfire account with the given
subdomain
. -
#logged_in? ⇒ Boolean
Returns true when successfully logged in.
-
#login(email, password) ⇒ Object
Log in to campfire using your
email
andpassword
. - #logout ⇒ Object
-
#rooms ⇒ Object
Get an array of all the available rooms TODO: detect rooms that are full (no link).
-
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?.
-
#users(*room_names) ⇒ Object
List the users that are currently chatting in any room.
Constructor Details
#initialize(subdomain, options = {}) ⇒ Campfire
17 18 19 20 21 22 |
# File 'lib/tinder/campfire.rb', line 17 def initialize(subdomain, = {}) = { :ssl => false }.merge() @cookie = nil @subdomain = subdomain @uri = URI.parse("#{[:ssl] ? 'https' : 'http' }://#{subdomain}.campfirenow.com") end |
Instance Attribute Details
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
11 12 13 |
# File 'lib/tinder/campfire.rb', line 11 def subdomain @subdomain end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
11 12 13 |
# File 'lib/tinder/campfire.rb', line 11 def uri @uri end |
Instance Method Details
#available_transcripts(room = nil) ⇒ Object
Get the dates of the available transcripts by room
campfire.available_transcripts
#=> {"15840" => [#<Date: 4908311/2,0,2299161>, #<Date: 4908285/2,0,2299161>]}
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tinder/campfire.rb', line 80 def available_transcripts(room = nil) url = "files%2Btranscripts" url += "?room_id#{room}" if room transcripts = (Hpricot(get(url).body) / ".transcript").inject({}) do |result,transcript| link = (transcript / "a").first.attributes['href'] (result[room_id_from_url(link)] ||= []) << Date.parse(link.scan(/\/transcript\/(\d{4}\/\d{2}\/\d{2})/).to_s) result end room ? transcripts[room.to_s] : transcripts end |
#create_room(name, topic = nil) ⇒ Object
Creates and returns a new Room with the given name
and optionally a topic
57 58 59 |
# File 'lib/tinder/campfire.rb', line 57 def create_room(name, topic = nil) find_room_by_name(name) if verify_response(post("account/create/room?from=lobby", {:room => {:name => name, :topic => topic}}, :ajax => true), :success) end |
#find_or_create_room_by_name(name) ⇒ Object
61 62 63 |
# File 'lib/tinder/campfire.rb', line 61 def find_or_create_room_by_name(name) find_room_by_name(name) || create_room(name) end |
#find_room_by_name(name) ⇒ Object
Find a campfire room by name
52 53 54 |
# File 'lib/tinder/campfire.rb', line 52 def find_room_by_name(name) rooms.detect {|room| room.name == name } end |
#host ⇒ Object
Deprecated: only included for backwards compatability
92 93 94 |
# File 'lib/tinder/campfire.rb', line 92 def host #:nodoc: uri.host end |
#logged_in? ⇒ Boolean
Returns true when successfully logged in
33 34 35 |
# File 'lib/tinder/campfire.rb', line 33 def logged_in? @logged_in === true end |
#login(email, password) ⇒ Object
Log in to campfire using your email
and password
25 26 27 28 29 30 |
# File 'lib/tinder/campfire.rb', line 25 def login(email, password) unless verify_response(post("login", :email_address => email, :password => password), :redirect_to => url_for(:only_path => false)) raise Error, "Campfire login failed" end @logged_in = true end |
#logout ⇒ Object
37 38 39 40 41 |
# File 'lib/tinder/campfire.rb', line 37 def logout returning verify_response(get("logout"), :redirect) do |result| @logged_in = !result end end |
#rooms ⇒ Object
Get an array of all the available rooms TODO: detect rooms that are full (no link)
45 46 47 48 49 |
# File 'lib/tinder/campfire.rb', line 45 def rooms Hpricot(get.body).search("//h2/a").collect do |a| Room.new(self, room_id_from_url(a.attributes['href']), a.inner_html) end end |
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?
97 98 99 |
# File 'lib/tinder/campfire.rb', line 97 def ssl? uri.scheme == 'https' end |
#users(*room_names) ⇒ Object
List the users that are currently chatting in any room
66 67 68 69 70 71 72 73 |
# File 'lib/tinder/campfire.rb', line 66 def users(*room_names) users = Hpricot(get.body).search("div.room").collect do |room| if room_names.empty? || room_names.include?((room/"h2/a").inner_html) room.search("//li.user").collect { |user| user.inner_html } end end users.flatten.compact.uniq.sort end |