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 +8 -8
- data/README.md +4 -1
- data/lib/party_cc/httparty.rb +10 -6
- data/lib/party_cc/net/response.rb +0 -1
- data/lib/party_cc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2YzY2E2MGM5Y2EzYWM4OGM4NzliNTc5ODE1NDU1YzVmMDUxYzA3NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2ZmYjkyYzllM2RkZjliYWJlZGJiMzlhMDc3NjEyN2IwOWVjOTM5MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWNmZjVmOTFjYjk4MzVlMDEzOThiOGU0YjI3YmZhZjA3OGE3YzI1M2I2NjQz
|
10
|
+
NmUzY2M3NjI0M2FlMWY0MmM3OTNmYzkzNGU5MTZiYTczOGE4MDc1NGM2OTg1
|
11
|
+
YzJhMjE3NDhiMjZhNmY5NGRjMzNjN2ViOTQzODUwYmQ3NzllMjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
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
|
data/lib/party_cc/httparty.rb
CHANGED
@@ -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
|
-
|
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("
|
33
|
-
File.open(
|
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
|
data/lib/party_cc/version.rb
CHANGED