Class: Tinder::Campfire

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

Overview

Usage

campfire = Tinder::Campfire.new 'mysubdomain'
campfire. 'my_token'

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!'

Constant Summary collapse

HOST =
"campfirenow.com"

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 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, options = {})
  options = { :ssl => false }.merge(options)
  @connection = Connection.new
  @cookie = nil
  @subdomain = subdomain
  @uri = URI.parse("#{options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}")
  connection.base_uri @uri.to_s
  if options[:proxy]
    uri = URI.parse(options[: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

#connectionObject (readonly)

Returns the value of attribute connection.



17
18
19
# File 'lib/tinder/campfire.rb', line 17

def connection
  @connection
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



17
18
19
# File 'lib/tinder/campfire.rb', line 17

def subdomain
  @subdomain
end

#uriObject (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>]}

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)


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 (token)
  connection.basic_auth(token, 'x')
  @logged_in = true
end

#logoutObject



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

def logout
  connection.default_options.delete(:basic_auth)
  @logged_in = false
end

#roomsObject

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?

Returns:

  • (Boolean)


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