Class: Buffer::HttpClient::RequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/buffer/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
# File 'lib/buffer/http_client/request_handler.rb', line 8

def self.set_body(options)
  type = options.has_key?(:request_type) ? options[:request_type] : "form"

  # Encoding body into form-urlencoded format
  if type == "form"
    options[:body] = Faraday::Utils::ParamsHash[options[:body]].to_query
    options[:headers]["content-type"] = "application/x-www-form-urlencoded"
  end

  # Raw body
  if type == "raw"
    options[:body] = options[:body].is_a?(Hash) ? "" : options[:body]
    options[:headers].delete "content-type"
  end

  return options
end