Class: Academical::HttpClient::RequestHandler
- Inherits:
-
Object
- Object
- Academical::HttpClient::RequestHandler
- Defined in:
- lib/academical/http_client/request_handler.rb
Overview
RequestHandler takes care of encoding the request body into format given by options
Class Method Summary collapse
Class Method Details
.set_body(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/academical/http_client/request_handler.rb', line 8 def self.set_body() type = .fetch(:request_type, "json") # Encoding request body into JSON format if type == "json" request_wrapper = {} request_wrapper[:data] = [:body] [:body] = request_wrapper.to_json [:headers]["content-type"] = "application/json" end # Raw body if type == "raw" [:body] = [:body].is_a?(Hash) ? "" : [:body] [:headers].delete("content-type") end return end |