Module: Cortex::Request

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

Instance Method Summary collapse

Instance Method Details

#delete(path) ⇒ Object



27
28
29
30
31
32
# File 'lib/cortex/request.rb', line 27

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

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



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

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



38
39
40
# File 'lib/cortex/request.rb', line 38

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

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



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

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



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

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



34
35
36
# File 'lib/cortex/request.rb', line 34

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