rest-client 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.mailmap +10 -0
- data/.rubocop +2 -0
- data/.rubocop-disables.yml +46 -44
- data/.rubocop.yml +5 -0
- data/.travis.yml +31 -17
- data/AUTHORS +8 -0
- data/README.md +126 -9
- data/Rakefile +12 -4
- data/history.md +53 -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 +29 -4
- data/lib/restclient/raw_response.rb +17 -6
- data/lib/restclient/request.rb +94 -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 +3 -2
- data/spec/ISS.jpg +0 -0
- data/spec/helpers.rb +37 -5
- data/spec/integration/capath_digicert/3513523f.0 +22 -0
- data/spec/integration/capath_digicert/399e7759.0 +22 -0
- data/spec/integration/capath_digicert/digicert.crt +20 -17
- data/spec/integration/certs/digicert.crt +20 -17
- 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 +53 -65
- 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 +34 -13
- data/spec/integration/capath_digicert/244b5494.0 +0 -19
- data/spec/integration/capath_digicert/81b9768f.0 +0 -19
- data/spec/unit/master_shake.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e61fb064d966989b00da05fc3e16e3c389cebb68de302d1436e9e2be10dbef8c
|
4
|
+
data.tar.gz: fa5deab3c8c4a44e2d5478e212dd24221d37812f818d4e8cb63e65ebafd8e85c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca5026c1f26f1c465c0e2ed869c1a6f6f0dc3b229843d972f9c0267d2f25e98565a672a91b899796d5494391bac73b35d3f36782f0b4afdade1b4d525e09307a
|
7
|
+
data.tar.gz: 8ce3970ab67e95e68cfce154ed6865285f04f0e493c694a7014dee54901a9d64759299bf43c542ce23baf05e15676c9daebd5fa4c53703891cdf179a6a0cf769
|
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
|
|
@@ -53,8 +53,9 @@ Style/BracesAroundHashParameters:
|
|
53
53
|
Enabled: false
|
54
54
|
|
55
55
|
# Offense count: 1
|
56
|
-
|
57
|
-
|
56
|
+
Naming/ClassAndModuleCamelCase:
|
57
|
+
Exclude:
|
58
|
+
- lib/restclient/windows/root_certs.rb
|
58
59
|
|
59
60
|
# Offense count: 2
|
60
61
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
@@ -102,7 +103,7 @@ Style/ConditionalAssignment:
|
|
102
103
|
EnforcedStyle: assign_inside_condition
|
103
104
|
|
104
105
|
# Offense count: 2
|
105
|
-
|
106
|
+
Naming/ConstantName:
|
106
107
|
Enabled: false
|
107
108
|
|
108
109
|
# TODO: eh?
|
@@ -110,10 +111,8 @@ Style/ConstantName:
|
|
110
111
|
Metrics/CyclomaticComplexity:
|
111
112
|
Max: 22
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
Style/DeprecatedHashMethods:
|
116
|
-
Enabled: false
|
114
|
+
Style/PreferredHashMethods:
|
115
|
+
EnforcedStyle: verbose
|
117
116
|
|
118
117
|
# TODO: docs
|
119
118
|
# Offense count: 17
|
@@ -122,7 +121,7 @@ Style/Documentation:
|
|
122
121
|
|
123
122
|
# Offense count: 9
|
124
123
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
125
|
-
|
124
|
+
Layout/DotPosition:
|
126
125
|
Enabled: false
|
127
126
|
|
128
127
|
# Offense count: 1
|
@@ -136,24 +135,27 @@ Style/EachWithObject:
|
|
136
135
|
|
137
136
|
# Offense count: 5
|
138
137
|
# Cop supports --auto-correct.
|
139
|
-
|
138
|
+
Layout/EmptyLines:
|
140
139
|
Enabled: false
|
141
140
|
|
142
141
|
# Offense count: 11
|
143
142
|
# Cop supports --auto-correct.
|
144
143
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
145
|
-
|
144
|
+
Layout/EmptyLinesAroundClassBody:
|
146
145
|
Enabled: false
|
147
146
|
|
148
147
|
# Offense count: 1
|
149
148
|
# Cop supports --auto-correct.
|
150
|
-
|
149
|
+
Layout/EmptyLinesAroundMethodBody:
|
151
150
|
Enabled: false
|
152
151
|
|
153
152
|
# Offense count: 9
|
154
153
|
# Cop supports --auto-correct.
|
155
154
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
156
|
-
|
155
|
+
Layout/EmptyLinesAroundModuleBody:
|
156
|
+
Enabled: false
|
157
|
+
|
158
|
+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
|
157
159
|
Enabled: false
|
158
160
|
|
159
161
|
# Offense count: 31
|
@@ -161,11 +163,9 @@ Style/EmptyLinesAroundModuleBody:
|
|
161
163
|
Style/Encoding:
|
162
164
|
Enabled: false
|
163
165
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
Style/FileName:
|
168
|
-
Enabled: false
|
166
|
+
Naming/FileName:
|
167
|
+
Exclude:
|
168
|
+
- lib/rest-client.rb
|
169
169
|
|
170
170
|
# Offense count: 3
|
171
171
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
@@ -184,12 +184,9 @@ Style/HashSyntax:
|
|
184
184
|
Style/IfUnlessModifier:
|
185
185
|
Enabled: false
|
186
186
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
191
|
-
Style/IndentHash:
|
192
|
-
Enabled: false
|
187
|
+
Layout/IndentFirstHashElement:
|
188
|
+
Exclude:
|
189
|
+
- 'spec/**/*.rb'
|
193
190
|
|
194
191
|
# NOTABUG
|
195
192
|
# Offense count: 19
|
@@ -199,14 +196,13 @@ Style/Lambda:
|
|
199
196
|
# TODO
|
200
197
|
# Offense count: 14
|
201
198
|
# Cop supports --auto-correct.
|
202
|
-
|
199
|
+
Layout/LeadingCommentSpace:
|
203
200
|
Enabled: false
|
204
201
|
|
205
|
-
# TODO
|
206
|
-
# Offense count: 218
|
207
|
-
# Configuration parameters: AllowURI.
|
208
202
|
Metrics/LineLength:
|
209
|
-
|
203
|
+
Exclude:
|
204
|
+
- 'spec/**/*.rb'
|
205
|
+
- 'Rakefile'
|
210
206
|
|
211
207
|
# TODO
|
212
208
|
# Offense count: 28
|
@@ -262,7 +258,7 @@ Style/PercentLiteralDelimiters:
|
|
262
258
|
|
263
259
|
# Offense count: 3
|
264
260
|
# Configuration parameters: NamePrefixBlacklist.
|
265
|
-
|
261
|
+
Naming/PredicateName:
|
266
262
|
Enabled: false
|
267
263
|
|
268
264
|
# TODO: configure
|
@@ -298,47 +294,45 @@ Style/SignalException:
|
|
298
294
|
# TODO
|
299
295
|
# Offense count: 2
|
300
296
|
# Cop supports --auto-correct.
|
301
|
-
|
297
|
+
Layout/SpaceAfterNot:
|
302
298
|
Enabled: false
|
303
299
|
|
304
300
|
# Offense count: 19
|
305
301
|
# Cop supports --auto-correct.
|
306
302
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
307
|
-
|
303
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
308
304
|
Enabled: false
|
309
305
|
|
310
306
|
# Offense count: 20
|
311
307
|
# Cop supports --auto-correct.
|
312
|
-
|
308
|
+
Layout/SpaceAroundOperators:
|
313
309
|
Enabled: false
|
314
310
|
|
315
311
|
# Offense count: 9
|
316
312
|
# Cop supports --auto-correct.
|
317
313
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
318
|
-
|
314
|
+
Layout/SpaceBeforeBlockBraces:
|
319
315
|
Enabled: false
|
320
316
|
|
321
|
-
|
322
|
-
# Cop supports --auto-correct.
|
323
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
324
|
-
Style/SpaceInsideBlockBraces:
|
317
|
+
Layout/EmptyLinesAroundBlockBody:
|
325
318
|
Enabled: false
|
326
319
|
|
327
|
-
# Offense count:
|
320
|
+
# Offense count: 37
|
328
321
|
# Cop supports --auto-correct.
|
329
|
-
|
322
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
323
|
+
Layout/SpaceInsideBlockBraces:
|
330
324
|
Enabled: false
|
331
325
|
|
332
326
|
# Offense count: 181
|
333
327
|
# Cop supports --auto-correct.
|
334
328
|
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
335
|
-
|
329
|
+
Layout/SpaceInsideHashLiteralBraces:
|
336
330
|
Enabled: false
|
337
331
|
|
338
332
|
# TODO
|
339
333
|
# Offense count: 9
|
340
334
|
# Cop supports --auto-correct.
|
341
|
-
|
335
|
+
Layout/SpaceInsideParens:
|
342
336
|
Enabled: false
|
343
337
|
|
344
338
|
# Offense count: 414
|
@@ -347,8 +341,10 @@ Style/SpaceInsideParens:
|
|
347
341
|
Style/StringLiterals:
|
348
342
|
Enabled: false
|
349
343
|
|
350
|
-
Style/
|
351
|
-
EnforcedStyleForMultiline:
|
344
|
+
Style/TrailingCommaInArrayLiteral:
|
345
|
+
EnforcedStyleForMultiline: consistent_comma
|
346
|
+
Style/TrailingCommaInHashLiteral:
|
347
|
+
EnforcedStyleForMultiline: consistent_comma
|
352
348
|
Style/TrailingCommaInArguments:
|
353
349
|
Enabled: false
|
354
350
|
|
@@ -382,3 +378,9 @@ Style/WordArray:
|
|
382
378
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
383
379
|
Style/BarePercentLiterals:
|
384
380
|
Enabled: false
|
381
|
+
|
382
|
+
|
383
|
+
Style/RescueStandardError:
|
384
|
+
Exclude:
|
385
|
+
- 'bin/restclient'
|
386
|
+
- 'lib/restclient/windows/root_certs.rb'
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,48 +1,62 @@
|
|
1
1
|
# Available ruby versions: http://rubies.travis-ci.org/
|
2
2
|
|
3
3
|
language: ruby
|
4
|
+
sudo: false
|
4
5
|
|
5
6
|
os:
|
6
7
|
- linux
|
7
|
-
- osx
|
8
|
+
# - osx
|
8
9
|
|
9
10
|
rvm:
|
10
|
-
- "2.0.0"
|
11
11
|
- "2.1" # latest 2.1.x
|
12
|
-
- "2.2.
|
13
|
-
- "2.3.
|
14
|
-
- "2.4.
|
12
|
+
- "2.2.10"
|
13
|
+
- "2.3.8"
|
14
|
+
- "2.4.6"
|
15
|
+
- "2.5.5"
|
16
|
+
- "2.6.3"
|
15
17
|
- "ruby-head"
|
16
|
-
- "jruby-9.
|
17
|
-
- "jruby-9.1.5.0"
|
18
|
+
- "jruby-9.1.9.0"
|
18
19
|
- "jruby-head"
|
19
20
|
|
20
21
|
cache: bundler
|
21
22
|
|
22
23
|
script:
|
23
|
-
bundle exec rake test
|
24
|
+
- bundle exec rake test
|
25
|
+
- bundle exec rake rubocop
|
24
26
|
|
25
27
|
branches:
|
26
28
|
except:
|
27
29
|
- "readme-edits"
|
28
30
|
|
29
31
|
before_install:
|
30
|
-
|
32
|
+
# Install rubygems < 3.0 so that we can support ruby < 2.3
|
33
|
+
# https://github.com/rubygems/rubygems/issues/2534
|
34
|
+
- gem install rubygems-update -v '<3' && update_rubygems
|
31
35
|
# bundler installation needed for jruby-head
|
32
36
|
# https://github.com/travis-ci/travis-ci/issues/5861
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#
|
37
|
-
#
|
37
|
+
# stick to bundler 1.x in order to support ruby < 2.3
|
38
|
+
- gem install bundler -v '~> 1.17'
|
39
|
+
|
40
|
+
# Travis macOS support is pretty janky. These are some hacks to include tests
|
41
|
+
# only on versions that actually work. We test on macOS because Apple monkey
|
42
|
+
# patches OpenSSL to have different behavior, and we want to ensure that SSL
|
43
|
+
# verification at least is broken in the expected ways on macOS.
|
44
|
+
# (last tested: 2019-08)
|
38
45
|
matrix:
|
39
46
|
# exclude: {}
|
40
|
-
|
47
|
+
include:
|
48
|
+
# test only a few versions on mac
|
49
|
+
- os: osx
|
50
|
+
rvm: 2.6.3
|
51
|
+
- os: osx
|
52
|
+
rvm: ruby-head
|
53
|
+
- os: osx
|
54
|
+
rvm: jruby-9.1.9.0
|
55
|
+
- os: osx
|
56
|
+
rvm: jruby-head
|
41
57
|
|
42
58
|
allow_failures:
|
43
59
|
- rvm: 'ruby-head'
|
44
60
|
|
45
61
|
# return results as soon as mandatory versions are done
|
46
62
|
fast_finish: true
|
47
|
-
|
48
|
-
sudo: false
|
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,15 +599,32 @@ $ 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
|
-
- set RestClient.log with a Ruby Logger
|
504
|
-
|
604
|
+
- set RestClient.log with a Ruby Logger
|
605
|
+
|
606
|
+
```ruby
|
607
|
+
RestClient.log = STDOUT
|
608
|
+
```
|
609
|
+
|
610
|
+
- or set an environment variable to avoid modifying the code (in this case you can use a file name, "stdout" or "stderr"):
|
505
611
|
|
506
612
|
```ruby
|
507
613
|
$ RESTCLIENT_LOG=stdout path/to/my/program
|
508
614
|
```
|
509
|
-
|
615
|
+
|
616
|
+
You can also set individual loggers when instantiating a Resource or making an
|
617
|
+
individual request:
|
618
|
+
|
619
|
+
```ruby
|
620
|
+
resource = RestClient::Resource.new 'http://example.com/resource', log: Logger.new(STDOUT)
|
621
|
+
```
|
622
|
+
|
623
|
+
```ruby
|
624
|
+
RestClient::Request.execute(method: :get, url: 'http://example.com/foo', log: Logger.new(STDERR))
|
625
|
+
```
|
626
|
+
|
627
|
+
All options produce logs like this:
|
510
628
|
|
511
629
|
```ruby
|
512
630
|
RestClient.get "http://some/resource"
|
@@ -774,11 +892,10 @@ See AUTHORS for the full list.
|
|
774
892
|
|
775
893
|
## Legal
|
776
894
|
|
777
|
-
Released under the MIT License:
|
895
|
+
Released under the MIT License: https://opensource.org/licenses/MIT
|
778
896
|
|
779
|
-
|
780
|
-
|
781
|
-
Generic license (http://creativecommons.org/licenses/by-sa/2.0/)
|
897
|
+
Photo of the International Space Station was produced by NASA and is in the
|
898
|
+
public domain.
|
782
899
|
|
783
900
|
Code for reading Windows root certificate store derived from work by Puppet;
|
784
901
|
used under terms of the Apache License, Version 2.0.
|