Module: Vertebrae::Request
- Included in:
- API
- Defined in:
- lib/vertebrae/request.rb
Constant Summary collapse
- METHODS =
[:get, :post, :put, :delete, :patch]
- METHODS_WITH_BODIES =
[ :post, :put, :patch ]
Instance Method Summary collapse
- #delete_request(path, params = {}, options = {}) ⇒ Object
- #get_request(path, params = {}, options = {}) ⇒ Object
- #patch_request(path, params = {}, options = {}) ⇒ Object
- #post_request(path, params = {}, options = {}) ⇒ Object
- #put_request(path, params = {}, options = {}) ⇒ Object
-
#request(method, path, params, options) ⇒ Object
:nodoc:.
Instance Method Details
#delete_request(path, params = {}, options = {}) ⇒ Object
25 26 27 |
# File 'lib/vertebrae/request.rb', line 25 def delete_request(path, params={}, ={}) request(:delete, path, params, ) end |
#get_request(path, params = {}, options = {}) ⇒ Object
9 10 11 |
# File 'lib/vertebrae/request.rb', line 9 def get_request(path, params={}, ={}) request(:get, path, params, ) end |
#patch_request(path, params = {}, options = {}) ⇒ Object
13 14 15 |
# File 'lib/vertebrae/request.rb', line 13 def patch_request(path, params={}, ={}) request(:patch, path, params, ) end |
#post_request(path, params = {}, options = {}) ⇒ Object
17 18 19 |
# File 'lib/vertebrae/request.rb', line 17 def post_request(path, params={}, ={}) request(:post, path, params, ) end |
#put_request(path, params = {}, options = {}) ⇒ Object
21 22 23 |
# File 'lib/vertebrae/request.rb', line 21 def put_request(path, params={}, ={}) request(:put, path, params, ) end |
#request(method, path, params, options) ⇒ Object
:nodoc:
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vertebrae/request.rb', line 29 def request(method, path, params, ) # :nodoc: if !::Vertebrae::Request::METHODS.include?(method) raise ArgumentError, "unknown http method: #{method}" end connection. = .merge(.merge()) path = connection.configuration.prefix + '/' + path ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}" connection.connection.send(method) do |request| case method.to_sym when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES) request.body = params.delete('data') if params.has_key?('data') request.url(path, params) when *::Vertebrae::Request::METHODS_WITH_BODIES request.path = path request.body = extract_data_from_params(params) unless params.empty? end end end |