httparty 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +92 -0
- data/.rubocop_todo.yml +124 -0
- data/.simplecov +1 -0
- data/.travis.yml +4 -2
- data/CONTRIBUTING.md +23 -0
- data/Gemfile +8 -3
- data/Guardfile +3 -3
- data/History +106 -11
- data/README.md +19 -20
- data/Rakefile +5 -7
- data/bin/httparty +18 -14
- data/docs/README.md +100 -0
- data/examples/README.md +67 -0
- data/examples/aaws.rb +5 -5
- data/examples/basic.rb +6 -10
- data/examples/crack.rb +2 -2
- data/examples/custom_parsers.rb +1 -4
- data/examples/delicious.rb +8 -8
- data/examples/google.rb +2 -2
- data/examples/headers_and_user_agents.rb +1 -1
- data/examples/logging.rb +36 -0
- data/examples/nokogiri_html_parser.rb +0 -3
- data/examples/rescue_json.rb +17 -0
- data/examples/rubyurl.rb +3 -3
- data/examples/stackexchange.rb +24 -0
- data/examples/tripit_sign_in.rb +20 -9
- data/examples/twitter.rb +7 -7
- data/examples/whoismyrep.rb +1 -1
- data/features/command_line.feature +90 -2
- data/features/digest_authentication.feature +10 -0
- data/features/steps/env.rb +16 -11
- data/features/steps/httparty_response_steps.rb +18 -14
- data/features/steps/httparty_steps.rb +10 -2
- data/features/steps/mongrel_helper.rb +35 -2
- data/features/steps/remote_service_steps.rb +26 -8
- data/features/supports_read_timeout_option.feature +13 -0
- data/httparty.gemspec +6 -5
- data/lib/httparty/connection_adapter.rb +36 -13
- data/lib/httparty/cookie_hash.rb +3 -4
- data/lib/httparty/exceptions.rb +4 -1
- data/lib/httparty/hash_conversions.rb +17 -15
- data/lib/httparty/logger/{apache_logger.rb → apache_formatter.rb} +3 -3
- data/lib/httparty/logger/curl_formatter.rb +91 -0
- data/lib/httparty/logger/logger.rb +18 -10
- data/lib/httparty/module_inheritable_attributes.rb +1 -1
- data/lib/httparty/net_digest_auth.rb +69 -18
- data/lib/httparty/parser.rb +4 -2
- data/lib/httparty/request.rb +105 -48
- data/lib/httparty/response.rb +31 -6
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +132 -72
- data/spec/httparty/connection_adapter_spec.rb +285 -88
- data/spec/httparty/cookie_hash_spec.rb +46 -29
- data/spec/httparty/exception_spec.rb +29 -7
- data/spec/httparty/hash_conversions_spec.rb +49 -0
- data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
- data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
- data/spec/httparty/logger/logger_spec.rb +23 -7
- data/spec/httparty/net_digest_auth_spec.rb +118 -30
- data/spec/httparty/parser_spec.rb +43 -35
- data/spec/httparty/request_spec.rb +734 -182
- data/spec/httparty/response_spec.rb +139 -69
- data/spec/httparty/ssl_spec.rb +22 -22
- data/spec/httparty_spec.rb +307 -199
- data/spec/spec_helper.rb +34 -12
- data/spec/support/ssl_test_helper.rb +6 -6
- data/spec/support/ssl_test_server.rb +21 -21
- data/spec/support/stub_response.rb +20 -14
- data/website/index.html +3 -3
- metadata +30 -33
- data/lib/httparty/core_extensions.rb +0 -32
- data/lib/httparty/logger/curl_logger.rb +0 -48
- data/spec/httparty/logger/apache_logger_spec.rb +0 -26
- data/spec/httparty/logger/curl_logger_spec.rb +0 -18
- data/spec/spec.opts +0 -2
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start
|
2
3
|
|
3
4
|
require "httparty"
|
4
|
-
|
5
|
-
require 'spec/autorun'
|
6
|
-
require 'fakeweb'
|
5
|
+
require "fakeweb"
|
7
6
|
|
8
7
|
def file_fixture(filename)
|
9
|
-
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename
|
8
|
+
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
|
10
9
|
end
|
11
10
|
|
12
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
11
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each {|f| require f}
|
13
12
|
|
14
|
-
|
13
|
+
RSpec.configure do |config|
|
15
14
|
config.include HTTParty::StubResponse
|
16
15
|
config.include HTTParty::SSLTestHelper
|
17
16
|
|
@@ -22,15 +21,38 @@ Spec::Runner.configure do |config|
|
|
22
21
|
config.after(:suite) do
|
23
22
|
FakeWeb.allow_net_connect = true
|
24
23
|
end
|
25
|
-
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
config.expect_with :rspec do |expectations|
|
26
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
27
|
+
end
|
28
|
+
|
29
|
+
config.mock_with :rspec do |mocks|
|
30
|
+
mocks.verify_partial_doubles = false
|
30
31
|
end
|
32
|
+
|
33
|
+
config.filter_run :focus
|
34
|
+
config.run_all_when_everything_filtered = true
|
35
|
+
|
36
|
+
config.disable_monkey_patching!
|
37
|
+
|
38
|
+
config.warnings = true
|
39
|
+
|
40
|
+
if config.files_to_run.one?
|
41
|
+
config.default_formatter = 'doc'
|
42
|
+
end
|
43
|
+
|
44
|
+
config.profile_examples = 10
|
45
|
+
|
46
|
+
config.order = :random
|
47
|
+
|
48
|
+
Kernel.srand config.seed
|
49
|
+
end
|
50
|
+
|
51
|
+
RSpec::Matchers.define :use_ssl do
|
52
|
+
match(&:use_ssl?)
|
31
53
|
end
|
32
54
|
|
33
|
-
|
55
|
+
RSpec::Matchers.define :use_cert_store do |cert_store|
|
34
56
|
match do |connection|
|
35
57
|
connection.cert_store == cert_store
|
36
58
|
end
|
@@ -4,8 +4,8 @@ module HTTParty
|
|
4
4
|
module SSLTestHelper
|
5
5
|
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
|
6
6
|
options = {
|
7
|
-
:
|
8
|
-
:
|
7
|
+
format: :json,
|
8
|
+
timeout: 30
|
9
9
|
}.merge(options)
|
10
10
|
|
11
11
|
if mode
|
@@ -16,8 +16,8 @@ module HTTParty
|
|
16
16
|
|
17
17
|
begin
|
18
18
|
test_server = SSLTestServer.new(
|
19
|
-
:
|
20
|
-
:
|
19
|
+
rsa_key: File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
|
20
|
+
cert: File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
|
21
21
|
|
22
22
|
test_server.start
|
23
23
|
|
@@ -33,8 +33,8 @@ module HTTParty
|
|
33
33
|
end
|
34
34
|
|
35
35
|
test_server = SSLTestServer.new({
|
36
|
-
:
|
37
|
-
:
|
36
|
+
rsa_key: path.join('server.key').read,
|
37
|
+
cert: path.join(server_cert_filename).read
|
38
38
|
})
|
39
39
|
|
40
40
|
test_server.start
|
@@ -9,7 +9,7 @@ class SSLTestServer
|
|
9
9
|
attr_accessor :ctx # SSLContext object
|
10
10
|
attr_reader :port
|
11
11
|
|
12
|
-
def initialize(options={})
|
12
|
+
def initialize(options = {})
|
13
13
|
@ctx = OpenSSL::SSL::SSLContext.new
|
14
14
|
@ctx.cert = OpenSSL::X509::Certificate.new(options[:cert])
|
15
15
|
@ctx.key = OpenSSL::PKey::RSA.new(options[:rsa_key])
|
@@ -24,21 +24,21 @@ class SSLTestServer
|
|
24
24
|
@raw_server = TCPServer.new(@port)
|
25
25
|
|
26
26
|
if @port == 0
|
27
|
-
@port = Socket
|
27
|
+
@port = Socket.getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)[1].to_i
|
28
28
|
end
|
29
29
|
|
30
30
|
@ssl_server = OpenSSL::SSL::SSLServer.new(@raw_server, @ctx)
|
31
31
|
|
32
|
-
@stopping_mutex.synchronize{
|
32
|
+
@stopping_mutex.synchronize {
|
33
33
|
return if @stopping
|
34
|
-
@thread = Thread.new{ thread_main }
|
34
|
+
@thread = Thread.new { thread_main }
|
35
35
|
}
|
36
36
|
|
37
37
|
nil
|
38
38
|
end
|
39
39
|
|
40
40
|
def stop
|
41
|
-
@stopping_mutex.synchronize{
|
41
|
+
@stopping_mutex.synchronize {
|
42
42
|
return if @stopping
|
43
43
|
@stopping = true
|
44
44
|
}
|
@@ -47,22 +47,22 @@ class SSLTestServer
|
|
47
47
|
|
48
48
|
private
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
def thread_main
|
51
|
+
until @stopping_mutex.synchronize { @stopping }
|
52
|
+
(rr, _, _) = select([@ssl_server.to_io], nil, nil, 0.1)
|
53
53
|
|
54
|
-
|
54
|
+
next unless rr && rr.include?(@ssl_server.to_io)
|
55
55
|
|
56
|
-
|
56
|
+
socket = @ssl_server.accept
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
Thread.new {
|
59
|
+
header = []
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
until (line = socket.readline).rstrip.empty?
|
62
|
+
header << line
|
63
|
+
end
|
64
64
|
|
65
|
-
|
65
|
+
response = <<EOF
|
66
66
|
HTTP/1.1 200 OK
|
67
67
|
Connection: close
|
68
68
|
Content-Type: application/json; charset=UTF-8
|
@@ -70,11 +70,11 @@ Content-Type: application/json; charset=UTF-8
|
|
70
70
|
{"success":true}
|
71
71
|
EOF
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
socket.write(response.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n"))
|
74
|
+
socket.close
|
75
75
|
}
|
76
|
-
end
|
77
|
-
|
78
|
-
@ssl_server.close
|
79
76
|
end
|
77
|
+
|
78
|
+
@ssl_server.close
|
79
|
+
end
|
80
80
|
end
|
@@ -5,38 +5,44 @@ module HTTParty
|
|
5
5
|
data = file_fixture(filename)
|
6
6
|
|
7
7
|
response = Net::HTTPOK.new("1.1", 200, "Content for you")
|
8
|
-
response.
|
8
|
+
allow(response).to receive(:body).and_return(data)
|
9
9
|
|
10
|
-
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :
|
11
|
-
http_request.
|
10
|
+
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', format: format)
|
11
|
+
allow(http_request).to receive_message_chain(:http, :request).and_return(response)
|
12
12
|
|
13
|
-
HTTParty::Request.
|
13
|
+
expect(HTTParty::Request).to receive(:new).and_return(http_request)
|
14
14
|
end
|
15
15
|
|
16
|
-
def stub_chunked_http_response_with(chunks)
|
16
|
+
def stub_chunked_http_response_with(chunks, options = {format: "html"})
|
17
17
|
response = Net::HTTPResponse.new("1.1", 200, nil)
|
18
|
-
response.
|
18
|
+
allow(response).to receive(:chunked_data).and_return(chunks)
|
19
19
|
def response.read_body(&block)
|
20
20
|
@body || chunked_data.each(&block)
|
21
21
|
end
|
22
22
|
|
23
|
-
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost',
|
24
|
-
http_request.
|
23
|
+
http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', options)
|
24
|
+
allow(http_request).to receive_message_chain(:http, :request).and_yield(response).and_return(response)
|
25
25
|
|
26
|
-
HTTParty::Request.
|
26
|
+
expect(HTTParty::Request).to receive(:new).and_return(http_request)
|
27
27
|
end
|
28
28
|
|
29
|
-
def stub_response(body, code = 200)
|
29
|
+
def stub_response(body, code = '200')
|
30
|
+
code = code.to_s
|
30
31
|
@request.options[:base_uri] ||= 'http://localhost'
|
31
32
|
unless defined?(@http) && @http
|
32
33
|
@http = Net::HTTP.new('localhost', 80)
|
33
|
-
@request.
|
34
|
+
allow(@request).to receive(:http).and_return(@http)
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
# CODE_TO_OBJ currently missing 308
|
38
|
+
if code == '308'
|
39
|
+
response = Net::HTTPRedirection.new("1.1", code, body)
|
40
|
+
else
|
41
|
+
response = Net::HTTPResponse::CODE_TO_OBJ[code].new("1.1", code, body)
|
42
|
+
end
|
43
|
+
allow(response).to receive(:body).and_return(body)
|
38
44
|
|
39
|
-
@http.
|
45
|
+
allow(@http).to receive(:request).and_return(response)
|
40
46
|
response
|
41
47
|
end
|
42
48
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
basic_auth 'username', 'password'
|
34
34
|
end
|
35
35
|
|
36
|
-
Twitter.post('/statuses/update.json', :
|
36
|
+
Twitter.post('/statuses/update.json', query: {status: "It's an HTTParty and everyone is invited!"})</code></pre>
|
37
37
|
|
38
38
|
<p>That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used because of the .json extension in the path of the request. You can also explicitly set a format (see the examples). </p>
|
39
39
|
|
@@ -44,11 +44,11 @@ Twitter.post('/statuses/update.json', :query => {:status => "It's an HTTParty an
|
|
44
44
|
base_uri 'twitter.com'
|
45
45
|
|
46
46
|
def initialize(u, p)
|
47
|
-
@auth = {:
|
47
|
+
@auth = {username: u, password: p}
|
48
48
|
end
|
49
49
|
|
50
50
|
def post(text)
|
51
|
-
options = { :
|
51
|
+
options = { query: {status: text}, basic_auth: @auth }
|
52
52
|
self.class.post('/statuses/update.json', options)
|
53
53
|
end
|
54
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,34 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: json
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.8'
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.8'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: multi_xml
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
|
-
- -
|
18
|
+
- - ">="
|
33
19
|
- !ruby/object:Gem::Version
|
34
20
|
version: 0.5.2
|
35
21
|
type: :runtime
|
36
22
|
prerelease: false
|
37
23
|
version_requirements: !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
|
-
- -
|
25
|
+
- - ">="
|
40
26
|
- !ruby/object:Gem::Version
|
41
27
|
version: 0.5.2
|
42
28
|
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
@@ -47,8 +33,12 @@ executables:
|
|
47
33
|
extensions: []
|
48
34
|
extra_rdoc_files: []
|
49
35
|
files:
|
50
|
-
- .gitignore
|
51
|
-
- .
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- ".rubocop_todo.yml"
|
39
|
+
- ".simplecov"
|
40
|
+
- ".travis.yml"
|
41
|
+
- CONTRIBUTING.md
|
52
42
|
- Gemfile
|
53
43
|
- Guardfile
|
54
44
|
- History
|
@@ -57,6 +47,8 @@ files:
|
|
57
47
|
- Rakefile
|
58
48
|
- bin/httparty
|
59
49
|
- cucumber.yml
|
50
|
+
- docs/README.md
|
51
|
+
- examples/README.md
|
60
52
|
- examples/aaws.rb
|
61
53
|
- examples/basic.rb
|
62
54
|
- examples/crack.rb
|
@@ -64,8 +56,11 @@ files:
|
|
64
56
|
- examples/delicious.rb
|
65
57
|
- examples/google.rb
|
66
58
|
- examples/headers_and_user_agents.rb
|
59
|
+
- examples/logging.rb
|
67
60
|
- examples/nokogiri_html_parser.rb
|
61
|
+
- examples/rescue_json.rb
|
68
62
|
- examples/rubyurl.rb
|
63
|
+
- examples/stackexchange.rb
|
69
64
|
- examples/tripit_sign_in.rb
|
70
65
|
- examples/twitter.rb
|
71
66
|
- examples/whoismyrep.rb
|
@@ -80,17 +75,17 @@ files:
|
|
80
75
|
- features/steps/httparty_steps.rb
|
81
76
|
- features/steps/mongrel_helper.rb
|
82
77
|
- features/steps/remote_service_steps.rb
|
78
|
+
- features/supports_read_timeout_option.feature
|
83
79
|
- features/supports_redirection.feature
|
84
80
|
- features/supports_timeout_option.feature
|
85
81
|
- httparty.gemspec
|
86
82
|
- lib/httparty.rb
|
87
83
|
- lib/httparty/connection_adapter.rb
|
88
84
|
- lib/httparty/cookie_hash.rb
|
89
|
-
- lib/httparty/core_extensions.rb
|
90
85
|
- lib/httparty/exceptions.rb
|
91
86
|
- lib/httparty/hash_conversions.rb
|
92
|
-
- lib/httparty/logger/
|
93
|
-
- lib/httparty/logger/
|
87
|
+
- lib/httparty/logger/apache_formatter.rb
|
88
|
+
- lib/httparty/logger/curl_formatter.rb
|
94
89
|
- lib/httparty/logger/logger.rb
|
95
90
|
- lib/httparty/module_inheritable_attributes.rb
|
96
91
|
- lib/httparty/net_digest_auth.rb
|
@@ -119,8 +114,9 @@ files:
|
|
119
114
|
- spec/httparty/connection_adapter_spec.rb
|
120
115
|
- spec/httparty/cookie_hash_spec.rb
|
121
116
|
- spec/httparty/exception_spec.rb
|
122
|
-
- spec/httparty/
|
123
|
-
- spec/httparty/logger/
|
117
|
+
- spec/httparty/hash_conversions_spec.rb
|
118
|
+
- spec/httparty/logger/apache_formatter_spec.rb
|
119
|
+
- spec/httparty/logger/curl_formatter_spec.rb
|
124
120
|
- spec/httparty/logger/logger_spec.rb
|
125
121
|
- spec/httparty/net_digest_auth_spec.rb
|
126
122
|
- spec/httparty/parser_spec.rb
|
@@ -128,7 +124,6 @@ files:
|
|
128
124
|
- spec/httparty/response_spec.rb
|
129
125
|
- spec/httparty/ssl_spec.rb
|
130
126
|
- spec/httparty_spec.rb
|
131
|
-
- spec/spec.opts
|
132
127
|
- spec/spec_helper.rb
|
133
128
|
- spec/support/ssl_test_helper.rb
|
134
129
|
- spec/support/ssl_test_server.rb
|
@@ -136,7 +131,8 @@ files:
|
|
136
131
|
- website/css/common.css
|
137
132
|
- website/index.html
|
138
133
|
homepage: http://jnunemaker.github.com/httparty
|
139
|
-
licenses:
|
134
|
+
licenses:
|
135
|
+
- MIT
|
140
136
|
metadata: {}
|
141
137
|
post_install_message: When you HTTParty, you must party hard!
|
142
138
|
rdoc_options: []
|
@@ -144,17 +140,17 @@ require_paths:
|
|
144
140
|
- lib
|
145
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
142
|
requirements:
|
147
|
-
- -
|
143
|
+
- - ">="
|
148
144
|
- !ruby/object:Gem::Version
|
149
145
|
version: 1.9.3
|
150
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
147
|
requirements:
|
152
|
-
- -
|
148
|
+
- - ">="
|
153
149
|
- !ruby/object:Gem::Version
|
154
150
|
version: '0'
|
155
151
|
requirements: []
|
156
152
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.4.5.1
|
158
154
|
signing_key:
|
159
155
|
specification_version: 4
|
160
156
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|
@@ -170,6 +166,7 @@ test_files:
|
|
170
166
|
- features/steps/httparty_steps.rb
|
171
167
|
- features/steps/mongrel_helper.rb
|
172
168
|
- features/steps/remote_service_steps.rb
|
169
|
+
- features/supports_read_timeout_option.feature
|
173
170
|
- features/supports_redirection.feature
|
174
171
|
- features/supports_timeout_option.feature
|
175
172
|
- spec/fixtures/delicious.xml
|
@@ -191,8 +188,9 @@ test_files:
|
|
191
188
|
- spec/httparty/connection_adapter_spec.rb
|
192
189
|
- spec/httparty/cookie_hash_spec.rb
|
193
190
|
- spec/httparty/exception_spec.rb
|
194
|
-
- spec/httparty/
|
195
|
-
- spec/httparty/logger/
|
191
|
+
- spec/httparty/hash_conversions_spec.rb
|
192
|
+
- spec/httparty/logger/apache_formatter_spec.rb
|
193
|
+
- spec/httparty/logger/curl_formatter_spec.rb
|
196
194
|
- spec/httparty/logger/logger_spec.rb
|
197
195
|
- spec/httparty/net_digest_auth_spec.rb
|
198
196
|
- spec/httparty/parser_spec.rb
|
@@ -200,7 +198,6 @@ test_files:
|
|
200
198
|
- spec/httparty/response_spec.rb
|
201
199
|
- spec/httparty/ssl_spec.rb
|
202
200
|
- spec/httparty_spec.rb
|
203
|
-
- spec/spec.opts
|
204
201
|
- spec/spec_helper.rb
|
205
202
|
- spec/support/ssl_test_helper.rb
|
206
203
|
- spec/support/ssl_test_server.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module HTTParty
|
2
|
-
if defined?(::BasicObject)
|
3
|
-
BasicObject = ::BasicObject #:nodoc:
|
4
|
-
else
|
5
|
-
class BasicObject #:nodoc:
|
6
|
-
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval/ }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
unless defined?(Net::HTTP::Patch)
|
11
|
-
class Net::HTTP
|
12
|
-
def patch(path, data, initheader = nil, dest = nil, &block) #:nodoc:
|
13
|
-
res = nil
|
14
|
-
request(Patch.new(path, initheader), data) {|r|
|
15
|
-
r.read_body dest, &block
|
16
|
-
res = r
|
17
|
-
}
|
18
|
-
unless @newimpl
|
19
|
-
res.value
|
20
|
-
return res, res.body
|
21
|
-
end
|
22
|
-
res
|
23
|
-
end
|
24
|
-
|
25
|
-
class Patch < Net::HTTPRequest
|
26
|
-
METHOD = 'PATCH'
|
27
|
-
REQUEST_HAS_BODY = true
|
28
|
-
RESPONSE_HAS_BODY = true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module HTTParty
|
2
|
-
module Logger
|
3
|
-
class CurlLogger #:nodoc:
|
4
|
-
TAG_NAME = HTTParty.name
|
5
|
-
OUT = ">"
|
6
|
-
IN = "<"
|
7
|
-
|
8
|
-
attr_accessor :level, :logger, :current_time
|
9
|
-
|
10
|
-
def initialize(logger, level)
|
11
|
-
@logger = logger
|
12
|
-
@level = level.to_sym
|
13
|
-
end
|
14
|
-
|
15
|
-
def format(request, response)
|
16
|
-
messages = []
|
17
|
-
time = Time.now.strftime("%Y-%m-%d %H:%M:%S %z")
|
18
|
-
http_method = request.http_method.name.split("::").last.upcase
|
19
|
-
path = request.path.to_s
|
20
|
-
|
21
|
-
messages << print(time, OUT, "#{http_method} #{path}")
|
22
|
-
|
23
|
-
if request.options[:headers] && request.options[:headers].size > 0
|
24
|
-
request.options[:headers].each do |k, v|
|
25
|
-
messages << print(time, OUT, "#{k}: #{v}")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
messages << print(time, OUT, request.raw_body)
|
30
|
-
messages << print(time, OUT, "")
|
31
|
-
messages << print(time, IN, "HTTP/#{response.http_version} #{response.code}")
|
32
|
-
|
33
|
-
headers = response.respond_to?(:headers) ? response.headers : response
|
34
|
-
response.each_header do |response_header|
|
35
|
-
messages << print(time, IN, "#{response_header.capitalize}: #{headers[response_header]}")
|
36
|
-
end
|
37
|
-
|
38
|
-
messages << print(time, IN, "\n#{response.body}")
|
39
|
-
|
40
|
-
@logger.send @level, messages.join("\n")
|
41
|
-
end
|
42
|
-
|
43
|
-
def print(time, direction, line)
|
44
|
-
"[#{TAG_NAME}] [#{time}] #{direction} #{line}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe HTTParty::Logger::ApacheLogger do
|
4
|
-
describe "#format" do
|
5
|
-
it "formats a response in a style that resembles apache's access log" do
|
6
|
-
request_time = Time.new.strftime("%Y-%m-%d %H:%M:%S %z")
|
7
|
-
log_message = "[HTTParty] [#{request_time}] 302 \"GET http://my.domain.com/my_path\" - "
|
8
|
-
|
9
|
-
request_double = double(
|
10
|
-
:http_method => Net::HTTP::Get,
|
11
|
-
:path => "http://my.domain.com/my_path"
|
12
|
-
)
|
13
|
-
response_double = double(
|
14
|
-
:code => 302,
|
15
|
-
:[] => nil
|
16
|
-
)
|
17
|
-
|
18
|
-
logger_double = double
|
19
|
-
logger_double.should_receive(:info).with(log_message)
|
20
|
-
|
21
|
-
subject = described_class.new(logger_double, :info)
|
22
|
-
subject.current_time = request_time
|
23
|
-
subject.format(request_double, response_double)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe HTTParty::Logger::CurlLogger do
|
4
|
-
describe "#format" do
|
5
|
-
it "formats a response in a style that resembles a -v curl" do
|
6
|
-
logger_double = double
|
7
|
-
logger_double.should_receive(:info).with(
|
8
|
-
/\[HTTParty\] \[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\ [+-]\d{4}\] > GET http:\/\/localhost/)
|
9
|
-
|
10
|
-
subject = described_class.new(logger_double, :info)
|
11
|
-
|
12
|
-
stub_http_response_with("google.html")
|
13
|
-
|
14
|
-
response = HTTParty::Request.new.perform
|
15
|
-
subject.format(response.request, response)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/spec.opts
DELETED