party_cc 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2YzY2E2MGM5Y2EzYWM4OGM4NzliNTc5ODE1NDU1YzVmMDUxYzA3NA==
4
+ ZjZkYTQzZTIxNzA5NDk3MTQ2NjU3MmJjY2QxY2E5M2M1Y2U5MmNhNQ==
5
5
  data.tar.gz: !binary |-
6
- Y2ZmYjkyYzllM2RkZjliYWJlZGJiMzlhMDc3NjEyN2IwOWVjOTM5MA==
6
+ Yjc3NzIxZmQ4YTYyZjg5YmFiM2ZhMDIzMTg0NjlhZjY4Nzc1M2QwYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWNmZjVmOTFjYjk4MzVlMDEzOThiOGU0YjI3YmZhZjA3OGE3YzI1M2I2NjQz
10
- NmUzY2M3NjI0M2FlMWY0MmM3OTNmYzkzNGU5MTZiYTczOGE4MDc1NGM2OTg1
11
- YzJhMjE3NDhiMjZhNmY5NGRjMzNjN2ViOTQzODUwYmQ3NzllMjY=
9
+ NWNjYWFlODA1ODAwZjE1N2Q5ZTAyZDExMWQwN2UwZTcxMmFmN2RjYmU2ZTky
10
+ NGJkYTUwNThjN2ZhMDdjNTkyYjU2OGI5NDQxMmY4NTY3NTQ3ZDJhODQwNmRm
11
+ Nzk5NTZkMmU1M2I3ODljMzg3ZjA4MGNlYjY3YjE1YjNlNTNlYWM=
12
12
  data.tar.gz: !binary |-
13
- N2FlNmI3NWVkNzBhNWQzYzMyM2YwMDFlYjQzYTNmYzI1YTM5ZDdmNzljY2U1
14
- MjYzNWQwNTAzNWU1YzMzNDI0ODY2YTQyYTYwNTE5MWQyMDZjZWY0OTBiMWYx
15
- NjFjMzdhYWRkMDRhNzQ2YTBmZjg3NzE4ZDI2MjAxNTQ0ZWNiODE=
13
+ ZDcwMWFlYzFlNjZlZDhkYzhkNzgwNzY1NzIyNDlhMWY2ZGI1ZjAyYjkwMGI1
14
+ OTE0ZDgzODEyYzUwNmY4NDcyYmM2NDM0YTg2OGM0ODNkODEzYmZiMmZkZTVi
15
+ ZGNlNzM2NWViMTkxMDRlOGZjNzRiNmU1NWFiMzg4YjJiMTBlNjM=
data/README.md CHANGED
@@ -23,7 +23,7 @@ Just require gem and it will generate two files.
23
23
  require 'party_cc'
24
24
  ```
25
25
 
26
- The stub_request will be written down to disk in the format 'stub_#{method}\_#{path}\_#{timestamp}.txt'
26
+ The stub_request will be written down to disk in the format 'stub_#{method}\_#{path}\_#{timestamp}.txt'
27
27
  The request response will be written down to disk in the format 'response_#{method}\_#{path}\_#{timestamp}.txt'
28
28
 
29
29
  ## Contributing
@@ -1,15 +1,24 @@
1
1
  module HTTParty
2
2
  class << self
3
- def decode_ruby buffer
4
- buffer.string
5
- .gsub('=>', ': ')
6
- .gsub('nil', 'null')
7
- end
8
3
 
9
4
  def generate_stub method, response_filename, url, params
10
5
  %Q|stub_request(:#{method}, '#{url}')
11
6
  .with(#{params})
12
- .to_return('#{response_filename}')|
7
+ .to_return(File.new('#{response_filename}'))|
8
+ end
9
+
10
+ def pp_body body
11
+ buffer = StringIO.new
12
+
13
+ jsonified = JSON.load body
14
+ PP.pp(jsonified, buffer)
15
+
16
+ buffer
17
+ rescue
18
+ xmldoc = REXML::Document.new body
19
+ xmldoc.write buffer
20
+
21
+ buffer
13
22
  end
14
23
 
15
24
  request_methods = ['get', 'post', 'patch', 'put', 'delete', 'head', 'options']
@@ -27,11 +36,7 @@ module HTTParty
27
36
  base_file_name = "#{method}_\#{path}_\#{stmp}.txt"
28
37
  response_file_name = "response_\#{base_file_name}"
29
38
 
30
- rsp_buffer = StringIO.new
31
-
32
- PP.pp(rsp, rsp_buffer)
33
-
34
- prettied_rsp = decode_ruby rsp_buffer
39
+ prettied_rsp = pp_body(rsp.response.body).string
35
40
 
36
41
  File.write("stub_\#{base_file_name}", generate_stub(:#{method}, response_file_name, *args))
37
42
  File.open(response_file_name, 'w') do |f|
@@ -1,3 +1,3 @@
1
1
  module PartyCC
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/party_cc.rb CHANGED
@@ -3,6 +3,7 @@ require 'pp'
3
3
  require 'httparty'
4
4
  require 'net/http'
5
5
  require 'net/https'
6
+ require "rexml/document"
6
7
 
7
8
  require "party_cc/version"
8
9
  require 'party_cc/string_buffered_i_o'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: party_cc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - barberj