Module: Cortex::Request

Included in:
Client
Defined in:
lib/cortex/request.rb

Instance Method Summary collapse

Instance Method Details

#delete(path) ⇒ Object



29
30
31
32
33
34
# File 'lib/cortex/request.rb', line 29

def delete(path)
  response = connection.delete do |r|
    r.url base_url + path
  end
  parse_response(response)
end

#get(path, params = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/cortex/request.rb', line 5

def get(path, params = {})
  response = connection.get do |r|
    r.url base_url + path
    r.params = params
  end
  parse_response(response)
end

#parse_response(response) ⇒ Object



40
41
42
# File 'lib/cortex/request.rb', line 40

def parse_response(response)
  Cortex::Result.new(response.body, response.headers, response.status)
end

#post(path, params = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/cortex/request.rb', line 13

def post(path, params = {})
  response = connection.post do |r|
    r.url base_url + path
    r.body = params unless params.empty?
  end
  parse_response(response)
end

#put(path, params = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/cortex/request.rb', line 21

def put(path, params = {})
  response = connection.put do |r|
    r.url base_url + path
    r.body = params unless params.empty?
  end
  parse_response(response)
end

#save(path, model) ⇒ Object



36
37
38
# File 'lib/cortex/request.rb', line 36

def save(path, model)
  model[:id] ? put("#{path}/#{model[:id]}", model) : post(path, model)
end