Class: Matchstick::Campfire

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

Direct Known Subclasses

Room

Constant Summary collapse

HOST =
"campfirenow.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subdomain, api_key, use_ssl = false) ⇒ Campfire

Returns a new instance of Campfire.



8
9
10
11
12
13
14
15
# File 'lib/matchstick/campfire.rb', line 8

def initialize(subdomain, api_key, use_ssl=false)
  @subdomain  = subdomain
  @api_key    = api_key
  @use_ssl    = use_ssl
  @connection = build_connection

  self
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/matchstick/campfire.rb', line 6

def api_key
  @api_key
end

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/matchstick/campfire.rb', line 6

def connection
  @connection
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



6
7
8
# File 'lib/matchstick/campfire.rb', line 6

def subdomain
  @subdomain
end

#use_sslObject (readonly)

Returns the value of attribute use_ssl.



6
7
8
# File 'lib/matchstick/campfire.rb', line 6

def use_ssl
  @use_ssl
end

Instance Method Details

#get(action) ⇒ Object



21
22
23
24
# File 'lib/matchstick/campfire.rb', line 21

def get(action)
  response = RestClient.get "#{connection}/#{action}", :content_type => :json, :accept => :json
  response.body.strip.empty? ? true : JSON.parse(response.body)
end

#post(action, body = {}) ⇒ Object



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

def post(action, body = {})
  response = RestClient.post "#{connection}/#{action}", body.to_json, :content_type => :json, :accept => :json
  response.body.strip.empty? ? true : JSON.parse(response.body)
end

#roomsObject



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

def rooms
  get("rooms")["rooms"].collect {|room| Room.new(room, connection)}
end