Module: Restool::Service::RequestUtils
- Defined in:
- lib/restool/service/request_utils.rb
Class Method Summary collapse
- .build_base_request(method, path) ⇒ Object
- .build_request(method, path, params, headers, basic_auth) ⇒ Object
Class Method Details
.build_base_request(method, path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/restool/service/request_utils.rb', line 31 def self.build_base_request(method, path) case method.to_s.downcase when 'get' Net::HTTP::Get.new(path) when 'post' Net::HTTP::Post.new(path) when 'put' Net::HTTP::Put.new(path) when 'delete' Net::HTTP::Delete.new(path) when 'patch' Net::HTTP::Patch.new(path) end end |
.build_request(method, path, params, headers, basic_auth) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/restool/service/request_utils.rb', line 7 def self.build_request(method, path, params, headers, basic_auth) if ['post', 'put', 'patch'].include?(method) request = build_base_request(method, path) if params && params.is_a?(Hash) request.set_form_data(params) else request.body = params end else uri = URI(path) uri.query = URI.encode_www_form(params) if params request = build_base_request(method, uri.to_s) end request.basic_auth(basic_auth.user, basic_auth.password) if basic_auth headers.each { |k, v| request[k] = v } if headers OperationRequest.new(request, method, path, params, headers) end |