party_cc 0.0.3 → 0.0.4

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
- YzMxNzA3NWRhYTEyZjE4ZTYwNmIyOGE1OThkYmJkNWQ1ZDg1YWE4Zg==
4
+ N2YzY2E2MGM5Y2EzYWM4OGM4NzliNTc5ODE1NDU1YzVmMDUxYzA3NA==
5
5
  data.tar.gz: !binary |-
6
- MGY4ODk0NzI0ODEyMDk2NzUyNWFiODY0OTgzMDkxZTI2MDg2ZGU0ZA==
6
+ Y2ZmYjkyYzllM2RkZjliYWJlZGJiMzlhMDc3NjEyN2IwOWVjOTM5MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGRkYzY2OGJkMDgyY2I1M2U3Yjg0ZjhkODJmNzQyYThjOTY2YmZjNDQ5NGZh
10
- YzAyMGYwY2ZhODQwNGI4YTcwNzM5YzU3YTU3ODkxODU2M2QxMTFlOGU0NzEx
11
- MzUzNzZkN2Q3Njc0YzJiODYxM2Y3NDZjM2Y5ZDI4ZDcxYzdlZTM=
9
+ MWNmZjVmOTFjYjk4MzVlMDEzOThiOGU0YjI3YmZhZjA3OGE3YzI1M2I2NjQz
10
+ NmUzY2M3NjI0M2FlMWY0MmM3OTNmYzkzNGU5MTZiYTczOGE4MDc1NGM2OTg1
11
+ YzJhMjE3NDhiMjZhNmY5NGRjMzNjN2ViOTQzODUwYmQ3NzllMjY=
12
12
  data.tar.gz: !binary |-
13
- MjNjMTU1M2I4NjBmNjhhZTcxMDU2YTExMmY1YzM4ZDEwZjBiMTI2MjVmYjlh
14
- Nzg5M2M2ODdkYTlmNmM4ZGMxYjhiYjEwMjU3YzljNGRkMGIzNWRiZTg2YzQy
15
- NzdhZGQ3ODk1NjEzYzJkNjdhYmRlZTcyYWI5MzY3MjE1ZTQyNTk=
13
+ N2FlNmI3NWVkNzBhNWQzYzMyM2YwMDFlYjQzYTNmYzI1YTM5ZDdmNzljY2U1
14
+ MjYzNWQwNTAzNWU1YzMzNDI0ODY2YTQyYTYwNTE5MWQyMDZjZWY0OTBiMWYx
15
+ NjFjMzdhYWRkMDRhNzQ2YTBmZjg3NzE4ZDI2MjAxNTQ0ZWNiODE=
data/README.md CHANGED
@@ -18,11 +18,14 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- Just require gem and it will write responses down to disk in the format '#{method}\_#{path}\_#{timestamp}.txt'
21
+ Just require gem and it will generate two files.
22
22
  ```ruby
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'
27
+ The request response will be written down to disk in the format 'response_#{method}\_#{path}\_#{timestamp}.txt'
28
+
26
29
  ## Contributing
27
30
 
28
31
  1. Fork it
@@ -6,6 +6,12 @@ module HTTParty
6
6
  .gsub('nil', 'null')
7
7
  end
8
8
 
9
+ def generate_stub method, response_filename, url, params
10
+ %Q|stub_request(:#{method}, '#{url}')
11
+ .with(#{params})
12
+ .to_return('#{response_filename}')|
13
+ end
14
+
9
15
  request_methods = ['get', 'post', 'patch', 'put', 'delete', 'head', 'options']
10
16
  request_methods.each do |method|
11
17
  class_eval <<-EOT, __FILE__, __LINE__ + 1
@@ -18,19 +24,17 @@ module HTTParty
18
24
  path = Addressable::URI.parse(args[0])
19
25
  .path.split('/').join('_').gsub(/^_/,'')
20
26
 
21
- file_name = "#{method}_\#{path}_\#{stmp}.txt"
27
+ base_file_name = "#{method}_\#{path}_\#{stmp}.txt"
28
+ response_file_name = "response_\#{base_file_name}"
22
29
 
23
- req_buffer = StringIO.new
24
30
  rsp_buffer = StringIO.new
25
31
 
26
- PP.pp(args, req_buffer)
27
32
  PP.pp(rsp, rsp_buffer)
28
33
 
29
- prettied_req = decode_ruby req_buffer
30
34
  prettied_rsp = decode_ruby rsp_buffer
31
35
 
32
- File.write("request_\#{file_name}", prettied_req)
33
- File.open("response_\#{file_name}", 'w') do |f|
36
+ File.write("stub_\#{base_file_name}", generate_stub(:#{method}, response_file_name, *args))
37
+ File.open(response_file_name, 'w') do |f|
34
38
  f.write rsp.response.instance_variable_get :@raw_headers
35
39
  f.write ''
36
40
  f.write prettied_rsp
@@ -19,7 +19,6 @@ class Net::HTTPResponse
19
19
  res.add_field k, v
20
20
  end
21
21
  res.instance_variable_set :@raw_headers, buffer.string
22
- puts 'set raw'
23
22
  res
24
23
  end
25
24
  end
@@ -1,3 +1,3 @@
1
1
  module PartyCC
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - barberj