rest-client 1.8.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.mailmap +10 -0
  4. data/.rspec +2 -1
  5. data/.rubocop +2 -0
  6. data/.rubocop-disables.yml +386 -0
  7. data/.rubocop.yml +8 -0
  8. data/.travis.yml +56 -8
  9. data/AUTHORS +26 -1
  10. data/README.md +901 -0
  11. data/Rakefile +27 -3
  12. data/bin/restclient +3 -5
  13. data/history.md +181 -0
  14. data/lib/restclient/abstract_response.rb +172 -55
  15. data/lib/restclient/exceptions.rb +96 -55
  16. data/lib/restclient/params_array.rb +72 -0
  17. data/lib/restclient/payload.rb +70 -74
  18. data/lib/restclient/platform.rb +19 -0
  19. data/lib/restclient/raw_response.rb +21 -7
  20. data/lib/restclient/request.rb +540 -281
  21. data/lib/restclient/resource.rb +19 -9
  22. data/lib/restclient/response.rb +75 -6
  23. data/lib/restclient/utils.rb +274 -0
  24. data/lib/restclient/version.rb +2 -1
  25. data/lib/restclient.rb +21 -3
  26. data/rest-client.gemspec +12 -10
  27. data/spec/ISS.jpg +0 -0
  28. data/spec/helpers.rb +54 -0
  29. data/spec/integration/_lib.rb +1 -0
  30. data/spec/integration/capath_digicert/3513523f.0 +22 -0
  31. data/spec/integration/capath_digicert/399e7759.0 +22 -0
  32. data/spec/integration/capath_digicert/digicert.crt +20 -17
  33. data/spec/integration/certs/digicert.crt +20 -17
  34. data/spec/integration/httpbin_spec.rb +128 -0
  35. data/spec/integration/integration_spec.rb +97 -14
  36. data/spec/integration/request_spec.rb +25 -2
  37. data/spec/spec_helper.rb +28 -1
  38. data/spec/unit/_lib.rb +1 -0
  39. data/spec/unit/abstract_response_spec.rb +95 -38
  40. data/spec/unit/exceptions_spec.rb +41 -28
  41. data/spec/unit/params_array_spec.rb +36 -0
  42. data/spec/unit/payload_spec.rb +118 -68
  43. data/spec/unit/raw_response_spec.rb +10 -6
  44. data/spec/unit/request2_spec.rb +34 -12
  45. data/spec/unit/request_spec.rb +745 -424
  46. data/spec/unit/resource_spec.rb +31 -27
  47. data/spec/unit/response_spec.rb +134 -57
  48. data/spec/unit/restclient_spec.rb +16 -15
  49. data/spec/unit/utils_spec.rb +147 -0
  50. data/spec/unit/windows/root_certs_spec.rb +3 -3
  51. metadata +79 -29
  52. data/README.rdoc +0 -324
  53. data/spec/integration/capath_digicert/244b5494.0 +0 -19
  54. data/spec/integration/capath_digicert/81b9768f.0 +0 -19
  55. data/spec/unit/master_shake.jpg +0 -0
@@ -0,0 +1,147 @@
1
+ require_relative '_lib'
2
+
3
+ describe RestClient::Utils do
4
+ describe '.get_encoding_from_headers' do
5
+ it 'assumes no encoding by default for text' do
6
+ headers = {:content_type => 'text/plain'}
7
+ expect(RestClient::Utils.get_encoding_from_headers(headers)).
8
+ to eq nil
9
+ end
10
+
11
+ it 'returns nil on failures' do
12
+ expect(RestClient::Utils.get_encoding_from_headers(
13
+ {:content_type => 'blah'})).to eq nil
14
+ expect(RestClient::Utils.get_encoding_from_headers(
15
+ {})).to eq nil
16
+ expect(RestClient::Utils.get_encoding_from_headers(
17
+ {:content_type => 'foo; bar=baz'})).to eq nil
18
+ end
19
+
20
+ it 'handles various charsets' do
21
+ expect(RestClient::Utils.get_encoding_from_headers(
22
+ {:content_type => 'text/plain; charset=UTF-8'})).to eq 'UTF-8'
23
+ expect(RestClient::Utils.get_encoding_from_headers(
24
+ {:content_type => 'application/json; charset=ISO-8859-1'})).
25
+ to eq 'ISO-8859-1'
26
+ expect(RestClient::Utils.get_encoding_from_headers(
27
+ {:content_type => 'text/html; charset=windows-1251'})).
28
+ to eq 'windows-1251'
29
+
30
+ expect(RestClient::Utils.get_encoding_from_headers(
31
+ {:content_type => 'text/html; charset="UTF-16"'})).
32
+ to eq 'UTF-16'
33
+ end
34
+ end
35
+
36
+ describe '.cgi_parse_header' do
37
+ it 'parses headers', :unless => RUBY_VERSION.start_with?('2.0') do
38
+ expect(RestClient::Utils.cgi_parse_header('text/plain')).
39
+ to eq ['text/plain', {}]
40
+
41
+ expect(RestClient::Utils.cgi_parse_header('text/vnd.just.made.this.up')).
42
+ to eq ['text/vnd.just.made.this.up', {}]
43
+
44
+ expect(RestClient::Utils.cgi_parse_header('text/plain;charset=us-ascii')).
45
+ to eq ['text/plain', {'charset' => 'us-ascii'}]
46
+
47
+ expect(RestClient::Utils.cgi_parse_header('text/plain ; charset="us-ascii"')).
48
+ to eq ['text/plain', {'charset' => 'us-ascii'}]
49
+
50
+ expect(RestClient::Utils.cgi_parse_header(
51
+ 'text/plain ; charset="us-ascii"; another=opt')).
52
+ to eq ['text/plain', {'charset' => 'us-ascii', 'another' => 'opt'}]
53
+
54
+ expect(RestClient::Utils.cgi_parse_header(
55
+ 'foo/bar; filename="silly.txt"')).
56
+ to eq ['foo/bar', {'filename' => 'silly.txt'}]
57
+
58
+ expect(RestClient::Utils.cgi_parse_header(
59
+ 'foo/bar; filename="strange;name"')).
60
+ to eq ['foo/bar', {'filename' => 'strange;name'}]
61
+
62
+ expect(RestClient::Utils.cgi_parse_header(
63
+ 'foo/bar; filename="strange;name";size=123')).to eq \
64
+ ['foo/bar', {'filename' => 'strange;name', 'size' => '123'}]
65
+
66
+ expect(RestClient::Utils.cgi_parse_header(
67
+ 'foo/bar; name="files"; filename="fo\\"o;bar"')).to eq \
68
+ ['foo/bar', {'name' => 'files', 'filename' => 'fo"o;bar'}]
69
+ end
70
+ end
71
+
72
+ describe '.encode_query_string' do
73
+ it 'handles simple hashes' do
74
+ {
75
+ {foo: 123, bar: 456} => 'foo=123&bar=456',
76
+ {'foo' => 123, 'bar' => 456} => 'foo=123&bar=456',
77
+ {foo: 'abc', bar: 'one two'} => 'foo=abc&bar=one+two',
78
+ {escaped: '1+2=3'} => 'escaped=1%2B2%3D3',
79
+ {'escaped + key' => 'foo'} => 'escaped+%2B+key=foo',
80
+ }.each_pair do |input, expected|
81
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
82
+ end
83
+ end
84
+
85
+ it 'handles simple arrays' do
86
+ {
87
+ {foo: [1, 2, 3]} => 'foo[]=1&foo[]=2&foo[]=3',
88
+ {foo: %w{a b c}, bar: [1, 2, 3]} => 'foo[]=a&foo[]=b&foo[]=c&bar[]=1&bar[]=2&bar[]=3',
89
+ {foo: ['one two', 3]} => 'foo[]=one+two&foo[]=3',
90
+ {'a+b' => [1,2,3]} => 'a%2Bb[]=1&a%2Bb[]=2&a%2Bb[]=3',
91
+ }.each_pair do |input, expected|
92
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
93
+ end
94
+ end
95
+
96
+ it 'handles nested hashes' do
97
+ {
98
+ {outer: {foo: 123, bar: 456}} => 'outer[foo]=123&outer[bar]=456',
99
+ {outer: {foo: [1, 2, 3], bar: 'baz'}} => 'outer[foo][]=1&outer[foo][]=2&outer[foo][]=3&outer[bar]=baz',
100
+ }.each_pair do |input, expected|
101
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
102
+ end
103
+ end
104
+
105
+ it 'handles null and empty values' do
106
+ {
107
+ {string: '', empty: nil, list: [], hash: {}, falsey: false } =>
108
+ 'string=&empty&list&hash&falsey=false',
109
+ }.each_pair do |input, expected|
110
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
111
+ end
112
+ end
113
+
114
+ it 'handles nested nulls' do
115
+ {
116
+ {foo: {string: '', empty: nil}} => 'foo[string]=&foo[empty]',
117
+ }.each_pair do |input, expected|
118
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
119
+ end
120
+ end
121
+
122
+ it 'handles deep nesting' do
123
+ {
124
+ {coords: [{x: 1, y: 0}, {x: 2}, {x: 3}]} => 'coords[][x]=1&coords[][y]=0&coords[][x]=2&coords[][x]=3',
125
+ }.each_pair do |input, expected|
126
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
127
+ end
128
+ end
129
+
130
+ it 'handles multiple fields with the same name using ParamsArray' do
131
+ {
132
+ RestClient::ParamsArray.new([[:foo, 1], [:foo, 2], [:foo, 3]]) => 'foo=1&foo=2&foo=3',
133
+ }.each_pair do |input, expected|
134
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
135
+ end
136
+ end
137
+
138
+ it 'handles nested ParamsArrays' do
139
+ {
140
+ {foo: RestClient::ParamsArray.new([[:a, 1], [:a, 2]])} => 'foo[a]=1&foo[a]=2',
141
+ RestClient::ParamsArray.new([[:foo, {a: 1}], [:foo, {a: 2}]]) => 'foo[a]=1&foo[a]=2',
142
+ }.each_pair do |input, expected|
143
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
144
+ end
145
+ end
146
+ end
147
+ end
@@ -1,11 +1,11 @@
1
- require 'spec_helper'
1
+ require_relative '../_lib'
2
2
 
3
3
  describe 'RestClient::Windows::RootCerts',
4
4
  :if => RestClient::Platform.windows? do
5
5
  let(:x509_store) { RestClient::Windows::RootCerts.instance.to_a }
6
6
 
7
7
  it 'should return at least one X509 certificate' do
8
- expect(x509_store.to_a).to have_at_least(1).items
8
+ expect(x509_store.to_a.size).to be >= 1
9
9
  end
10
10
 
11
11
  it 'should return an X509 certificate with a subject' do
@@ -16,7 +16,7 @@ describe 'RestClient::Windows::RootCerts',
16
16
 
17
17
  it 'should return X509 certificate objects' do
18
18
  x509_store.each do |cert|
19
- cert.should be_a(OpenSSL::X509::Certificate)
19
+ expect(cert).to be_a(OpenSSL::X509::Certificate)
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - REST Client Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webmock
@@ -16,54 +16,54 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.4'
33
+ version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.4'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-doc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: 2.4.2
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
- version: '5.0'
78
+ version: '6.0'
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,41 @@ dependencies:
85
85
  version: 2.4.2
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
- version: '5.0'
88
+ version: '6.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.49'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.49'
103
+ - !ruby/object:Gem::Dependency
104
+ name: http-accept
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 1.7.0
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '2.0'
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 1.7.0
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '2.0'
89
123
  - !ruby/object:Gem::Dependency
90
124
  name: http-cookie
91
125
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +149,7 @@ dependencies:
115
149
  version: '1.16'
116
150
  - - "<"
117
151
  - !ruby/object:Gem::Version
118
- version: '3.0'
152
+ version: '4.0'
119
153
  type: :runtime
120
154
  prerelease: false
121
155
  version_requirements: !ruby/object:Gem::Requirement
@@ -125,38 +159,42 @@ dependencies:
125
159
  version: '1.16'
126
160
  - - "<"
127
161
  - !ruby/object:Gem::Version
128
- version: '3.0'
162
+ version: '4.0'
129
163
  - !ruby/object:Gem::Dependency
130
164
  name: netrc
131
165
  requirement: !ruby/object:Gem::Requirement
132
166
  requirements:
133
167
  - - "~>"
134
168
  - !ruby/object:Gem::Version
135
- version: '0.7'
169
+ version: '0.8'
136
170
  type: :runtime
137
171
  prerelease: false
138
172
  version_requirements: !ruby/object:Gem::Requirement
139
173
  requirements:
140
174
  - - "~>"
141
175
  - !ruby/object:Gem::Version
142
- version: '0.7'
176
+ version: '0.8'
143
177
  description: 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework
144
178
  style of specifying actions: get, put, post, delete.'
145
- email: rest.client@librelist.com
179
+ email: discuss@rest-client.groups.io
146
180
  executables:
147
181
  - restclient
148
182
  extensions: []
149
183
  extra_rdoc_files:
150
- - README.rdoc
184
+ - README.md
151
185
  - history.md
152
186
  files:
153
187
  - ".gitignore"
188
+ - ".mailmap"
154
189
  - ".rspec"
190
+ - ".rubocop"
191
+ - ".rubocop-disables.yml"
192
+ - ".rubocop.yml"
155
193
  - ".travis.yml"
156
194
  - AUTHORS
157
195
  - Gemfile
158
196
  - LICENSE
159
- - README.rdoc
197
+ - README.md
160
198
  - Rakefile
161
199
  - bin/restclient
162
200
  - history.md
@@ -165,19 +203,24 @@ files:
165
203
  - lib/restclient.rb
166
204
  - lib/restclient/abstract_response.rb
167
205
  - lib/restclient/exceptions.rb
206
+ - lib/restclient/params_array.rb
168
207
  - lib/restclient/payload.rb
169
208
  - lib/restclient/platform.rb
170
209
  - lib/restclient/raw_response.rb
171
210
  - lib/restclient/request.rb
172
211
  - lib/restclient/resource.rb
173
212
  - lib/restclient/response.rb
213
+ - lib/restclient/utils.rb
174
214
  - lib/restclient/version.rb
175
215
  - lib/restclient/windows.rb
176
216
  - lib/restclient/windows/root_certs.rb
177
217
  - rest-client.gemspec
178
218
  - rest-client.windows.gemspec
179
- - spec/integration/capath_digicert/244b5494.0
180
- - spec/integration/capath_digicert/81b9768f.0
219
+ - spec/ISS.jpg
220
+ - spec/helpers.rb
221
+ - spec/integration/_lib.rb
222
+ - spec/integration/capath_digicert/3513523f.0
223
+ - spec/integration/capath_digicert/399e7759.0
181
224
  - spec/integration/capath_digicert/README
182
225
  - spec/integration/capath_digicert/digicert.crt
183
226
  - spec/integration/capath_verisign/415660c1.0
@@ -186,12 +229,14 @@ files:
186
229
  - spec/integration/capath_verisign/verisign.crt
187
230
  - spec/integration/certs/digicert.crt
188
231
  - spec/integration/certs/verisign.crt
232
+ - spec/integration/httpbin_spec.rb
189
233
  - spec/integration/integration_spec.rb
190
234
  - spec/integration/request_spec.rb
191
235
  - spec/spec_helper.rb
236
+ - spec/unit/_lib.rb
192
237
  - spec/unit/abstract_response_spec.rb
193
238
  - spec/unit/exceptions_spec.rb
194
- - spec/unit/master_shake.jpg
239
+ - spec/unit/params_array_spec.rb
195
240
  - spec/unit/payload_spec.rb
196
241
  - spec/unit/raw_response_spec.rb
197
242
  - spec/unit/request2_spec.rb
@@ -199,6 +244,7 @@ files:
199
244
  - spec/unit/resource_spec.rb
200
245
  - spec/unit/response_spec.rb
201
246
  - spec/unit/restclient_spec.rb
247
+ - spec/unit/utils_spec.rb
202
248
  - spec/unit/windows/root_certs_spec.rb
203
249
  homepage: https://github.com/rest-client/rest-client
204
250
  licenses:
@@ -212,22 +258,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
258
  requirements:
213
259
  - - ">="
214
260
  - !ruby/object:Gem::Version
215
- version: 1.9.2
261
+ version: 2.0.0
216
262
  required_rubygems_version: !ruby/object:Gem::Requirement
217
263
  requirements:
218
264
  - - ">="
219
265
  - !ruby/object:Gem::Version
220
266
  version: '0'
221
267
  requirements: []
222
- rubyforge_project:
223
- rubygems_version: 2.2.2
268
+ rubygems_version: 3.0.3
224
269
  signing_key:
225
270
  specification_version: 4
226
271
  summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
227
272
  specifying actions.
228
273
  test_files:
229
- - spec/integration/capath_digicert/244b5494.0
230
- - spec/integration/capath_digicert/81b9768f.0
274
+ - spec/ISS.jpg
275
+ - spec/helpers.rb
276
+ - spec/integration/_lib.rb
277
+ - spec/integration/capath_digicert/3513523f.0
278
+ - spec/integration/capath_digicert/399e7759.0
231
279
  - spec/integration/capath_digicert/README
232
280
  - spec/integration/capath_digicert/digicert.crt
233
281
  - spec/integration/capath_verisign/415660c1.0
@@ -236,12 +284,14 @@ test_files:
236
284
  - spec/integration/capath_verisign/verisign.crt
237
285
  - spec/integration/certs/digicert.crt
238
286
  - spec/integration/certs/verisign.crt
287
+ - spec/integration/httpbin_spec.rb
239
288
  - spec/integration/integration_spec.rb
240
289
  - spec/integration/request_spec.rb
241
290
  - spec/spec_helper.rb
291
+ - spec/unit/_lib.rb
242
292
  - spec/unit/abstract_response_spec.rb
243
293
  - spec/unit/exceptions_spec.rb
244
- - spec/unit/master_shake.jpg
294
+ - spec/unit/params_array_spec.rb
245
295
  - spec/unit/payload_spec.rb
246
296
  - spec/unit/raw_response_spec.rb
247
297
  - spec/unit/request2_spec.rb
@@ -249,5 +299,5 @@ test_files:
249
299
  - spec/unit/resource_spec.rb
250
300
  - spec/unit/response_spec.rb
251
301
  - spec/unit/restclient_spec.rb
302
+ - spec/unit/utils_spec.rb
252
303
  - spec/unit/windows/root_certs_spec.rb
253
- has_rdoc: