rest-client 2.0.2 → 2.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.mailmap +10 -0
- data/.rubocop +2 -0
- data/.rubocop-disables.yml +27 -24
- data/.rubocop.yml +5 -0
- data/.travis.yml +2 -1
- data/AUTHORS +8 -0
- data/README.md +119 -7
- data/Rakefile +12 -4
- data/history.md +33 -0
- data/lib/restclient.rb +0 -1
- data/lib/restclient/abstract_response.rb +28 -2
- data/lib/restclient/exceptions.rb +3 -3
- data/lib/restclient/payload.rb +28 -3
- data/lib/restclient/raw_response.rb +17 -6
- data/lib/restclient/request.rb +89 -67
- data/lib/restclient/resource.rb +16 -6
- data/lib/restclient/response.rb +14 -4
- data/lib/restclient/utils.rb +47 -8
- data/lib/restclient/version.rb +2 -2
- data/rest-client.gemspec +1 -0
- data/spec/ISS.jpg +0 -0
- data/spec/helpers.rb +37 -5
- data/spec/integration/httpbin_spec.rb +41 -0
- data/spec/integration/integration_spec.rb +0 -7
- data/spec/unit/abstract_response_spec.rb +7 -7
- data/spec/unit/payload_spec.rb +51 -19
- data/spec/unit/raw_response_spec.rb +6 -2
- data/spec/unit/request2_spec.rb +8 -8
- data/spec/unit/request_spec.rb +51 -63
- data/spec/unit/resource_spec.rb +7 -7
- data/spec/unit/response_spec.rb +33 -22
- data/spec/unit/restclient_spec.rb +3 -2
- data/spec/unit/utils_spec.rb +10 -10
- metadata +29 -7
- data/spec/unit/master_shake.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be555e32d656143a98153988f6758f7ca828a0b7
|
4
|
+
data.tar.gz: efde23cfc811c084a5a34e1b6584bac05871b500
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bad368b009578eb64f2194a5c6c2adddb908e16d2f6388a9cf8fc2a62da56adbdcaf15c1e9057a13fb9ddd4ee606b87213687c6934387cdf49e7e0c2819c093
|
7
|
+
data.tar.gz: 8ba37282e55441392e706a70d25ad73c2b24166d378167ae29e3389fd092c9f344248aaa2aab0d81d4f250e9240f8cd75cd10739fb09984e4293cf0ceac1d9e1
|
data/.gitignore
CHANGED
data/.mailmap
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Blake Mizerany <blake.mizerany@gmail.com>
|
2
|
+
Lawrence Leonard Gilbert <larry@l2g.to>
|
3
|
+
<larry@l2g.to> <larry@L2G.to>
|
4
|
+
Marc-André Cournoyer <macournoyer@gmail.com>
|
5
|
+
Matthew Manning <matt.manning@gmail.com>
|
6
|
+
Nicholas Wieland <nicholas.wieland@gmail.com>
|
7
|
+
Rafael Ssouza <rafael.ssouza@gmail.com>
|
8
|
+
Richard Schneeman <richard.schneeman@gmail.com>
|
9
|
+
Rick Olson <technoweenie@gmail.com>
|
10
|
+
T. Watanabe <wtnabe@wt-srv.watanabe>
|
data/.rubocop
ADDED
data/.rubocop-disables.yml
CHANGED
@@ -17,7 +17,7 @@ Lint/StringConversionInInterpolation:
|
|
17
17
|
Lint/UnusedBlockArgument:
|
18
18
|
Enabled: false
|
19
19
|
|
20
|
-
|
20
|
+
Security/Eval:
|
21
21
|
Exclude:
|
22
22
|
- rest-client.windows.gemspec
|
23
23
|
|
@@ -110,10 +110,8 @@ Style/ConstantName:
|
|
110
110
|
Metrics/CyclomaticComplexity:
|
111
111
|
Max: 22
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
Style/DeprecatedHashMethods:
|
116
|
-
Enabled: false
|
113
|
+
Style/PreferredHashMethods:
|
114
|
+
EnforcedStyle: verbose
|
117
115
|
|
118
116
|
# TODO: docs
|
119
117
|
# Offense count: 17
|
@@ -122,7 +120,7 @@ Style/Documentation:
|
|
122
120
|
|
123
121
|
# Offense count: 9
|
124
122
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
125
|
-
|
123
|
+
Layout/DotPosition:
|
126
124
|
Enabled: false
|
127
125
|
|
128
126
|
# Offense count: 1
|
@@ -136,24 +134,27 @@ Style/EachWithObject:
|
|
136
134
|
|
137
135
|
# Offense count: 5
|
138
136
|
# Cop supports --auto-correct.
|
139
|
-
|
137
|
+
Layout/EmptyLines:
|
140
138
|
Enabled: false
|
141
139
|
|
142
140
|
# Offense count: 11
|
143
141
|
# Cop supports --auto-correct.
|
144
142
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
145
|
-
|
143
|
+
Layout/EmptyLinesAroundClassBody:
|
146
144
|
Enabled: false
|
147
145
|
|
148
146
|
# Offense count: 1
|
149
147
|
# Cop supports --auto-correct.
|
150
|
-
|
148
|
+
Layout/EmptyLinesAroundMethodBody:
|
151
149
|
Enabled: false
|
152
150
|
|
153
151
|
# Offense count: 9
|
154
152
|
# Cop supports --auto-correct.
|
155
153
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
156
|
-
|
154
|
+
Layout/EmptyLinesAroundModuleBody:
|
155
|
+
Enabled: false
|
156
|
+
|
157
|
+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
|
157
158
|
Enabled: false
|
158
159
|
|
159
160
|
# Offense count: 31
|
@@ -188,7 +189,7 @@ Style/IfUnlessModifier:
|
|
188
189
|
# Offense count: 6
|
189
190
|
# Cop supports --auto-correct.
|
190
191
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
191
|
-
|
192
|
+
Layout/IndentHash:
|
192
193
|
Enabled: false
|
193
194
|
|
194
195
|
# NOTABUG
|
@@ -199,14 +200,13 @@ Style/Lambda:
|
|
199
200
|
# TODO
|
200
201
|
# Offense count: 14
|
201
202
|
# Cop supports --auto-correct.
|
202
|
-
|
203
|
+
Layout/LeadingCommentSpace:
|
203
204
|
Enabled: false
|
204
205
|
|
205
|
-
# TODO
|
206
|
-
# Offense count: 218
|
207
|
-
# Configuration parameters: AllowURI.
|
208
206
|
Metrics/LineLength:
|
209
|
-
|
207
|
+
Exclude:
|
208
|
+
- 'spec/**/*.rb'
|
209
|
+
- 'Rakefile'
|
210
210
|
|
211
211
|
# TODO
|
212
212
|
# Offense count: 28
|
@@ -298,47 +298,50 @@ Style/SignalException:
|
|
298
298
|
# TODO
|
299
299
|
# Offense count: 2
|
300
300
|
# Cop supports --auto-correct.
|
301
|
-
|
301
|
+
Layout/SpaceAfterNot:
|
302
302
|
Enabled: false
|
303
303
|
|
304
304
|
# Offense count: 19
|
305
305
|
# Cop supports --auto-correct.
|
306
306
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
307
|
-
|
307
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
308
308
|
Enabled: false
|
309
309
|
|
310
310
|
# Offense count: 20
|
311
311
|
# Cop supports --auto-correct.
|
312
|
-
|
312
|
+
Layout/SpaceAroundOperators:
|
313
313
|
Enabled: false
|
314
314
|
|
315
315
|
# Offense count: 9
|
316
316
|
# Cop supports --auto-correct.
|
317
317
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
318
|
-
|
318
|
+
Layout/SpaceBeforeBlockBraces:
|
319
|
+
Enabled: false
|
320
|
+
|
321
|
+
Layout/EmptyLinesAroundBlockBody:
|
319
322
|
Enabled: false
|
320
323
|
|
321
324
|
# Offense count: 37
|
322
325
|
# Cop supports --auto-correct.
|
323
326
|
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
324
|
-
|
327
|
+
Layout/SpaceInsideBlockBraces:
|
325
328
|
Enabled: false
|
326
329
|
|
327
330
|
# Offense count: 6
|
328
331
|
# Cop supports --auto-correct.
|
329
|
-
|
332
|
+
Layout/SpaceInsideBrackets:
|
330
333
|
Enabled: false
|
331
334
|
|
332
335
|
# Offense count: 181
|
333
336
|
# Cop supports --auto-correct.
|
334
337
|
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
335
|
-
|
338
|
+
Layout/SpaceInsideHashLiteralBraces:
|
336
339
|
Enabled: false
|
337
340
|
|
338
341
|
# TODO
|
339
342
|
# Offense count: 9
|
340
343
|
# Cop supports --auto-correct.
|
341
|
-
|
344
|
+
Layout/SpaceInsideParens:
|
342
345
|
Enabled: false
|
343
346
|
|
344
347
|
# Offense count: 414
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/AUTHORS
CHANGED
@@ -7,6 +7,7 @@ Adrian Rangel
|
|
7
7
|
Alex Tomlins
|
8
8
|
Aman Gupta
|
9
9
|
Andy Brody
|
10
|
+
Avi Deitcher
|
10
11
|
Blake Mizerany
|
11
12
|
Brad Ediger
|
12
13
|
Braintree
|
@@ -38,10 +39,12 @@ Harm Aarts
|
|
38
39
|
Hiro Asari
|
39
40
|
Hugh McGowan
|
40
41
|
Ian Warshak
|
42
|
+
Igor Zubkov
|
41
43
|
Ivan Makfinsky
|
42
44
|
JH. Chabran
|
43
45
|
James Edward Gray II
|
44
46
|
Jari Bakken
|
47
|
+
Jeff Pereira
|
45
48
|
Jeff Remer
|
46
49
|
Jeffrey Hardy
|
47
50
|
Jeremy Kemper
|
@@ -59,12 +62,14 @@ Keith Rarick
|
|
59
62
|
Kenichi Kamiya
|
60
63
|
Kevin Read
|
61
64
|
Kosuke Asami
|
65
|
+
Kyle Meyer
|
62
66
|
Kyle VanderBeek
|
63
67
|
Lars Gierth
|
64
68
|
Lawrence Leonard Gilbert
|
65
69
|
Lee Jarvis
|
66
70
|
Lennon Day-Reynolds
|
67
71
|
Lin Jen-Shin
|
72
|
+
Magne Matre Gåsland
|
68
73
|
Marc-André Cournoyer
|
69
74
|
Marius Butuc
|
70
75
|
Matthew Manning
|
@@ -77,6 +82,7 @@ Nicholas Wieland
|
|
77
82
|
Nick Hammond
|
78
83
|
Nick Plante
|
79
84
|
Niko Dittmann
|
85
|
+
Nikolay Shebanov
|
80
86
|
Oscar Del Ben
|
81
87
|
Pablo Astigarraga
|
82
88
|
Paul Dlug
|
@@ -85,9 +91,11 @@ Pedro Chambino
|
|
85
91
|
Philip Corliss
|
86
92
|
Pierre-Louis Gottfrois
|
87
93
|
Rafael Ssouza
|
94
|
+
Richard Schneeman
|
88
95
|
Rick Olson
|
89
96
|
Robert Eanes
|
90
97
|
Rodrigo Panachi
|
98
|
+
Sam Norbury
|
91
99
|
Samuel Cochran
|
92
100
|
Syl Turner
|
93
101
|
T. Watanabe
|
data/README.md
CHANGED
@@ -39,6 +39,7 @@ The rest-client gem depends on these other gems for usage at runtime:
|
|
39
39
|
|
40
40
|
* [mime-types](http://rubygems.org/gems/mime-types)
|
41
41
|
* [netrc](http://rubygems.org/gems/netrc)
|
42
|
+
* [http-accept](https://rubygems.org/gems/http-accept)
|
42
43
|
* [http-cookie](https://rubygems.org/gems/http-cookie)
|
43
44
|
|
44
45
|
There are also several development dependencies. It's recommended to use
|
@@ -359,7 +360,7 @@ RestClient.get('http://example.com/resource') { |response, request, result, &blo
|
|
359
360
|
when 423
|
360
361
|
raise SomeCustomExceptionIfYouWant
|
361
362
|
else
|
362
|
-
response.return!(
|
363
|
+
response.return!(&block)
|
363
364
|
end
|
364
365
|
}
|
365
366
|
```
|
@@ -446,6 +447,106 @@ You can:
|
|
446
447
|
|
447
448
|
See `RestClient::Request`'s documentation for more information.
|
448
449
|
|
450
|
+
### Streaming request payload
|
451
|
+
|
452
|
+
RestClient will try to stream any file-like payload rather than reading it into
|
453
|
+
memory. This happens through `RestClient::Payload::Streamed`, which is
|
454
|
+
automatically called internally by `RestClient::Payload.generate` on anything
|
455
|
+
with a `read` method.
|
456
|
+
|
457
|
+
```ruby
|
458
|
+
>> r = RestClient.put('http://httpbin.org/put', File.open('/tmp/foo.txt', 'r'),
|
459
|
+
content_type: 'text/plain')
|
460
|
+
=> <RestClient::Response 200 "{\n \"args\":...">
|
461
|
+
```
|
462
|
+
|
463
|
+
In Multipart requests, RestClient will also stream file handles passed as Hash
|
464
|
+
(or __new in 2.1__ ParamsArray).
|
465
|
+
|
466
|
+
```ruby
|
467
|
+
>> r = RestClient.put('http://httpbin.org/put',
|
468
|
+
{file_a: File.open('a.txt', 'r'),
|
469
|
+
file_b: File.open('b.txt', 'r')})
|
470
|
+
=> <RestClient::Response 200 "{\n \"args\":...">
|
471
|
+
|
472
|
+
# received by server as two file uploads with multipart/form-data
|
473
|
+
>> JSON.parse(r)['files'].keys
|
474
|
+
=> ['file_a', 'file_b']
|
475
|
+
```
|
476
|
+
|
477
|
+
### Streaming responses
|
478
|
+
|
479
|
+
Normally, when you use `RestClient.get` or the lower level
|
480
|
+
`RestClient::Request.execute method: :get` to retrieve data, the entire
|
481
|
+
response is buffered in memory and returned as the response to the call.
|
482
|
+
|
483
|
+
However, if you are retrieving a large amount of data, for example a Docker
|
484
|
+
image, an iso, or any other large file, you may want to stream the response
|
485
|
+
directly to disk rather than loading it in memory. If you have a very large
|
486
|
+
file, it may become *impossible* to load it into memory.
|
487
|
+
|
488
|
+
There are two main ways to do this:
|
489
|
+
|
490
|
+
#### `raw_response`, saves into Tempfile
|
491
|
+
|
492
|
+
If you pass `raw_response: true` to `RestClient::Request.execute`, it will save
|
493
|
+
the response body to a temporary file (using `Tempfile`) and return a
|
494
|
+
`RestClient::RawResponse` object rather than a `RestClient::Response`.
|
495
|
+
|
496
|
+
Note that the tempfile created by `Tempfile.new` will be in `Dir.tmpdir`
|
497
|
+
(usually `/tmp/`), which you can override to store temporary files in a
|
498
|
+
different location. This file will be unlinked when it is dereferenced.
|
499
|
+
|
500
|
+
If logging is enabled, this will also print download progress.
|
501
|
+
__New in 2.1:__ Customize the interval with `:stream_log_percent` (defaults to
|
502
|
+
10 for printing a message every 10% complete).
|
503
|
+
|
504
|
+
For example:
|
505
|
+
|
506
|
+
```ruby
|
507
|
+
>> raw = RestClient::Request.execute(
|
508
|
+
method: :get,
|
509
|
+
url: 'http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-desktop-amd64.iso',
|
510
|
+
raw_response: true)
|
511
|
+
=> <RestClient::RawResponse @code=200, @file=#<Tempfile:/tmp/rest-client.20170522-5346-1pptjm1>, @request=<RestClient::Request @method="get", @url="http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-desktop-amd64.iso">>
|
512
|
+
>> raw.file.size
|
513
|
+
=> 1554186240
|
514
|
+
>> raw.file.path
|
515
|
+
=> "/tmp/rest-client.20170522-5346-1pptjm1"
|
516
|
+
raw.file.path
|
517
|
+
=> "/tmp/rest-client.20170522-5346-1pptjm1"
|
518
|
+
|
519
|
+
>> require 'digest/sha1'
|
520
|
+
>> Digest::SHA1.file(raw.file.path).hexdigest
|
521
|
+
=> "4375b73e3a1aa305a36320ffd7484682922262b3"
|
522
|
+
```
|
523
|
+
|
524
|
+
#### `block_response`, receives raw Net::HTTPResponse
|
525
|
+
|
526
|
+
If you want to stream the data from the response to a file as it comes, rather
|
527
|
+
than entirely in memory, you can also pass `RestClient::Request.execute` a
|
528
|
+
parameter `:block_response` to which you pass a block/proc. This block receives
|
529
|
+
the raw unmodified Net::HTTPResponse object from Net::HTTP, which you can use
|
530
|
+
to stream directly to a file as each chunk is received.
|
531
|
+
|
532
|
+
Note that this bypasses all the usual HTTP status code handling, so you will
|
533
|
+
want to do you own checking for HTTP 20x response codes, redirects, etc.
|
534
|
+
|
535
|
+
The following is an example:
|
536
|
+
|
537
|
+
````ruby
|
538
|
+
File.open('/some/output/file', 'w') {|f|
|
539
|
+
block = proc { |response|
|
540
|
+
response.read_body do |chunk|
|
541
|
+
f.write chunk
|
542
|
+
end
|
543
|
+
}
|
544
|
+
RestClient::Request.execute(method: :get,
|
545
|
+
url: 'http://example.com/some/really/big/file.img',
|
546
|
+
block_response: block)
|
547
|
+
}
|
548
|
+
````
|
549
|
+
|
449
550
|
## Shell
|
450
551
|
|
451
552
|
The restclient shell command gives an IRB session with RestClient already loaded:
|
@@ -498,7 +599,7 @@ $ restclient put http://example.com/resource < input_body
|
|
498
599
|
|
499
600
|
## Logging
|
500
601
|
|
501
|
-
To enable logging you can:
|
602
|
+
To enable logging globally you can:
|
502
603
|
|
503
604
|
- set RestClient.log with a Ruby Logger, or
|
504
605
|
- set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
|
@@ -506,7 +607,19 @@ To enable logging you can:
|
|
506
607
|
```ruby
|
507
608
|
$ RESTCLIENT_LOG=stdout path/to/my/program
|
508
609
|
```
|
509
|
-
|
610
|
+
|
611
|
+
You can also set individual loggers when instantiating a Resource or making an
|
612
|
+
individual request:
|
613
|
+
|
614
|
+
```ruby
|
615
|
+
resource = RestClient::Resource.new 'http://example.com/resource', log: Logger.new(STDOUT)
|
616
|
+
```
|
617
|
+
|
618
|
+
```ruby
|
619
|
+
RestClient::Request.execute(method: :get, url: 'http://example.com/foo', log: Logger.new(STDERR))
|
620
|
+
```
|
621
|
+
|
622
|
+
All options produce logs like this:
|
510
623
|
|
511
624
|
```ruby
|
512
625
|
RestClient.get "http://some/resource"
|
@@ -774,11 +887,10 @@ See AUTHORS for the full list.
|
|
774
887
|
|
775
888
|
## Legal
|
776
889
|
|
777
|
-
Released under the MIT License:
|
890
|
+
Released under the MIT License: https://opensource.org/licenses/MIT
|
778
891
|
|
779
|
-
|
780
|
-
|
781
|
-
Generic license (http://creativecommons.org/licenses/by-sa/2.0/)
|
892
|
+
Photo of the International Space Station was produced by NASA and is in the
|
893
|
+
public domain.
|
782
894
|
|
783
895
|
Code for reading Windows root certificate store derived from work by Puppet;
|
784
896
|
used under terms of the Apache License, Version 2.0.
|
data/Rakefile
CHANGED
@@ -38,12 +38,11 @@ desc 'Regenerate authors file'
|
|
38
38
|
task :authors do
|
39
39
|
Dir.chdir(File.dirname(__FILE__)) do
|
40
40
|
File.open('AUTHORS', 'w') do |f|
|
41
|
-
f.write
|
41
|
+
f.write <<-EOM
|
42
42
|
The Ruby REST Client would not be what it is today without the help of
|
43
43
|
the following kind souls:
|
44
44
|
|
45
45
|
EOM
|
46
|
-
)
|
47
46
|
end
|
48
47
|
|
49
48
|
sh 'git shortlog -s | cut -f 2 >> AUTHORS'
|
@@ -70,8 +69,8 @@ namespace :all do
|
|
70
69
|
task :build => ['ruby:build'] + \
|
71
70
|
WindowsPlatforms.map {|p| "windows:#{p}:build"}
|
72
71
|
|
73
|
-
desc "Create tag v#{RestClient::VERSION} and for all platforms build and
|
74
|
-
"rest-client #{RestClient::VERSION} to Rubygems"
|
72
|
+
desc "Create tag v#{RestClient::VERSION} and for all platforms build and " \
|
73
|
+
"push rest-client #{RestClient::VERSION} to Rubygems"
|
75
74
|
task :release => ['build', 'ruby:release'] + \
|
76
75
|
WindowsPlatforms.map {|p| "windows:#{p}:push"}
|
77
76
|
|
@@ -130,3 +129,12 @@ Rake::RDocTask.new do |t|
|
|
130
129
|
t.rdoc_files.include('README.md')
|
131
130
|
t.rdoc_files.include('lib/*.rb')
|
132
131
|
end
|
132
|
+
|
133
|
+
############################
|
134
|
+
|
135
|
+
require 'rubocop/rake_task'
|
136
|
+
|
137
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
138
|
+
t.options = ['--display-cop-names']
|
139
|
+
end
|
140
|
+
alias_task(:lint, :rubocop)
|