party_cc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/party_cc/httparty.rb +44 -0
- data/lib/party_cc/net/response.rb +26 -0
- data/lib/party_cc/string_buffered_i_o.rb +11 -0
- data/lib/party_cc/version.rb +1 -1
- data/lib/party_cc.rb +7 -41
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzMxNzA3NWRhYTEyZjE4ZTYwNmIyOGE1OThkYmJkNWQ1ZDg1YWE4Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGY4ODk0NzI0ODEyMDk2NzUyNWFiODY0OTgzMDkxZTI2MDg2ZGU0ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGRkYzY2OGJkMDgyY2I1M2U3Yjg0ZjhkODJmNzQyYThjOTY2YmZjNDQ5NGZh
|
10
|
+
YzAyMGYwY2ZhODQwNGI4YTcwNzM5YzU3YTU3ODkxODU2M2QxMTFlOGU0NzEx
|
11
|
+
MzUzNzZkN2Q3Njc0YzJiODYxM2Y3NDZjM2Y5ZDI4ZDcxYzdlZTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjNjMTU1M2I4NjBmNjhhZTcxMDU2YTExMmY1YzM4ZDEwZjBiMTI2MjVmYjlh
|
14
|
+
Nzg5M2M2ODdkYTlmNmM4ZGMxYjhiYjEwMjU3YzljNGRkMGIzNWRiZTg2YzQy
|
15
|
+
NzdhZGQ3ODk1NjEzYzJkNjdhYmRlZTcyYWI5MzY3MjE1ZTQyNTk=
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module HTTParty
|
2
|
+
class << self
|
3
|
+
def decode_ruby buffer
|
4
|
+
buffer.string
|
5
|
+
.gsub('=>', ': ')
|
6
|
+
.gsub('nil', 'null')
|
7
|
+
end
|
8
|
+
|
9
|
+
request_methods = ['get', 'post', 'patch', 'put', 'delete', 'head', 'options']
|
10
|
+
request_methods.each do |method|
|
11
|
+
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
12
|
+
alias_method :old_#{method}, :#{method}
|
13
|
+
|
14
|
+
def #{method} *args
|
15
|
+
rsp = old_#{method}(*args)
|
16
|
+
|
17
|
+
stmp = Time.now.to_i.to_s
|
18
|
+
path = Addressable::URI.parse(args[0])
|
19
|
+
.path.split('/').join('_').gsub(/^_/,'')
|
20
|
+
|
21
|
+
file_name = "#{method}_\#{path}_\#{stmp}.txt"
|
22
|
+
|
23
|
+
req_buffer = StringIO.new
|
24
|
+
rsp_buffer = StringIO.new
|
25
|
+
|
26
|
+
PP.pp(args, req_buffer)
|
27
|
+
PP.pp(rsp, rsp_buffer)
|
28
|
+
|
29
|
+
prettied_req = decode_ruby req_buffer
|
30
|
+
prettied_rsp = decode_ruby rsp_buffer
|
31
|
+
|
32
|
+
File.write("request_\#{file_name}", prettied_req)
|
33
|
+
File.open("response_\#{file_name}", 'w') do |f|
|
34
|
+
f.write rsp.response.instance_variable_get :@raw_headers
|
35
|
+
f.write ''
|
36
|
+
f.write prettied_rsp
|
37
|
+
end
|
38
|
+
|
39
|
+
rsp
|
40
|
+
end
|
41
|
+
EOT
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Net::HTTPResponse
|
2
|
+
class << self
|
3
|
+
alias_method :orig_read_new, :read_new
|
4
|
+
def read_new(sock)
|
5
|
+
buffer = StringBufferedIO.new
|
6
|
+
|
7
|
+
loop do
|
8
|
+
chunk = sock.readuntil("\n", true)
|
9
|
+
buffer.write chunk
|
10
|
+
break if chunk.sub(/\s+\z/, '').empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
buffer.rewind
|
14
|
+
|
15
|
+
httpv, code, msg = read_status_line(buffer)
|
16
|
+
|
17
|
+
res = response_class(code).new(httpv, code, msg)
|
18
|
+
each_response_header(buffer) do |k,v|
|
19
|
+
res.add_field k, v
|
20
|
+
end
|
21
|
+
res.instance_variable_set :@raw_headers, buffer.string
|
22
|
+
puts 'set raw'
|
23
|
+
res
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/party_cc/version.rb
CHANGED
data/lib/party_cc.rb
CHANGED
@@ -1,46 +1,12 @@
|
|
1
|
-
require "party_cc/version"
|
2
|
-
require 'httparty'
|
3
1
|
require 'addressable/uri'
|
4
2
|
require 'pp'
|
3
|
+
require 'httparty'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
.gsub('=>', ': ')
|
11
|
-
.gsub('nil', 'null')
|
12
|
-
end
|
13
|
-
|
14
|
-
request_methods = ['get', 'post', 'patch', 'put', 'delete', 'head', 'options']
|
15
|
-
request_methods.each do |method|
|
16
|
-
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
17
|
-
alias_method :old_#{method}, :#{method}
|
18
|
-
|
19
|
-
def #{method} *args
|
20
|
-
old_#{method}(*args).tap do |rsp|
|
21
|
-
|
22
|
-
stmp = Time.now.to_i.to_s
|
23
|
-
path = Addressable::URI.parse(args[0])
|
24
|
-
.path.split('/').join('_').gsub(/^_/,'')
|
25
|
-
|
26
|
-
file_name = "#{method}_\#{path}_\#{stmp}.txt"
|
27
|
-
|
28
|
-
req_buffer = StringIO.new
|
29
|
-
rsp_buffer = StringIO.new
|
30
|
-
|
31
|
-
PP.pp(args, req_buffer)
|
32
|
-
PP.pp(rsp, rsp_buffer)
|
33
|
-
|
34
|
-
prettied_req = decode_ruby req_buffer
|
35
|
-
prettied_rsp = decode_ruby rsp_buffer
|
36
|
-
|
37
|
-
File.write("request_\#{file_name}", prettied_req)
|
38
|
-
File.write("response_\#{file_name}", prettied_rsp)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
EOT
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
7
|
+
require "party_cc/version"
|
8
|
+
require 'party_cc/string_buffered_i_o'
|
9
|
+
require 'party_cc/net/response'
|
10
|
+
require 'party_cc/httparty'
|
45
11
|
|
46
12
|
module PartyCC; 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.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,9 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/party_cc.rb
|
68
|
+
- lib/party_cc/httparty.rb
|
69
|
+
- lib/party_cc/net/response.rb
|
70
|
+
- lib/party_cc/string_buffered_i_o.rb
|
68
71
|
- lib/party_cc/version.rb
|
69
72
|
- party_cc.gemspec
|
70
73
|
homepage: https://github.com/barberj/party_cc
|