httparty 0.16.0 → 0.16.1
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/.travis.yml +5 -4
- data/Changelog.md +6 -0
- data/lib/httparty/hash_conversions.rb +6 -7
- data/lib/httparty/parser.rb +1 -0
- data/lib/httparty/request.rb +9 -9
- data/lib/httparty/request/body.rb +1 -1
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/connection_adapter_spec.rb +6 -3
- data/spec/httparty/net_digest_auth_spec.rb +2 -0
- data/spec/httparty/parser_spec.rb +4 -4
- data/spec/httparty/request/body_spec.rb +6 -1
- data/spec/httparty/request_spec.rb +28 -1
- data/spec/httparty/response_spec.rb +1 -1
- data/spec/httparty_spec.rb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08b40cc11bb3f226a66cc268ecc924e0c340880e'
|
4
|
+
data.tar.gz: 73c74369eefec097816a367683a353a2c37fad19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6dd1403411ae60aac6f7380dea7c6788c6a605fe76b58177803d761eb1cd4282773d19e5ea6ca590ed67d93cf64ac03868880c0d90578d9550178a3daf3c53a
|
7
|
+
data.tar.gz: aa62e154f5059e7baad7c4618e7e2c23097d34f259154b783052a42cfb77e22bba5d7012c65d6369bbb5511685f7461943adf209f2956ed45bac02c4ce1453c9
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.16.1
|
2
|
+
|
3
|
+
* [Parse content with application/hal+json content type as JSON](https://github.com/jnunemaker/httparty/pull/573)
|
4
|
+
* [Convert objects to string when concatenating in multipart stuff](https://github.com/jnunemaker/httparty/pull/575)
|
5
|
+
* [Fix multipart to set its header even when other headers are provided](https://github.com/jnunemaker/httparty/pull/576)
|
6
|
+
|
1
7
|
## 0.16.0
|
2
8
|
|
3
9
|
* [Add multipart support](https://github.com/jnunemaker/httparty/pull/569)
|
@@ -47,15 +47,14 @@ module HTTParty
|
|
47
47
|
normalized_keys << [key.to_s, value]
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
50
|
stack.each do |parent, hash|
|
52
|
-
hash.each do |
|
53
|
-
if
|
54
|
-
stack << ["#{parent}[#{
|
55
|
-
elsif
|
56
|
-
|
51
|
+
hash.each do |child_key, child_value|
|
52
|
+
if child_value.respond_to?(:to_hash)
|
53
|
+
stack << ["#{parent}[#{child_key}]", child_value.to_hash]
|
54
|
+
elsif child_value.respond_to?(:to_ary)
|
55
|
+
child_value.to_ary.each { |v| normalized_keys << normalize_keys("#{parent}[#{child_key}][]", v).flatten }
|
57
56
|
else
|
58
|
-
normalized_keys << normalize_keys("#{parent}[#{
|
57
|
+
normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
data/lib/httparty/parser.rb
CHANGED
data/lib/httparty/request.rb
CHANGED
@@ -205,15 +205,6 @@ module HTTParty
|
|
205
205
|
@raw_request = http_method.new(request_uri(uri))
|
206
206
|
@raw_request.body_stream = options[:body_stream] if options[:body_stream]
|
207
207
|
|
208
|
-
if options[:body]
|
209
|
-
body = Body.new(options[:body], query_string_normalizer: query_string_normalizer)
|
210
|
-
if body.multipart?
|
211
|
-
content_type = "multipart/form-data; boundary=#{body.boundary}"
|
212
|
-
@raw_request.initialize_http_header('Content-Type' => content_type)
|
213
|
-
end
|
214
|
-
@raw_request.body = body.call
|
215
|
-
end
|
216
|
-
|
217
208
|
if options[:headers].respond_to?(:to_hash)
|
218
209
|
headers_hash = options[:headers].to_hash
|
219
210
|
|
@@ -227,6 +218,15 @@ module HTTParty
|
|
227
218
|
end
|
228
219
|
end
|
229
220
|
|
221
|
+
if options[:body]
|
222
|
+
body = Body.new(options[:body], query_string_normalizer: query_string_normalizer)
|
223
|
+
if body.multipart?
|
224
|
+
content_type = "multipart/form-data; boundary=#{body.boundary}"
|
225
|
+
@raw_request['Content-Type'] = content_type
|
226
|
+
end
|
227
|
+
@raw_request.body = body.call
|
228
|
+
end
|
229
|
+
|
230
230
|
if options[:basic_auth] && send_authorization_header?
|
231
231
|
@raw_request.basic_auth(username, password)
|
232
232
|
@credentials_sent = true
|
data/lib/httparty/version.rb
CHANGED
@@ -32,9 +32,12 @@ RSpec.describe HTTParty::ConnectionAdapter do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe ".call" do
|
35
|
+
let(:uri) { URI 'http://www.google.com' }
|
36
|
+
let(:options) { { foo: :bar } }
|
37
|
+
|
35
38
|
it "generates an HTTParty::ConnectionAdapter instance with the given uri and options" do
|
36
|
-
expect(HTTParty::ConnectionAdapter).to receive(:new).with(
|
37
|
-
HTTParty::ConnectionAdapter.call(
|
39
|
+
expect(HTTParty::ConnectionAdapter).to receive(:new).with(uri, options).and_return(double(connection: nil))
|
40
|
+
HTTParty::ConnectionAdapter.call(uri, options)
|
38
41
|
end
|
39
42
|
|
40
43
|
it "calls #connection on the connection adapter" do
|
@@ -42,7 +45,7 @@ RSpec.describe HTTParty::ConnectionAdapter do
|
|
42
45
|
connection = double('Connection')
|
43
46
|
expect(adapter).to receive(:connection).and_return(connection)
|
44
47
|
allow(HTTParty::ConnectionAdapter).to receive_messages(new: adapter)
|
45
|
-
expect(HTTParty::ConnectionAdapter.call(
|
48
|
+
expect(HTTParty::ConnectionAdapter.call(uri, options)).to be connection
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -27,10 +27,10 @@ RSpec.describe HTTParty::Parser do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns the SupportedFormats constant for subclasses" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
expect(
|
30
|
+
klass = Class.new(HTTParty::Parser)
|
31
|
+
klass::SupportedFormats = { "application/atom+xml" => :atom }
|
32
|
+
|
33
|
+
expect(klass.formats).to eq({"application/atom+xml" => :atom})
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -27,7 +27,8 @@ RSpec.describe HTTParty::Request::Body do
|
|
27
27
|
user: {
|
28
28
|
avatar: File.open('spec/fixtures/tiny.gif'),
|
29
29
|
first_name: 'John',
|
30
|
-
last_name: 'Doe'
|
30
|
+
last_name: 'Doe',
|
31
|
+
enabled: true
|
31
32
|
}
|
32
33
|
}
|
33
34
|
end
|
@@ -45,6 +46,10 @@ RSpec.describe HTTParty::Request::Body do
|
|
45
46
|
"Content-Disposition: form-data; name=\"user[last_name]\"\r\n" \
|
46
47
|
"\r\n" \
|
47
48
|
"Doe\r\n" \
|
49
|
+
"--------------------------c772861a5109d5ef\r\n" \
|
50
|
+
"Content-Disposition: form-data; name=\"user[enabled]\"\r\n" \
|
51
|
+
"\r\n" \
|
52
|
+
"true\r\n" \
|
48
53
|
"--------------------------c772861a5109d5ef--\r\n"
|
49
54
|
end
|
50
55
|
|
@@ -342,6 +342,27 @@ RSpec.describe HTTParty::Request do
|
|
342
342
|
expect(CGI.unescape(body)).to eq("foo=bar&foo=baz&page=1")
|
343
343
|
end
|
344
344
|
end
|
345
|
+
|
346
|
+
context "when body is multipart" do
|
347
|
+
it "sets header Content-Type: multipart/form-data; boundary=" do
|
348
|
+
@request.options[:body] = {file: File.open(File::NULL, 'r')}
|
349
|
+
@request.send(:setup_raw_request)
|
350
|
+
headers = @request.instance_variable_get(:@raw_request).each_header.to_a
|
351
|
+
headers = Hash[*headers.flatten] # Ruby 2.0 doesn't have Array#to_h
|
352
|
+
expect(headers['content-type']).to match(%r{^multipart/form-data; boundary=---})
|
353
|
+
end
|
354
|
+
|
355
|
+
context "and header Content-Type is provided" do
|
356
|
+
it "overwrites the header to: multipart/form-data; boundary=" do
|
357
|
+
@request.options[:body] = {file: File.open(File::NULL, 'r')}
|
358
|
+
@request.options[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
359
|
+
@request.send(:setup_raw_request)
|
360
|
+
headers = @request.instance_variable_get(:@raw_request).each_header.to_a
|
361
|
+
headers = Hash[*headers.flatten] # Ruby 2.0 doesn't have Array#to_h
|
362
|
+
expect(headers['content-type']).to match(%r{^multipart/form-data; boundary=---})
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
345
366
|
end
|
346
367
|
|
347
368
|
describe 'http' do
|
@@ -379,6 +400,12 @@ RSpec.describe HTTParty::Request do
|
|
379
400
|
end
|
380
401
|
end
|
381
402
|
|
403
|
+
it 'should handle application/hal+json' do
|
404
|
+
["application/hal+json", "application/hal+json; charset=iso8859-1"].each do |ct|
|
405
|
+
expect(@request.send(:format_from_mimetype, ct)).to eq(:json)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
382
409
|
it 'should handle application/json' do
|
383
410
|
["application/json", "application/json; charset=iso8859-1"].each do |ct|
|
384
411
|
expect(@request.send(:format_from_mimetype, ct)).to eq(:json)
|
@@ -585,7 +612,7 @@ RSpec.describe HTTParty::Request do
|
|
585
612
|
stub_request(:get, 'http://api.foo.com/v2')
|
586
613
|
.to_return(body: '<hash><foo>bar</foo></hash>')
|
587
614
|
body = ""
|
588
|
-
|
615
|
+
@request.perform { |chunk| body += chunk }
|
589
616
|
expect(body.length).to eq(27)
|
590
617
|
end
|
591
618
|
|
@@ -66,7 +66,7 @@ RSpec.describe HTTParty::Response do
|
|
66
66
|
subject { described_class.new(request, @response_object, @parsed_response) }
|
67
67
|
|
68
68
|
it 'does not throw exception' do
|
69
|
-
expect{ subject }.not_to raise_error
|
69
|
+
expect{ subject }.not_to raise_error
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
data/spec/httparty_spec.rb
CHANGED
@@ -358,11 +358,12 @@ RSpec.describe HTTParty do
|
|
358
358
|
|
359
359
|
it "raises UnsupportedFormat when the parser cannot handle the format" do
|
360
360
|
@klass.format :json
|
361
|
-
|
362
|
-
|
363
|
-
|
361
|
+
|
362
|
+
parser_class = Class.new(HTTParty::Parser)
|
363
|
+
parser_class::SupportedFormats = {}
|
364
|
+
|
364
365
|
expect do
|
365
|
-
@klass.parser
|
366
|
+
@klass.parser parser_class
|
366
367
|
end.to raise_error(HTTParty::UnsupportedFormat)
|
367
368
|
end
|
368
369
|
|
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.16.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_xml
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.6.
|
157
|
+
rubygems_version: 2.6.14
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|