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

#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


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

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

#request_with_params_in_body(method, path, options) ⇒ Object


30
31
32
33
34
35
# File 'lib/footrest/request.rb', line 30

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


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

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