Class: Tinder::Campfire
- Inherits:
-
Object
- Object
- Tinder::Campfire
- Defined in:
- lib/tinder/campfire.rb
Overview
Constant Summary collapse
- HOST =
"campfirenow.com"
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#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_guest_hash(hash, name) ⇒ Object
Find a campfire room by its guest hash.
-
#find_room_by_name(name) ⇒ Object
Find a campfire room by name.
-
#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(token) ⇒ Object
Log in to campfire using your token.
- #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
Create a new connection to the campfire account with the given subdomain
.
Options:
-
:ssl
: use SSL for the connection, which is required if you have a Campfire SSL account.Defaults to false
-
:proxy
: a proxy URI. (e.g. :proxy => ‘user:[email protected]:8000’)c = Tinder::Campfire.new(“mysubdomain”, :ssl => true)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tinder/campfire.rb', line 27 def initialize(subdomain, = {}) = { :ssl => false }.merge() @connection = Connection.new @cookie = nil @subdomain = subdomain @uri = URI.parse("#{[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}") connection.base_uri @uri.to_s if [:proxy] uri = URI.parse([:proxy]) @http = Net::HTTP::Proxy(uri.host, uri.port, uri.user, uri.password) else @http = Net::HTTP end @logged_in = false end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
17 18 19 |
# File 'lib/tinder/campfire.rb', line 17 def connection @connection end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
17 18 19 |
# File 'lib/tinder/campfire.rb', line 17 def subdomain @subdomain end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
17 18 19 |
# File 'lib/tinder/campfire.rb', line 17 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>]}
97 98 99 |
# File 'lib/tinder/campfire.rb', line 97 def available_transcripts(room = nil) raise NotImplementedError end |
#create_room(name, topic = nil) ⇒ Object
Creates and returns a new Room with the given name
and optionally a topic
78 79 80 81 |
# File 'lib/tinder/campfire.rb', line 78 def create_room(name, topic = nil) connection.post('/rooms.json', :body => { :room => { :name => name, :topic => topic } }.to_json) find_room_by_name(name) end |
#find_or_create_room_by_name(name) ⇒ Object
83 84 85 |
# File 'lib/tinder/campfire.rb', line 83 def find_or_create_room_by_name(name) find_room_by_name(name) || create_room(name) end |
#find_room_by_guest_hash(hash, name) ⇒ Object
Find a campfire room by its guest hash
73 74 75 |
# File 'lib/tinder/campfire.rb', line 73 def find_room_by_guest_hash(hash, name) rooms.detect { |room| room.guest_invite_code == hash } end |
#find_room_by_name(name) ⇒ Object
Find a campfire room by name
68 69 70 |
# File 'lib/tinder/campfire.rb', line 68 def find_room_by_name(name) rooms.detect { |room| room.name == name } end |
#logged_in? ⇒ Boolean
Returns true when successfully logged in
50 51 52 |
# File 'lib/tinder/campfire.rb', line 50 def logged_in? @logged_in == true end |
#login(token) ⇒ Object
Log in to campfire using your token
44 45 46 47 |
# File 'lib/tinder/campfire.rb', line 44 def login(token) connection.basic_auth(token, 'x') @logged_in = true end |
#logout ⇒ Object
54 55 56 57 |
# File 'lib/tinder/campfire.rb', line 54 def logout connection..delete(:basic_auth) @logged_in = false end |
#rooms ⇒ Object
Get an array of all the available rooms TODO: detect rooms that are full (no link)
61 62 63 64 65 |
# File 'lib/tinder/campfire.rb', line 61 def rooms connection.get('/rooms.json')['rooms'].map do |room| Room.new(self, room) end end |
#ssl? ⇒ Boolean
Is the connection to campfire using ssl?
102 103 104 |
# File 'lib/tinder/campfire.rb', line 102 def ssl? uri.scheme == 'https' end |
#users(*room_names) ⇒ Object
List the users that are currently chatting in any room
88 89 90 |
# File 'lib/tinder/campfire.rb', line 88 def users(*room_names) rooms.map(&:users).flatten.compact.uniq.sort end |