module HTTParty
Public Class Methods
adjust_content_length_for_pretty_print(rsp, net_rsp)
click to toggle source
# File lib/party_cc/httparty.rb, line 39 def adjust_content_length_for_pretty_print rsp, net_rsp headers = net_rsp.response.instance_variable_get :@raw_headers headers.gsub!(/(Content-Length|content-length)(:\s+)(\d+)/, '\1\2<CONTENTLENGTH>') size_without_substituion = headers.bytesize + rsp.bytesize - 15 size = size_without_substituion + size_without_substituion.to_s.length headers.gsub("<CONTENTLENGTH>", size.to_s) end
decode_ruby(buffer)
click to toggle source
# File lib/party_cc/httparty.rb, line 12 def decode_ruby buffer buffer.string .gsub('=>', ': ') .gsub('nil', 'null') rescue buffer end
generate_stub(method, response_filename, url, params={})
click to toggle source
# File lib/party_cc/httparty.rb, line 6 def generate_stub(method, response_filename, url, params={}) %Q|stub_request(:#{method}, '#{url}') .with(#{params}) .to_return(File.new('#{response_filename}'))| end
pp_body(body, type)
click to toggle source
# File lib/party_cc/httparty.rb, line 20 def pp_body(body, type) buffer = StringIO.new case when type && type.downcase.include?('json') jsonified = JSON.load body PP.pp(jsonified, buffer) when type && type.downcase.include?('xml') xmldoc = REXML::Document.new(body) xmldoc.write(buffer) else PP.pp(body, buffer) end buffer rescue PP.pp(body, buffer) buffer end