rest-man 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{multi-matrix-test.yml → ci.yml} +10 -1
  3. data/.github/workflows/single-matrix-test.yml +1 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop-disables.yml +4 -29
  6. data/AUTHORS +5 -1
  7. data/CHANGELOG.md +14 -0
  8. data/Gemfile +3 -0
  9. data/README.md +30 -37
  10. data/Rakefile +1 -59
  11. data/_doc/lib/restman/abstract_response/_follow_redirection.rdoc +7 -0
  12. data/_doc/lib/restman/abstract_response/beautify_headers.rdoc +24 -0
  13. data/_doc/lib/restman/abstract_response/cookie_jar.rdoc +4 -0
  14. data/_doc/lib/restman/abstract_response/cookies.rdoc +12 -0
  15. data/_doc/lib/restman/abstract_response/follow_get_redirection.rdoc +2 -0
  16. data/_doc/lib/restman/abstract_response/follow_redirection.rdoc +2 -0
  17. data/_doc/lib/restman/abstract_response/headers.rdoc +2 -0
  18. data/_doc/lib/restman/abstract_response/response_set_vars.rdoc +5 -0
  19. data/_doc/lib/restman/abstract_response/return.rdoc +9 -0
  20. data/_doc/lib/restman/add_before_execution_proc.rdoc +2 -0
  21. data/_doc/lib/restman/create_log.rdoc +2 -0
  22. data/_doc/lib/restman/exception.rdoc +6 -0
  23. data/_doc/lib/restman/exceptions/timeout.rdoc +4 -0
  24. data/_doc/lib/restman/exceptions.rdoc +4 -0
  25. data/_doc/lib/restman/log=.rdoc +3 -0
  26. data/_doc/lib/restman/params_array/new.rdoc +20 -0
  27. data/_doc/lib/restman/params_array/process_pair.rdoc +4 -0
  28. data/_doc/lib/restman/params_array.rdoc +11 -0
  29. data/_doc/lib/restman/platform/jruby?.rdoc +4 -0
  30. data/_doc/lib/restman/platform/mac_mri?.rdoc +5 -0
  31. data/_doc/lib/restman/proxy.rdoc +2 -0
  32. data/_doc/lib/restman/proxy_set?.rdoc +5 -0
  33. data/_doc/lib/restman/raw_response/new.rdoc +6 -0
  34. data/_doc/lib/restman/raw_response.rdoc +10 -0
  35. data/_doc/lib/restman/request/cookie_jar.rdoc +3 -0
  36. data/_doc/lib/restman/request/cookies.rdoc +11 -0
  37. data/_doc/lib/restman/request/default_headers.rdoc +5 -0
  38. data/_doc/lib/restman/request/default_ssl_cert_store.rdoc +8 -0
  39. data/_doc/lib/restman/request/init/cookie_jar.rdoc +55 -0
  40. data/_doc/lib/restman/request/init/http_method.rdoc +15 -0
  41. data/_doc/lib/restman/request/make_cookie_header.rdoc +8 -0
  42. data/_doc/lib/restman/request/make_headers.rdoc +25 -0
  43. data/_doc/lib/restman/request/maybe_convert_extension.rdoc +18 -0
  44. data/_doc/lib/restman/request/process_result.rdoc +4 -0
  45. data/_doc/lib/restman/request/proxy_uri.rdoc +7 -0
  46. data/_doc/lib/restman/request/stringify_headers.rdoc +9 -0
  47. data/_doc/lib/restman/request/use_ssl.rdoc +4 -0
  48. data/_doc/lib/restman/request.rdoc +46 -0
  49. data/_doc/lib/restman/reset_before_execution_procs.rdoc +1 -0
  50. data/_doc/lib/restman/resource/[].rdoc +25 -0
  51. data/_doc/lib/restman/resource.rdoc +33 -0
  52. data/_doc/lib/restman/response/body.rdoc +7 -0
  53. data/_doc/lib/restman/response/create.rdoc +10 -0
  54. data/_doc/lib/restman/response/fix_encoding.rdoc +2 -0
  55. data/_doc/lib/restman/statuses.rdoc +11 -0
  56. data/_doc/lib/restman/utils/cgi_parse_header.rdoc +6 -0
  57. data/_doc/lib/restman/utils/encode_query_string.rdoc +90 -0
  58. data/_doc/lib/restman/utils/escape.rdoc +11 -0
  59. data/_doc/lib/restman/utils/flatten_params.rdoc +16 -0
  60. data/_doc/lib/restman/utils/get_encoding_from_headers.rdoc +24 -0
  61. data/_doc/lib/restman.rdoc +43 -0
  62. data/bin/console +15 -0
  63. data/lib/restman/abstract_response.rb +13 -60
  64. data/lib/restman/exception.rb +43 -0
  65. data/lib/restman/exceptions/exception_with_response.rb +7 -0
  66. data/lib/restman/exceptions/exceptions_map.rb +26 -0
  67. data/lib/restman/exceptions/request_failed.rb +15 -0
  68. data/lib/restman/exceptions/server_broke_connection.rb +13 -0
  69. data/lib/restman/exceptions/timeout.rb +37 -0
  70. data/lib/restman/params_array/process_pair.rb +39 -0
  71. data/lib/restman/params_array.rb +3 -48
  72. data/lib/restman/payload/base.rb +57 -0
  73. data/lib/restman/payload/multipart/write_content_disposition.rb +88 -0
  74. data/lib/restman/payload/multipart.rb +56 -0
  75. data/lib/restman/payload/streamed.rb +22 -0
  76. data/lib/restman/payload/url_encoded.rb +14 -0
  77. data/lib/restman/payload.rb +14 -196
  78. data/lib/restman/platform.rb +2 -18
  79. data/lib/restman/raw_response.rb +2 -14
  80. data/lib/restman/request/default_ssl_cert_store.rb +13 -0
  81. data/lib/restman/request/fetch_body_to_tempfile.rb +58 -0
  82. data/lib/restman/request/init/cookie_jar.rb +65 -0
  83. data/lib/restman/request/init/ssl_opts.rb +70 -0
  84. data/lib/restman/request/init/url/add_query_from_headers.rb +51 -0
  85. data/lib/restman/request/init/url/normalize_url.rb +19 -0
  86. data/lib/restman/request/init/url.rb +40 -0
  87. data/lib/restman/request/init.rb +106 -0
  88. data/lib/restman/request/log_request.rb +46 -0
  89. data/lib/restman/request/make_cookie_header.rb +16 -0
  90. data/lib/restman/request/make_headers.rb +39 -0
  91. data/lib/restman/request/maybe_convert_extension.rb +28 -0
  92. data/lib/restman/request/net_http_object.rb +25 -0
  93. data/lib/restman/request/process_result.rb +36 -0
  94. data/lib/restman/request/proxy_uri.rb +31 -0
  95. data/lib/restman/request/stringify_headers.rb +36 -0
  96. data/lib/restman/request/transmit.rb +152 -0
  97. data/lib/restman/request.rb +60 -745
  98. data/lib/restman/resource.rb +2 -60
  99. data/lib/restman/response.rb +3 -21
  100. data/lib/restman/statuses.rb +75 -0
  101. data/lib/restman/statuses_compatibility.rb +18 -0
  102. data/lib/restman/utils.rb +10 -206
  103. data/lib/restman/version.rb +1 -1
  104. data/lib/restman.rb +24 -62
  105. data/matrixeval.yml +19 -1
  106. data/rest-man.gemspec +4 -10
  107. data/spec/integration/capath_digicert/ce5e74ef.0 +1 -1
  108. data/spec/integration/request_spec.rb +13 -1
  109. data/spec/spec_helper.rb +11 -0
  110. data/spec/unit/abstract_response_spec.rb +14 -0
  111. data/spec/unit/exception_spec.rb +64 -0
  112. data/spec/unit/exceptions/backwards_campatibility_spec.rb +29 -0
  113. data/spec/unit/exceptions/exceptions_map_spec.rb +89 -0
  114. data/spec/unit/exceptions/request_failed_spec.rb +51 -0
  115. data/spec/unit/exceptions/server_broke_connection_spec.rb +8 -0
  116. data/spec/unit/exceptions/timeout_spec.rb +59 -0
  117. data/spec/unit/params_array/process_pair_spec.rb +59 -0
  118. data/spec/unit/params_array_spec.rb +15 -10
  119. data/spec/unit/payload/multipart_spec.rb +116 -0
  120. data/spec/unit/payload/streamed_spec.rb +48 -0
  121. data/spec/unit/payload/url_encoded_spec.rb +65 -0
  122. data/spec/unit/payload_spec.rb +0 -208
  123. data/spec/unit/request/init/url/add_query_from_headers_spec.rb +40 -0
  124. data/spec/unit/request/init/url/normalize_url_spec.rb +25 -0
  125. data/spec/unit/request/init_spec.rb +83 -0
  126. data/spec/unit/request_spec.rb +143 -151
  127. data/spec/unit/utils_spec.rb +96 -104
  128. metadata +132 -16
  129. data/lib/restman/exceptions.rb +0 -238
  130. data/lib/restman/windows/root_certs.rb +0 -105
  131. data/lib/restman/windows.rb +0 -8
  132. data/spec/unit/exceptions_spec.rb +0 -108
  133. data/spec/unit/windows/root_certs_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2274a801fef783f90e351212a49c396e9206f39b6216a29c1cdc0b6995b0a8fc
4
- data.tar.gz: 5007d4e83636368725a1e4a3d69d7a844a05d0d5407bd2853d200b15ca4e4105
3
+ metadata.gz: d2a2ed4e6c9eb8299cb2b261f08ee19f8a8a6cb9716e3a92dd35f976f406f6a6
4
+ data.tar.gz: 959ea55211158eb81adde856be6144a62b5f9bd6e9bf0b3d294cb8ee41ab9cd3
5
5
  SHA512:
6
- metadata.gz: 674b7bd8deef3107f3a3bd41412de34e67116902e946842951487833e47ed772856df64a56b46e2082c04735cdc3a0b79f14236bb6ef501d26f6faf1fb072999
7
- data.tar.gz: 8d299a22870e2010f56e4ddb3c04b42d3e2959651438edb2f03ec22cc3af09e63b894d287e513e6e99bdceb5f535dbd443527858b7a67d53e9b0ab2f1329ccd2
6
+ metadata.gz: 4d92a3aa41d3447a1559466579314515950bb424a1a598310999841e77732d2ae604bb4b7ab5e868045aed1ea19d48fee0ba6ff4027828d9a221184a59a3bc73
7
+ data.tar.gz: 824b1be24cc6b19544d529a13f0aa18201cde6a9112ad331e6a1b35e56bc925e8ae7c2ca328b8b5c513dd5995716dc9079874e7ee4f4736f28afc6b02dad64fe
@@ -1,4 +1,4 @@
1
- name: Run tests against all matrix
1
+ name: CI
2
2
 
3
3
  on:
4
4
  push:
@@ -18,6 +18,7 @@ jobs:
18
18
  strategy:
19
19
  matrix:
20
20
  ruby:
21
+ - 2.6
21
22
  - 2.7
22
23
  - 3.0
23
24
  - 3.1
@@ -32,4 +33,12 @@ jobs:
32
33
  ruby-version: ${{ matrix.ruby }}
33
34
  bundler-cache: true
34
35
  - name: Run all tests with RSpec
36
+ env:
37
+ UPLOAD_COVERAGE_TO_CODACY: true
35
38
  run: bundle exec rspec
39
+ - name: Run codacy-coverage-reporter
40
+ if: matrix.ruby == '3.1'
41
+ uses: codacy/codacy-coverage-reporter-action@v1
42
+ with:
43
+ project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
44
+ coverage-reports: coverage/coverage.xml
@@ -7,6 +7,7 @@ on:
7
7
  required: true
8
8
  type: choice
9
9
  options:
10
+ - ruby-2.6
10
11
  - ruby-2.7
11
12
  - ruby-3.0
12
13
  - ruby-3.1
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .ruby-version
12
12
  .matrixeval/docker-compose
13
13
  .matrixeval/gemfile_locks
14
+ coverage
15
+ .DS_Store
@@ -8,7 +8,7 @@
8
8
  # TODO
9
9
  # Offense count: 1
10
10
  # Cop supports --auto-correct.
11
- Lint/StringConversionInInterpolation:
11
+ Lint/RedundantStringCoercion:
12
12
  Enabled: false
13
13
 
14
14
  # Tests only
@@ -17,18 +17,10 @@ Lint/StringConversionInInterpolation:
17
17
  Lint/UnusedBlockArgument:
18
18
  Enabled: false
19
19
 
20
- Security/Eval:
21
- Exclude:
22
- - rest-man.windows.gemspec
23
-
24
- Lint/HandleExceptions:
20
+ Lint/SuppressedException:
25
21
  Exclude:
26
22
  - lib/restman/utils.rb
27
23
 
28
- Lint/UselessAccessModifier:
29
- Exclude:
30
- - lib/restman/windows/root_certs.rb
31
-
32
24
  # Offense count: 4
33
25
  # Cop supports --auto-correct.
34
26
  Style/Alias:
@@ -46,17 +38,6 @@ Style/AndOr:
46
38
  Style/BlockDelimiters:
47
39
  Enabled: false
48
40
 
49
- # Offense count: 48
50
- # Cop supports --auto-correct.
51
- # Configuration parameters: EnforcedStyle, SupportedStyles.
52
- Style/BracesAroundHashParameters:
53
- Enabled: false
54
-
55
- # Offense count: 1
56
- Naming/ClassAndModuleCamelCase:
57
- Exclude:
58
- - lib/restman/windows/root_certs.rb
59
-
60
41
  # Offense count: 2
61
42
  # Configuration parameters: EnforcedStyle, SupportedStyles.
62
43
  Style/ClassAndModuleChildren:
@@ -184,7 +165,7 @@ Style/HashSyntax:
184
165
  Style/IfUnlessModifier:
185
166
  Enabled: false
186
167
 
187
- Layout/IndentFirstHashElement:
168
+ Layout/FirstHashElementIndentation:
188
169
  Exclude:
189
170
  - 'spec/**/*.rb'
190
171
 
@@ -364,7 +345,7 @@ Style/UnlessElse:
364
345
  # TODO?
365
346
  # Offense count: 6
366
347
  # Cop supports --auto-correct.
367
- Style/UnneededPercentQ:
348
+ Style/RedundantPercentQ:
368
349
  Enabled: false
369
350
 
370
351
  # Offense count: 5
@@ -378,9 +359,3 @@ Style/WordArray:
378
359
  # Configuration parameters: EnforcedStyle, SupportedStyles.
379
360
  Style/BarePercentLiterals:
380
361
  Enabled: false
381
-
382
-
383
- Style/RescueStandardError:
384
- Exclude:
385
- - 'exe/restman'
386
- - 'lib/restman/windows/root_certs.rb'
data/AUTHORS CHANGED
@@ -20,7 +20,6 @@ Coda Hale
20
20
  Crawford
21
21
  Cyril Rohr
22
22
  Dan Mayer
23
- Dario Hamidi
24
23
  Darren Coxall
25
24
  David Backeus
26
25
  David Perkowski
@@ -37,6 +36,7 @@ Giovanni Cappellotto
37
36
  Greg Borenstein
38
37
  Harm Aarts
39
38
  Hiro Asari
39
+ Hopper Gee
40
40
  Hugh McGowan
41
41
  Ian Warshak
42
42
  Igor Zubkov
@@ -77,12 +77,14 @@ Michael Klett
77
77
  Michael Rykov
78
78
  Michael Westbom
79
79
  Mike Fletcher
80
+ Nathan Perry
80
81
  Nelson Elhage
81
82
  Nicholas Wieland
82
83
  Nick Hammond
83
84
  Nick Plante
84
85
  Niko Dittmann
85
86
  Nikolay Shebanov
87
+ Olle Jonsson
86
88
  Oscar Del Ben
87
89
  Pablo Astigarraga
88
90
  Paul Dlug
@@ -95,11 +97,13 @@ Richard Schneeman
95
97
  Rick Olson
96
98
  Robert Eanes
97
99
  Rodrigo Panachi
100
+ Ryan Guest
98
101
  Sam Norbury
99
102
  Samuel Cochran
100
103
  Syl Turner
101
104
  T. Watanabe
102
105
  Tekin
106
+ The Gitter Badger
103
107
  W. Andrew Loe III
104
108
  Waynn Lue
105
109
  Xavier Shay
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # v1.1.0
2
+
3
+ - Drop support for Ruby < 2.6
4
+ - Support Ruby 3.1, 3.2, JRuby-9.4
5
+ - Remove support for windows platform
6
+ - Support `write_timeout`, `ssl_timeout`, `keep_alive_timeout` option
7
+ - Support `max_retries` option
8
+ - Support `ssl_min_version` and `ssl_max_version` option
9
+ - Support `close_on_empty_response` option
10
+ - Support `local_host`, `local_port` option
11
+ - Add `AbstractRequest#sucess?`
12
+ - Move doc to seperate files
13
+ - Refactor most code with `ActiveMethod`
14
+
1
15
  # 1.0.0
2
16
 
3
17
  - Fork from rest-client and rename to rest-man
data/Gemfile CHANGED
@@ -8,4 +8,7 @@ group :development, :test do
8
8
  gem 'rake'
9
9
  gem 'byebug' unless RUBY_PLATFORM == 'java'
10
10
  gem 'ruby-debug' if RUBY_PLATFORM == 'java'
11
+ gem 'simplecov'
12
+ gem 'simplecov-cobertura'
13
+ gem 'rubycritic'
11
14
  end
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # REST Man -- simple DSL for accessing HTTP and REST resources
2
2
 
3
+ [![CI](https://github.com/rest-man/rest-man/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rest-man/rest-man/actions/workflows/ci.yml)
4
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f68e8752d2c740129b82394f973de025)](https://www.codacy.com/gh/rest-man/rest-man/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=rest-man/rest-man&amp;utm_campaign=Badge_Grade)
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f68e8752d2c740129b82394f973de025)](https://www.codacy.com/gh/rest-man/rest-man/dashboard?utm_source=github.com&utm_medium=referral&utm_content=rest-man/rest-man&utm_campaign=Badge_Coverage)
6
+
3
7
  A simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style
4
8
  of specifying actions: get, put, post, delete.
5
9
 
@@ -7,23 +11,17 @@ This is a fork version of [rest-client](https://github.com/rest-client/rest-clie
7
11
 
8
12
  ## Requirements
9
13
 
10
- MRI Ruby 2.0 and newer are supported. Alternative interpreters compatible with
11
- 2.0+ should work as well.
12
-
13
- Earlier Ruby versions such as 1.8.7, 1.9.2, and 1.9.3 are no longer supported. These
14
- versions no longer have any official support, and do not receive security
15
- updates.
14
+ Supported Ruby versions
16
15
 
17
- The rest-man gem depends on these other gems for usage at runtime:
16
+ | 2.6 | 2.7 | 3.0 | 3.1 | 3.2 | 3.3-Preview |
17
+ | ---- | ---- | ---- | ---- | ---- | ---- |
18
+ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
18
19
 
19
- * [mime-types](http://rubygems.org/gems/mime-types)
20
- * [netrc](http://rubygems.org/gems/netrc)
21
- * [http-accept](https://rubygems.org/gems/http-accept)
22
- * [http-cookie](https://rubygems.org/gems/http-cookie)
20
+ Supported JRuby versions
23
21
 
24
- There are also several development dependencies. It's recommended to use
25
- [bundler](http://bundler.io/) to manage these dependencies for hacking on
26
- rest-man.
22
+ | 9.3 | 9.4 |
23
+ | ---- | ---- |
24
+ | ✅ | ✅ |
27
25
 
28
26
  ## Usage: Raw URL
29
27
 
@@ -202,7 +200,7 @@ Other `OpenSSL::SSL::SSLError` errors are raised as is.
202
200
 
203
201
  By default, rest-man will follow HTTP 30x redirection requests.
204
202
 
205
- __New in 2.0:__ `RestMan::Response` exposes a `#history` method that returns
203
+ `RestMan::Response` exposes a `#history` method that returns
206
204
  a list of each response received in a redirection chain.
207
205
 
208
206
  ```ruby
@@ -224,12 +222,6 @@ a list of each response received in a redirection chain.
224
222
 
225
223
  To disable automatic redirection, set `:max_redirects => 0`.
226
224
 
227
- __New in 2.0:__ Prior versions of rest-man would raise
228
- `RestMan::MaxRedirectsReached`, with no easy way to access the server's
229
- response. In 2.0, rest-man raises the normal
230
- `RestMan::ExceptionWithResponse` as it would with any other non-HTTP-20x
231
- response.
232
-
233
225
  ```ruby
234
226
  >> RestMan::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1')
235
227
  => RestMan::Response 200 "{\n "args":..."
@@ -258,6 +250,14 @@ RestMan::Found: 302 Found
258
250
  => RestMan::Response 200 "{\n "args":..."
259
251
  ```
260
252
 
253
+ #### Manually set max retries
254
+
255
+ The default max_retries is 1. You can change it to any number you like.
256
+
257
+ ```ruby
258
+ RestMan::Request.execute(method: :get, url: 'http://httpbin.org', max_retires: 0)
259
+ ```
260
+
261
261
  ## Result handling
262
262
 
263
263
  The result of a `RestMan::Request` is a `RestMan::Response` object.
@@ -271,9 +271,9 @@ Response objects have several useful methods. (See the class rdoc for more detai
271
271
  - `Response#headers`: A hash of HTTP response headers
272
272
  - `Response#raw_headers`: A hash of HTTP response headers as unprocessed arrays
273
273
  - `Response#cookies`: A hash of HTTP cookies set by the server
274
- - `Response#cookie_jar`: <em>New in 1.8</em> An HTTP::CookieJar of cookies
274
+ - `Response#cookie_jar`: An HTTP::CookieJar of cookies
275
275
  - `Response#request`: The RestMan::Request object used to make the request
276
- - `Response#history`: <em>New in 2.0</em> If redirection was followed, a list of prior Response objects
276
+ - `Response#history`: If redirection was followed, a list of prior Response objects
277
277
 
278
278
  ```ruby
279
279
  RestMan.get('http://example.com')
@@ -602,7 +602,7 @@ use whatever proxy the system is configured to use:
602
602
  RestMan.proxy = ENV['http_proxy']
603
603
  ```
604
604
 
605
- __New in 2.0:__ Specify a per-request proxy by passing the :proxy option to
605
+ Specify a per-request proxy by passing the :proxy option to
606
606
  RestMan::Request. This will override any proxies set by environment variable
607
607
  or by the global `RestMan.proxy` value.
608
608
 
@@ -702,7 +702,7 @@ GET:
702
702
  {"outer"=>{"foo"=>"123", "bar"=>"456"}}
703
703
  ```
704
704
 
705
- __New in 2.0:__ The new `RestMan::ParamsArray` class allows callers to
705
+ The `RestMan::ParamsArray` class allows callers to
706
706
  provide ordering even to structured parameters. This is useful for unusual
707
707
  cases where the server treats the order of parameters as significant or you
708
708
  want to pass a particular key multiple times.
@@ -741,18 +741,18 @@ RestMan.delete 'http://example.com/resource', {:Authorization => 'Bearer cT0febF
741
741
 
742
742
  By default the timeout for a request is 60 seconds. Timeouts for your request can
743
743
  be adjusted by setting the `timeout:` to the number of seconds that you would like
744
- the request to wait. Setting `timeout:` will override both `read_timeout:` and `open_timeout:`.
744
+ the request to wait. Setting `timeout:` will override `read_timeout:`, `open_timeout:` and `write_timeout`.
745
745
 
746
746
  ```ruby
747
747
  RestMan::Request.execute(method: :get, url: 'http://example.com/resource',
748
748
  timeout: 120)
749
749
  ```
750
750
 
751
- Additionally, you can set `read_timeout:` and `open_timeout:` separately.
751
+ Additionally, you can set `read_timeout:`, `open_timeout:` and `write_timeout` separately.
752
752
 
753
753
  ```ruby
754
754
  RestMan::Request.execute(method: :get, url: 'http://example.com/resource',
755
- read_timeout: 120, open_timeout: 240)
755
+ read_timeout: 120, open_timeout: 240, write_timeout: 120)
756
756
  ```
757
757
 
758
758
  ## Cookies
@@ -772,13 +772,9 @@ response2 = RestMan.post(
772
772
  )
773
773
  # ...response body
774
774
  ```
775
- ### Full cookie jar support (new in 1.8)
775
+ ### Full cookie jar support
776
776
 
777
- The original cookie implementation was very naive and ignored most of the
778
- cookie RFC standards.
779
- __New in 1.8__: An HTTP::CookieJar of cookies
780
-
781
- Response objects now carry a cookie_jar method that exposes an HTTP::CookieJar
777
+ Response objects carry a cookie_jar method that exposes an HTTP::CookieJar
782
778
  of cookies, which supports full standards compliant behavior.
783
779
 
784
780
  ## SSL/TLS support
@@ -838,6 +834,3 @@ Released under the MIT License: https://opensource.org/licenses/MIT
838
834
 
839
835
  Photo of the International Space Station was produced by NASA and is in the
840
836
  public domain.
841
-
842
- Code for reading Windows root certificate store derived from work by Puppet;
843
- used under terms of the Apache License, Version 2.0.
data/Rakefile CHANGED
@@ -50,7 +50,7 @@ the following kind souls:
50
50
  end
51
51
 
52
52
  task :default do
53
- sh 'rake -T'
53
+ sh 'rake test'
54
54
  end
55
55
 
56
56
  def alias_task(alias_task, original)
@@ -61,64 +61,6 @@ alias_task(:test, :spec)
61
61
 
62
62
  ############################
63
63
 
64
- WindowsPlatforms = %w{x86-mingw32 x64-mingw32 x86-mswin32}
65
-
66
- namespace :all do
67
-
68
- desc "Build rest-man #{RestMan::VERSION} for all platforms"
69
- task :build => ['ruby:build'] + \
70
- WindowsPlatforms.map {|p| "windows:#{p}:build"}
71
-
72
- desc "Create tag v#{RestMan::VERSION} and for all platforms build and " \
73
- "push rest-man #{RestMan::VERSION} to Rubygems"
74
- task :release => ['build', 'ruby:release'] + \
75
- WindowsPlatforms.map {|p| "windows:#{p}:push"}
76
-
77
- end
78
-
79
- namespace :windows do
80
- spec_path = File.join(File.dirname(__FILE__), 'rest-man.windows.gemspec')
81
-
82
- WindowsPlatforms.each do |platform|
83
- namespace platform do
84
- gem_filename = "rest-man-#{RestMan::VERSION}-#{platform}.gem"
85
- base = File.dirname(__FILE__)
86
- pkg_dir = File.join(base, 'pkg')
87
- gem_file_path = File.join(pkg_dir, gem_filename)
88
-
89
- desc "Build #{gem_filename} into the pkg directory"
90
- task 'build' do
91
- orig_platform = ENV['BUILD_PLATFORM']
92
- begin
93
- ENV['BUILD_PLATFORM'] = platform
94
-
95
- sh("gem build -V #{spec_path}") do |ok, res|
96
- if ok
97
- FileUtils.mkdir_p(pkg_dir)
98
- FileUtils.mv(File.join(base, gem_filename), pkg_dir)
99
- Bundler.ui.confirm("rest-man #{RestMan::VERSION} " \
100
- "built to pkg/#{gem_filename}")
101
- else
102
- abort "Command `gem build` failed: #{res}"
103
- end
104
- end
105
-
106
- ensure
107
- ENV['BUILD_PLATFORM'] = orig_platform
108
- end
109
- end
110
-
111
- desc "Push #{gem_filename} to Rubygems"
112
- task 'push' do
113
- sh("gem push #{gem_file_path}")
114
- end
115
- end
116
- end
117
-
118
- end
119
-
120
- ############################
121
-
122
64
  require 'rdoc/task'
123
65
 
124
66
  Rake::RDocTask.new do |t|
@@ -0,0 +1,7 @@
1
+ Follow a redirection
2
+
3
+ [Parameters:]
4
+
5
+ - *new_args* (Hash) -- Start with this hash of arguments for the
6
+ redirection request. The hash will be mutated, so be sure to dup any
7
+ existing hash that should not be modified.
@@ -0,0 +1,24 @@
1
+ :call-seq:
2
+ beautify_headers(headers) -> hash
3
+
4
+ Convert headers hash into canonical form.
5
+
6
+ Header names will be converted to lowercase symbols with underscores
7
+ instead of hyphens.
8
+
9
+ Headers specified multiple times will be joined by comma and space,
10
+ except for Set-Cookie, which will always be an array.
11
+
12
+ Per RFC 2616, if a server sends multiple headers with the same key, they
13
+ MUST be able to be joined into a single header by a comma. However,
14
+ Set-Cookie (RFC 6265) cannot because commas are valid within cookie
15
+ definitions. The newer RFC 7230 notes (3.2.2) that Set-Cookie should be
16
+ handled as a special case.
17
+
18
+ http://tools.ietf.org/html/rfc2616#section-4.2
19
+ http://tools.ietf.org/html/rfc7230#section-3.2.2
20
+ http://tools.ietf.org/html/rfc6265
21
+
22
+ [Parameters:]
23
+
24
+ - *headers* (Hash)
@@ -0,0 +1,4 @@
1
+ :call-seq:
2
+ cookie_jar -> HTTP::CookieJar
3
+
4
+ Cookie jar extracted from response headers.
@@ -0,0 +1,12 @@
1
+ :call-seq:
2
+ cookies -> hash
3
+
4
+ Hash of cookies extracted from response headers.
5
+
6
+ NB: This will return only cookies whose domain matches this request, and
7
+ may not even return all of those cookies if there are duplicate names.
8
+ Use the full cookie_jar for more nuanced access.
9
+
10
+ [See Also:]
11
+
12
+ - #cookie_jar
@@ -0,0 +1,2 @@
1
+ Follow a redirection response, but change the HTTP method to GET and drop
2
+ the payload from the original request.
@@ -0,0 +1,2 @@
1
+ Follow a redirection response by making a new HTTP request to the
2
+ redirection target.
@@ -0,0 +1,2 @@
1
+ A hash of the headers, beautified with symbols and underscores.
2
+ e.g. "Content-type" will become :content_type.
@@ -0,0 +1,5 @@
1
+ [Parameters:]
2
+
3
+ - net_http_res (Net::HTTPResponse)
4
+ - request (RestMan::Request)
5
+ - start_time (Time)
@@ -0,0 +1,9 @@
1
+ Return the default behavior corresponding to the response code:
2
+
3
+ For 20x status codes: return the response itself
4
+
5
+ For 30x status codes:
6
+ 301, 302, 307: redirect GET / HEAD if there is a Location header
7
+ 303: redirect, changing method to GET, if there is a Location header
8
+
9
+ For all other responses, raise a response exception
@@ -0,0 +1,2 @@
1
+ Add a Proc to be called before each request in executed.
2
+ The proc parameters will be the http request and the request params.
@@ -0,0 +1,2 @@
1
+ Create a log that respond to << like a logger
2
+ param can be 'stdout', 'stderr', a string (then we will log to that file) or a logger (then we return it)
@@ -0,0 +1,6 @@
1
+ This is the base RestMan exception class. Rescue it if you want to
2
+ catch any exception that your request might raise
3
+ You can get the status code by e.http_code, or see anything about the
4
+ response via e.response.
5
+ For example, the entire result body (which is
6
+ probably an HTML error page) is e.response.
@@ -0,0 +1,4 @@
1
+ Base class for request timeouts.
2
+
3
+ NB: Previous releases of rest-man would raise RequestTimeout both for
4
+ HTTP 408 responses and for actual connection timeouts.
@@ -0,0 +1,4 @@
1
+ RestMan exception classes. TODO: move all exceptions into this module.
2
+
3
+ We will a create an exception for each status code, see
4
+ http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
@@ -0,0 +1,3 @@
1
+ Setup the log for RestMan calls.
2
+ Value should be a logger but can can be stdout, stderr, or a filename.
3
+ You can also configure logging by the environment variable RESTCLIENT_LOG.
@@ -0,0 +1,20 @@
1
+ [Parameters:]
2
+
3
+ - array (Array) An array of parameter key,value pairs. These
4
+ pairs may be 2 element arrays [key, value] or single element hashes
5
+ {key => value}. They may also be single element arrays to represent a
6
+ key with no value.
7
+
8
+
9
+
10
+ *Examples*:
11
+
12
+ ParamsArray.new([[:foo, 123], [:foo, 456], [:bar, 789]])
13
+
14
+ This will be encoded as "foo=123&foo=456&bar=789"
15
+
16
+ ParamsArray.new({foo: 123, bar: 456})
17
+
18
+ This is valid, but there's no reason not to just use the Hash directly
19
+ instead of a ParamsArray.
20
+
@@ -0,0 +1,4 @@
1
+ A pair may be:
2
+ - A single element hash, e.g. {foo: 'bar'}
3
+ - A two element array, e.g. ['foo', 'bar']
4
+ - A one element array, e.g. ['foo']
@@ -0,0 +1,11 @@
1
+ The ParamsArray class is used to represent an ordered list of [key, value]
2
+ pairs. Use this when you need to include a key multiple times or want
3
+ explicit control over parameter ordering.
4
+
5
+ Most of the request payload & parameter functions normally accept a Hash of
6
+ keys => values, which does not allow for duplicated keys.
7
+
8
+ [See Also:]
9
+
10
+ - RestMan::Utils.encode_query_string
11
+ - RestMan::Utils.flatten_params
@@ -0,0 +1,4 @@
1
+ :call-seq:
2
+ jruby? -> boolean
3
+
4
+ Return true if we are running on jruby.
@@ -0,0 +1,5 @@
1
+ :call-seq:
2
+ mac_mri? -> boolean
3
+
4
+ # Return true if we are running on a darwin-based Ruby platform. This will
5
+ # be false for jruby even on OS X.
@@ -0,0 +1,2 @@
1
+ A global proxy URL to use for all requests. This can be overridden on a
2
+ per-request basis by passing `:proxy` to RestMan::Request.
@@ -0,0 +1,5 @@
1
+ :call-seq:
2
+ proxy_set? -> boolean
3
+
4
+ Return whether RestMan.proxy was set explicitly. We use this to
5
+ differentiate between no value being set and a value explicitly set to nil.
@@ -0,0 +1,6 @@
1
+ [Parameters:]
2
+
3
+ - tempfile (Tempfile) -- The temporary file containing the body
4
+ - net_http_res (Net::HTTPResponse)
5
+ - request (RestMan::Request)
6
+ - start_time (Time)
@@ -0,0 +1,10 @@
1
+ The response from RestMan on a raw request looks like a string, but is
2
+ actually one of these. 99% of the time you're making a rest call all you
3
+ care about is the body, but on the occasion you want to fetch the
4
+ headers you can:
5
+
6
+ RestMan.get('http://example.com').headers[:content_type]
7
+
8
+ In addition, if you do not use the response as a string, you can access
9
+ a Tempfile object at res.file, which contains the path to the raw
10
+ downloaded request body.
@@ -0,0 +1,3 @@
1
+ :call-seq:
2
+ cookie_jar() -> HTTP::CookieJar
3
+
@@ -0,0 +1,11 @@
1
+ :call-seq:
2
+ cookies -> hash
3
+
4
+ Render a hash of key => value pairs for cookies in the Request#cookie_jar
5
+ that are valid for the Request#uri. This will not necessarily include all
6
+ cookies if there are duplicate keys. It's safer to use the cookie_jar
7
+ directly if that's a concern.
8
+
9
+ [See Also:]
10
+
11
+ - Request#cookie_jar
@@ -0,0 +1,5 @@
1
+ :call-seq:
2
+ default_headers -> Hash<Symbol, String>
3
+
4
+ Default headers set by RestMan. In addition to these headers, servers
5
+ will receive headers set by Net::HTTP, such as Accept-Encoding and Host.
@@ -0,0 +1,8 @@
1
+ :call-seq:
2
+ .default_ssl_cert_store -> OpenSSL::X509::Store
3
+
4
+ Return a certificate store that can be used to validate certificates with
5
+ the system certificate authorities. This will probably not do anything on
6
+ OS X, which monkey patches OpenSSL in terrible ways to insert its own
7
+ validation. On most *nix platforms, this will add the system certifcates
8
+ using OpenSSL::X509::Store#set_default_paths.