Class: Tinder::Campfire
- Inherits:
-
Object
- Object
- Tinder::Campfire
- Defined in:
- lib/tinder/campfire.rb
Overview
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#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
. -
#me ⇒ Object
get the user info of the current user.
-
#rooms ⇒ Object
Get an array of all the available rooms TODO: detect rooms that are full (no link).
-
#users ⇒ 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)
24 25 26 |
# File 'lib/tinder/campfire.rb', line 24 def initialize(subdomain, = {}) @connection = Connection.new(subdomain, ) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
14 15 16 |
# File 'lib/tinder/campfire.rb', line 14 def connection @connection end |
Instance Method Details
#create_room(name, topic = nil) ⇒ Object
Creates and returns a new Room with the given name
and optionally a topic
47 48 49 50 |
# File 'lib/tinder/campfire.rb', line 47 def create_room(name, topic = nil) connection.post('/rooms.json', { :room => { :name => name, :topic => topic } }) find_room_by_name(name) end |
#find_or_create_room_by_name(name) ⇒ Object
52 53 54 |
# File 'lib/tinder/campfire.rb', line 52 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
42 43 44 |
# File 'lib/tinder/campfire.rb', line 42 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
37 38 39 |
# File 'lib/tinder/campfire.rb', line 37 def find_room_by_name(name) rooms.detect { |room| room.name == name } end |
#me ⇒ Object
get the user info of the current user
62 63 64 |
# File 'lib/tinder/campfire.rb', line 62 def me connection.get("/users/me.json")["user"] end |
#rooms ⇒ Object
Get an array of all the available rooms TODO: detect rooms that are full (no link)
30 31 32 33 34 |
# File 'lib/tinder/campfire.rb', line 30 def rooms connection.get('/rooms.json')['rooms'].map do |room| Room.new(connection, room) end end |
#users ⇒ Object
List the users that are currently chatting in any room
57 58 59 |
# File 'lib/tinder/campfire.rb', line 57 def users rooms.map(&:users).flatten.compact.uniq.sort_by {|u| u[:name]} end |