Module: Footrest::Request
- Included in:
- Client
- Defined in:
- lib/footrest/request.rb
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #fullpath(path) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #patch(path, options = {}) ⇒ Object
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
-
#request(method, &block) ⇒ Object
Generic request.
- #request_with_params_in_body(method, path, options) ⇒ Object
- #request_with_params_in_url(method, path, options) ⇒ Object
Instance Method Details
#delete(path, options = {}) ⇒ Object
8 9 10 |
# File 'lib/footrest/request.rb', line 8 def delete(path, ={}) request_with_params_in_url(:delete, path, ) 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, ={}) request_with_params_in_url(:get, path, ) end |
#patch(path, options = {}) ⇒ Object
24 25 26 |
# File 'lib/footrest/request.rb', line 24 def patch(path, ={}) request_with_params_in_body(:patch, path, ) end |
#post(path, options = {}) ⇒ Object
16 17 18 |
# File 'lib/footrest/request.rb', line 16 def post(path, ={}) request_with_params_in_body(:post, path, ) end |
#put(path, options = {}) ⇒ Object
20 21 22 |
# File 'lib/footrest/request.rb', line 20 def put(path, ={}) request_with_params_in_body(:put, path, ) 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, ) request(method) do |r| r.path = fullpath(path) r.body = unless .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, ) request(method) do |r| r.url(fullpath(path), ) end end |