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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b3d9cd5bf2c8c65e7c422ee6424b08fabde5bee
4
- data.tar.gz: c5e5164791c0c4ab0c1dca1ad1b87385b382d36a
3
+ metadata.gz: '08b40cc11bb3f226a66cc268ecc924e0c340880e'
4
+ data.tar.gz: 73c74369eefec097816a367683a353a2c37fad19
5
5
  SHA512:
6
- metadata.gz: 27268caca0723458d76464e7e510eb737feb425a9a9f2007337d9f1e12976b0bfb5c39850a5654f990fe66d1f7a4a53d2de4de80b57bfd670e470c9269c25b1f
7
- data.tar.gz: 3c7360f0232df51be5491f3c98bba7998b9321c42a5a845680be055b7929edc024a4a9fdad7aad14501ea3dba8875a5d9debfd24ba31e6a9779accf2e1935a9f
6
+ metadata.gz: e6dd1403411ae60aac6f7380dea7c6788c6a605fe76b58177803d761eb1cd4282773d19e5ea6ca590ed67d93cf64ac03868880c0d90578d9550178a3daf3c53a
7
+ data.tar.gz: aa62e154f5059e7baad7c4618e7e2c23097d34f259154b783052a42cfb77e22bba5d7012c65d6369bbb5511685f7461943adf209f2956ed45bac02c4ce1453c9
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1.8
5
- - 2.2.4
6
- - 2.3.0
7
- - 2.4.1
4
+ - 2.1.10
5
+ - 2.2.9
6
+ - 2.3.6
7
+ - 2.4.3
8
+ - 2.5.0
8
9
  bundler_args: --without development
9
10
  before_install: gem install bundler
@@ -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 |key, value|
53
- if value.respond_to?(:to_hash)
54
- stack << ["#{parent}[#{key}]", value.to_hash]
55
- elsif value.respond_to?(:to_ary)
56
- value.to_ary.each { |v| normalized_keys << normalize_keys("#{parent}[#{key}][]", v).flatten }
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}[#{key}]", value).flatten
57
+ normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten
59
58
  end
60
59
  end
61
60
  end
@@ -42,6 +42,7 @@ module HTTParty
42
42
  'application/xml' => :xml,
43
43
  'application/json' => :json,
44
44
  'application/vnd.api+json' => :json,
45
+ 'application/hal+json' => :json,
45
46
  'text/json' => :json,
46
47
  'application/javascript' => :plain,
47
48
  'text/javascript' => :plain,
@@ -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
@@ -36,7 +36,7 @@ module HTTParty
36
36
  memo += "\r\n"
37
37
  memo += "Content-Type: application/octet-stream\r\n" if file?(value)
38
38
  memo += "\r\n"
39
- memo += file?(value) ? value.read : value
39
+ memo += file?(value) ? value.read : value.to_s
40
40
  memo += "\r\n"
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  module HTTParty
2
- VERSION = "0.16.0"
2
+ VERSION = "0.16.1"
3
3
  end
@@ -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(@uri, @options).and_return(double(connection: nil))
37
- HTTParty::ConnectionAdapter.call(@uri, @options)
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(@uri, @options)).to be connection
48
+ expect(HTTParty::ConnectionAdapter.call(uri, options)).to be connection
46
49
  end
47
50
  end
48
51
 
@@ -23,6 +23,8 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do
23
23
  include Net::HTTPHeader
24
24
  def initialize
25
25
  @header = {}
26
+ @path = '/'
27
+ @method = 'GET'
26
28
  end
27
29
  end).new
28
30
  }
@@ -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
- class MyParser < HTTParty::Parser
31
- SupportedFormats = {"application/atom+xml" => :atom}
32
- end
33
- expect(MyParser.formats).to eq({"application/atom+xml" => :atom})
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
- response = @request.perform { |chunk| body += chunk }
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(HTTParty::ResponseError)
69
+ expect{ subject }.not_to raise_error
70
70
  end
71
71
  end
72
72
  end
@@ -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
- class MyParser < HTTParty::Parser
362
- SupportedFormats = {}
363
- end unless defined?(MyParser)
361
+
362
+ parser_class = Class.new(HTTParty::Parser)
363
+ parser_class::SupportedFormats = {}
364
+
364
365
  expect do
365
- @klass.parser MyParser
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.0
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-02-13 00:00:00.000000000 Z
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.8
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.