Class: Tinder::Campfire

Inherits:
Object
  • Object
show all
Defined in:
lib/tinder/campfire.rb

Overview

Usage

campfire = Tinder::Campfire.new 'mysubdomain', :token => 'xyz'

room = campfire.create_room 'New Room', 'My new campfire room to test tinder'
room.speak 'Hello world!'
room.destroy

room = campfire.find_room_by_guest_hash 'abc123', 'John Doe'
room.speak 'Hello world!'

Instance Attribute Summary collapse

Instance Method Summary collapse

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 true
    
  • :ssl_options: SSL options passed to the underlaying Faraday connection. Allows to specify if the SSL certificate should be verified (:verify => true|false) and to specify the path to the ssl certs directory (:ca_path => “path/certs”)

    Defaults to {:verify => true}
    
  • :proxy: a proxy URI. (e.g. :proxy => ‘user:[email protected]:8000’)

    c = Tinder::Campfire.new(“mysubdomain”, :ssl => true)



27
28
29
# File 'lib/tinder/campfire.rb', line 27

def initialize(subdomain, options = {})
  @connection = Connection.new(subdomain, options)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



15
16
17
# File 'lib/tinder/campfire.rb', line 15

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



64
65
66
67
# File 'lib/tinder/campfire.rb', line 64

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



69
70
71
# File 'lib/tinder/campfire.rb', line 69

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



59
60
61
# File 'lib/tinder/campfire.rb', line 59

def find_room_by_guest_hash(hash, name)
  rooms.detect { |room| room.guest_invite_code == hash }
end

#find_room_by_id(id) ⇒ Object

Find a campfire room by id NOTE: id should be of type Integer



48
49
50
51
# File 'lib/tinder/campfire.rb', line 48

def find_room_by_id(id)
  id = id.to_i
  rooms.detect { |room| room.id == id }
end

#find_room_by_name(name) ⇒ Object

Find a campfire room by name



54
55
56
# File 'lib/tinder/campfire.rb', line 54

def find_room_by_name(name)
  rooms.detect { |room| room.name == name }
end

#meObject

get the user info of the current user



79
80
81
# File 'lib/tinder/campfire.rb', line 79

def me
  connection.get("/users/me.json")["user"]
end

#presenceObject

Get an array of all rooms user is present in



40
41
42
43
44
# File 'lib/tinder/campfire.rb', line 40

def presence
  connection.get('/presence.json')['rooms'].map do |room|
    Room.new(connection, room)
  end
end

#roomsObject

Get an array of all the available rooms TODO: detect rooms that are full (no link)



33
34
35
36
37
# File 'lib/tinder/campfire.rb', line 33

def rooms
  connection.get('/rooms.json')['rooms'].map do |room|
    Room.new(connection, room)
  end
end

#usersObject

List the users that are currently chatting in any room



74
75
76
# File 'lib/tinder/campfire.rb', line 74

def users
  rooms.map(&:users).flatten.compact.uniq.sort_by {|u| u[:name]}
end