Sha256: 864ea6cd556fbdae78655ea91ac63f925aad2e898ec0087ddaae04da768333ea
Contents?: true
Size: 922 Bytes
Versions: 22
Compression:
Stored size: 922 Bytes
Contents
module HTTParty class Request # HTTParty::Request does some weird things with url params (namely, repeating them) # use last_uri if it exists def get_uri (self.respond_to?('last_uri') && last_uri) ? last_uri : uri end # monkey patch to_json and to_curl methods into Request def to_json { "requestUrl" => get_uri, "requestMethod" => http_method.to_s.split("::").last.upcase, "requestBody" => send(:body) || "", "headers" => options[:headers].to_a.flatten || [] }.to_json end def to_curl args = ["curl -X #{http_method.to_s.split("::").last.upcase}"] args << "-d #{send(:body).to_json}" if self.send(:body) args << "#{(options[:headers] || []).map{|k, v| "--header \"#{k}:#{v}\""}.join(" ")}" if options[:headers] args << "\"#{get_uri}\"" return args.join(" ") end end end
Version data entries
22 entries across 22 versions & 1 rubygems