Module: HTTParty

Defined in:
lib/party_cc/httparty.rb

Class Method Summary collapse

Class Method Details

.adjust_content_length_for_pretty_print(rsp, net_rsp) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/party_cc/httparty.rb', line 31

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) ⇒ Object



10
11
12
13
14
# File 'lib/party_cc/httparty.rb', line 10

def decode_ruby buffer
  buffer.string
    .gsub('=>', ': ')
    .gsub('nil', 'null')
end

.generate_stub(method, response_filename, url, params) ⇒ Object



4
5
6
7
8
# File 'lib/party_cc/httparty.rb', line 4

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) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/party_cc/httparty.rb', line 16

def pp_body body
  buffer = StringIO.new

  jsonified = JSON.load body

  PP.pp(jsonified, buffer)

  buffer
rescue
  xmldoc = REXML::Document.new body
  xmldoc.write buffer

  buffer
end