Class: Dickburt::Campfire
- Inherits:
-
Object
- Object
- Dickburt::Campfire
- Defined in:
- lib/dickburt/campfire.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #http ⇒ Object
-
#initialize(args = {}) ⇒ Campfire
constructor
A new instance of Campfire.
- #rooms ⇒ Object
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
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/dickburt/campfire.rb', line 3 def host @host end |
#token ⇒ Object
Returns the value of attribute token.
2 3 4 |
# File 'lib/dickburt/campfire.rb', line 2 def token @token end |
Instance Method Details
#http ⇒ Object
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 |
#rooms ⇒ Object
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 |