Module: Footrest::Request

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

Instance Method Summary collapse

Instance Method Details

#delete(path, options = {}) ⇒ Object



8
9
10
# File 'lib/footrest/request.rb', line 8

def delete(path, options={})
  request_with_params_in_url(:delete, path, options)
end

#fullpath(path) ⇒ Object



4
5
6
# File 'lib/footrest/request.rb', line 4

def fullpath(path)
  raise "fullpath should be overridden"
end

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



12
13
14
# File 'lib/footrest/request.rb', line 12

def get(path, options={})
  request_with_params_in_url(:get, path, options)
end

#patch(path, options = {}) ⇒ Object



24
25
26
# File 'lib/footrest/request.rb', line 24

def patch(path, options={})
  request_with_params_in_body(:patch, path, options)
end

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



16
17
18
# File 'lib/footrest/request.rb', line 16

def post(path, options={})
  request_with_params_in_body(:post, path, options)
end

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



20
21
22
# File 'lib/footrest/request.rb', line 20

def put(path, options={})
  request_with_params_in_body(:put, path, options)
end

#request(method, &block) ⇒ Object

Generic request



42
43
44
# File 'lib/footrest/request.rb', line 42

def request(method, &block)
  connection.send(method, &block).body
end

#request_with_params_in_body(method, path, options) ⇒ Object



34
35
36
37
38
39
# File 'lib/footrest/request.rb', line 34

def request_with_params_in_body(method, path, options)
  request(method) do |r|
    r.path = fullpath(path)
    r.body = options unless options.empty?
  end
end

#request_with_params_in_url(method, path, options) ⇒ Object



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

def request_with_params_in_url(method, path, options)
  request(method) do |r|
    r.url(fullpath(path), options)
  end
end