Class: HTTParty::Request
- Inherits:
-
Object
- Object
- HTTParty::Request
- Defined in:
- lib/request_ext.rb
Instance Method Summary collapse
-
#get_uri ⇒ Object
HTTParty::Request does some weird things with url params (namely, repeating them) use last_uri if it exists.
- #to_curl ⇒ Object
-
#to_json ⇒ Object
monkey patch to_json and to_curl methods into Request.
Instance Method Details
#get_uri ⇒ Object
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_curl ⇒ Object
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 << "#{([:headers] || []).map{|k, v| "--header \"#{k}:#{v}\""}.join(" ")}" if [:headers] args << "\"#{get_uri}\"" return args.join(" ") end |
#to_json ⇒ Object
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" => [:headers].to_a.flatten || [] }.to_json end |