Class: HTTParty::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/request_ext.rb

Instance Method Summary collapse

Instance Method Details

#get_uriObject

HTTParty::Request does some weird things with url params (namely, repeating them) use last_uri if it exists



6
7
8
# File 'lib/request_ext.rb', line 6

def get_uri
  (self.respond_to?('last_uri') && last_uri) ? last_uri : uri
end

#to_curlObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/request_ext.rb', line 20

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

#to_jsonObject

monkey patch to_json and to_curl methods into Request



11
12
13
14
15
16
17
18
# File 'lib/request_ext.rb', line 11

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