party_cc 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGEzM2Q2OTUyOTYzM2VkNjFjMzUyZGFiMGI2ZjI4Y2EwNmNmOGIxMA==
4
+ MjIwY2NjMDRmOGQxYzExYTZiZjk0YzUyNTVhZDFmNWRhOTliZmNhNA==
5
5
  data.tar.gz: !binary |-
6
- YjhhNWIyOThiMDNiZWNkOTBkZDY2ZGY3OTVjM2UyMzBhM2E0NzhhMw==
6
+ NjE0N2RjY2MwYzIyNTViZTY5MjA1MWY2ODdmMjgxZmYwODM2M2VhZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzUwNjgwMmQ0YzM3MDgxM2E5ZjlmZDJjY2E5MjgwZDU5MWMzNDdmZTM0MTU5
10
- ZDcyYWI0NDZhNTMxMjA3Mzk4ZDlkM2MzMGQ4YmIxMDhhYmM3ZmFiYjFhMDg0
11
- MzQzNDE2NmM5NTkyZjM5Yjg5NjVhZmU5ZWJlMzdmZWZkMmEwNzQ=
9
+ NjBiMTY2ZjFjMGUyOWY2MzAwODhmNDNhNzJhNWJhNjQ0MDc2NjI2MTEyMTI5
10
+ NzZmYmFiOTRmMGUyNzVhOTIzMWZiNGExMTY3MWRkY2E0YWE0ZjVjNjk3YzUx
11
+ Mzc0MDIyOGQyNDE5ZjdhNzc2OGJmY2FjNDRmNzkxMzNmNTdiZWE=
12
12
  data.tar.gz: !binary |-
13
- MDk5OGVlNzgxYWJlNzZmYTk0ODNhZDM3MmE0YTM4YjU5YWViYzhmMjYwNGE1
14
- NWM5MjBkZTcwMzg0NjA5ZTcyZTM1NzA3YWQ0Njc4NjQ2MGIwY2NjYmYzOGYx
15
- OGEwN2E0OGJhMTliOWZhMWRmMGFkMjAyN2YxMDQzODE2OWE2Zjc=
13
+ Y2MyYTQ2YjMzNzI0MzhjNDg1YjRmMDllNzRmN2IzODBjM2IyMDgyMGVhNDM4
14
+ OGZkZjE2YWRkYTEzYjIzNmJmNTE3YWY5ZDI1YmNhODRlNDNkZDg1YzYwOTMz
15
+ NDE3OTUxMmQ0MDM1ODQyYWY2YzA5M2QxNGZkZGU4ZmE5OGQ4Y2I=
@@ -1,7 +1,7 @@
1
1
  module HTTParty
2
2
  class << self
3
3
 
4
- def generate_stub method, response_filename, url, params
4
+ def generate_stub(method, response_filename, url, params={})
5
5
  %Q|stub_request(:#{method}, '#{url}')
6
6
  .with(#{params})
7
7
  .to_return(File.new('#{response_filename}'))|
@@ -11,19 +11,22 @@ module HTTParty
11
11
  buffer.string
12
12
  .gsub('=>', ': ')
13
13
  .gsub('nil', 'null')
14
+ rescue
15
+ buffer
14
16
  end
15
17
 
16
- def pp_body body
18
+ def pp_body(body, type)
17
19
  buffer = StringIO.new
18
-
19
- jsonified = JSON.load body
20
-
21
- PP.pp(jsonified, buffer)
22
-
23
- buffer
24
- rescue
25
- xmldoc = REXML::Document.new body
26
- xmldoc.write buffer
20
+ case
21
+ when type.downcase.include?('json')
22
+ jsonified = JSON.load body
23
+ PP.pp(jsonified, buffer)
24
+ when type.downcase.include?('xml')
25
+ xmldoc = REXML::Document.new(body)
26
+ xmldoc.write(buffer)
27
+ else
28
+ PP.pp(body, buffer)
29
+ end
27
30
 
28
31
  buffer
29
32
  end
@@ -52,14 +55,14 @@ module HTTParty
52
55
  base_file_name = "#{method}_\#{path}_\#{stmp}.txt"
53
56
  response_file_name = "response_\#{base_file_name}"
54
57
 
55
- prettied_rsp = decode_ruby(pp_body(rsp.response.body))
56
- adjusted_headers = adjust_content_length_for_pretty_print prettied_rsp, rsp
58
+ prettied_rsp = decode_ruby(pp_body(rsp.response.body, rsp.headers['content-type']))
59
+ adjusted_headers = adjust_content_length_for_pretty_print(prettied_rsp, rsp)
57
60
 
58
- File.write("stub_\#{base_file_name}", generate_stub(:#{method}, response_file_name, *args))
59
61
  File.open(response_file_name, 'w') do |f|
60
- f.write adjusted_headers
61
- f.write prettied_rsp
62
+ f.write(adjusted_headers)
63
+ f.write(prettied_rsp)
62
64
  end
65
+ File.write("stub_\#{base_file_name}", generate_stub(:#{method}, response_file_name, *args))
63
66
 
64
67
  rsp
65
68
  end
@@ -1,3 +1,3 @@
1
1
  module PartyCC
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: party_cc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - barberj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler