Module: Flamethrower::Campfire::RestApi

Included in:
Connection, Room
Defined in:
lib/flamethrower/campfire/rest_api.rb

Instance Method Summary collapse

Instance Method Details

#campfire_get(path, args = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/flamethrower/campfire/rest_api.rb', line 9

def campfire_get(path, args = {})
  action_log("get", path, nil)
  full_path = host << path
  http = EventMachine::HttpRequest.new(full_path).get(
    :head => {'authorization' => [@token, 'x']},
    :query => args)
  http.errback { on_connection_error("get", path) }
  http
end

#campfire_post(path, json = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/flamethrower/campfire/rest_api.rb', line 19

def campfire_post(path, json=nil)
  action_log("post", path, json)
  full_path = host << path
  params = {:head => {'Content-Type' => 'application/json', 'authorization' => [@token, 'x']}}
  params[:body] = json if json
  http = EventMachine::HttpRequest.new(full_path).post params
  http.errback { on_connection_error("post", path) }
  http
end

#campfire_put(path, json = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/flamethrower/campfire/rest_api.rb', line 29

def campfire_put(path, json=nil)
  action_log("put", path, json)
  full_path = host << path
  params = {:head => {'Content-Type' => 'application/json', 'authorization' => [@token, 'x']}}
  params[:body] = json if json
  http = EventMachine::HttpRequest.new(full_path).put params
  http.errback { on_connection_error("put", path) }
  http
end

#hostObject



5
6
7
# File 'lib/flamethrower/campfire/rest_api.rb', line 5

def host
  "https://#{@domain}.campfirenow.com"
end