Class: Dickburt::Campfire

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

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Campfire

Returns a new instance of Campfire.



7
8
9
10
# File 'lib/dickburt/campfire.rb', line 7

def initialize(args={})
  @token = args[:token] 
  @host = "https://#{args[:host]}.campfirenow.com"
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/dickburt/campfire.rb', line 3

def host
  @host
end

#tokenObject

Returns the value of attribute token.



2
3
4
# File 'lib/dickburt/campfire.rb', line 2

def token
  @token
end

Instance Method Details

#httpObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dickburt/campfire.rb', line 12

def http
  @http ||= Patron::Session.new
  @http.base_url = host
  @http.headers["Content-Type"] = "application/json"
  @http.headers['User-Agent'] = "Dickburt #{Dickburt::VERSION}"
  @http.username = token 
  @http.password = "x"
  @http.connect_timeout = 6000
  @http.timeout = 6000
  @http
end

#roomsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dickburt/campfire.rb', line 24

def rooms
  return @rooms if @rooms
  response = http.get("/rooms.json")
  @rooms = []
  if response.status < 400
    @rooms = JSON.parse(response.body)['rooms'] 
    @rooms.collect! do |room|
      Dickburt::Room.new(room, self)
    end
  else
    raise Dickburt::Campfire::Error, response.status.to_s + ": " + response.body
  end
end