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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-man
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hopper Gee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-19 00:00:00.000000000 Z
11
+ date: 2023-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webmock
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '0.49'
101
+ version: 1.50.2
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '0.49'
108
+ version: 1.50.2
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: http-accept
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +152,7 @@ dependencies:
152
152
  requirements:
153
153
  - - ">="
154
154
  - !ruby/object:Gem::Version
155
- version: '1.16'
155
+ version: '3.0'
156
156
  - - "<"
157
157
  - !ruby/object:Gem::Version
158
158
  version: '4.0'
@@ -162,7 +162,7 @@ dependencies:
162
162
  requirements:
163
163
  - - ">="
164
164
  - !ruby/object:Gem::Version
165
- version: '1.16'
165
+ version: '3.0'
166
166
  - - "<"
167
167
  - !ruby/object:Gem::Version
168
168
  version: '4.0'
@@ -180,6 +180,20 @@ dependencies:
180
180
  - - "~>"
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0.8'
183
+ - !ruby/object:Gem::Dependency
184
+ name: active_method
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '1.3'
190
+ type: :runtime
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: '1.3'
183
197
  description: 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework
184
198
  style of specifying actions: get, put, post, delete.'
185
199
  email: hopper.gee@hey.com
@@ -190,7 +204,7 @@ extra_rdoc_files:
190
204
  - README.md
191
205
  - CHANGELOG.md
192
206
  files:
193
- - ".github/workflows/multi-matrix-test.yml"
207
+ - ".github/workflows/ci.yml"
194
208
  - ".github/workflows/single-matrix-test.yml"
195
209
  - ".gitignore"
196
210
  - ".mailmap"
@@ -204,23 +218,103 @@ files:
204
218
  - LICENSE
205
219
  - README.md
206
220
  - Rakefile
221
+ - _doc/lib/restman.rdoc
222
+ - _doc/lib/restman/abstract_response/_follow_redirection.rdoc
223
+ - _doc/lib/restman/abstract_response/beautify_headers.rdoc
224
+ - _doc/lib/restman/abstract_response/cookie_jar.rdoc
225
+ - _doc/lib/restman/abstract_response/cookies.rdoc
226
+ - _doc/lib/restman/abstract_response/follow_get_redirection.rdoc
227
+ - _doc/lib/restman/abstract_response/follow_redirection.rdoc
228
+ - _doc/lib/restman/abstract_response/headers.rdoc
229
+ - _doc/lib/restman/abstract_response/response_set_vars.rdoc
230
+ - _doc/lib/restman/abstract_response/return.rdoc
231
+ - _doc/lib/restman/add_before_execution_proc.rdoc
232
+ - _doc/lib/restman/create_log.rdoc
233
+ - _doc/lib/restman/exception.rdoc
234
+ - _doc/lib/restman/exceptions.rdoc
235
+ - _doc/lib/restman/exceptions/timeout.rdoc
236
+ - _doc/lib/restman/log=.rdoc
237
+ - _doc/lib/restman/params_array.rdoc
238
+ - _doc/lib/restman/params_array/new.rdoc
239
+ - _doc/lib/restman/params_array/process_pair.rdoc
240
+ - _doc/lib/restman/platform/jruby?.rdoc
241
+ - _doc/lib/restman/platform/mac_mri?.rdoc
242
+ - _doc/lib/restman/proxy.rdoc
243
+ - _doc/lib/restman/proxy_set?.rdoc
244
+ - _doc/lib/restman/raw_response.rdoc
245
+ - _doc/lib/restman/raw_response/new.rdoc
246
+ - _doc/lib/restman/request.rdoc
247
+ - _doc/lib/restman/request/cookie_jar.rdoc
248
+ - _doc/lib/restman/request/cookies.rdoc
249
+ - _doc/lib/restman/request/default_headers.rdoc
250
+ - _doc/lib/restman/request/default_ssl_cert_store.rdoc
251
+ - _doc/lib/restman/request/init/cookie_jar.rdoc
252
+ - _doc/lib/restman/request/init/http_method.rdoc
253
+ - _doc/lib/restman/request/make_cookie_header.rdoc
254
+ - _doc/lib/restman/request/make_headers.rdoc
255
+ - _doc/lib/restman/request/maybe_convert_extension.rdoc
256
+ - _doc/lib/restman/request/process_result.rdoc
257
+ - _doc/lib/restman/request/proxy_uri.rdoc
258
+ - _doc/lib/restman/request/stringify_headers.rdoc
259
+ - _doc/lib/restman/request/use_ssl.rdoc
260
+ - _doc/lib/restman/reset_before_execution_procs.rdoc
261
+ - _doc/lib/restman/resource.rdoc
262
+ - _doc/lib/restman/resource/[].rdoc
263
+ - _doc/lib/restman/response/body.rdoc
264
+ - _doc/lib/restman/response/create.rdoc
265
+ - _doc/lib/restman/response/fix_encoding.rdoc
266
+ - _doc/lib/restman/statuses.rdoc
267
+ - _doc/lib/restman/utils/cgi_parse_header.rdoc
268
+ - _doc/lib/restman/utils/encode_query_string.rdoc
269
+ - _doc/lib/restman/utils/escape.rdoc
270
+ - _doc/lib/restman/utils/flatten_params.rdoc
271
+ - _doc/lib/restman/utils/get_encoding_from_headers.rdoc
272
+ - bin/console
207
273
  - exe/restman
208
274
  - lib/rest-man.rb
209
275
  - lib/rest_man.rb
210
276
  - lib/restman.rb
211
277
  - lib/restman/abstract_response.rb
212
- - lib/restman/exceptions.rb
278
+ - lib/restman/exception.rb
279
+ - lib/restman/exceptions/exception_with_response.rb
280
+ - lib/restman/exceptions/exceptions_map.rb
281
+ - lib/restman/exceptions/request_failed.rb
282
+ - lib/restman/exceptions/server_broke_connection.rb
283
+ - lib/restman/exceptions/timeout.rb
213
284
  - lib/restman/params_array.rb
285
+ - lib/restman/params_array/process_pair.rb
214
286
  - lib/restman/payload.rb
287
+ - lib/restman/payload/base.rb
288
+ - lib/restman/payload/multipart.rb
289
+ - lib/restman/payload/multipart/write_content_disposition.rb
290
+ - lib/restman/payload/streamed.rb
291
+ - lib/restman/payload/url_encoded.rb
215
292
  - lib/restman/platform.rb
216
293
  - lib/restman/raw_response.rb
217
294
  - lib/restman/request.rb
295
+ - lib/restman/request/default_ssl_cert_store.rb
296
+ - lib/restman/request/fetch_body_to_tempfile.rb
297
+ - lib/restman/request/init.rb
298
+ - lib/restman/request/init/cookie_jar.rb
299
+ - lib/restman/request/init/ssl_opts.rb
300
+ - lib/restman/request/init/url.rb
301
+ - lib/restman/request/init/url/add_query_from_headers.rb
302
+ - lib/restman/request/init/url/normalize_url.rb
303
+ - lib/restman/request/log_request.rb
304
+ - lib/restman/request/make_cookie_header.rb
305
+ - lib/restman/request/make_headers.rb
306
+ - lib/restman/request/maybe_convert_extension.rb
307
+ - lib/restman/request/net_http_object.rb
308
+ - lib/restman/request/process_result.rb
309
+ - lib/restman/request/proxy_uri.rb
310
+ - lib/restman/request/stringify_headers.rb
311
+ - lib/restman/request/transmit.rb
218
312
  - lib/restman/resource.rb
219
313
  - lib/restman/response.rb
314
+ - lib/restman/statuses.rb
315
+ - lib/restman/statuses_compatibility.rb
220
316
  - lib/restman/utils.rb
221
317
  - lib/restman/version.rb
222
- - lib/restman/windows.rb
223
- - lib/restman/windows/root_certs.rb
224
318
  - matrixeval.yml
225
319
  - rest-man.gemspec
226
320
  - spec/ISS.jpg
@@ -255,17 +349,28 @@ files:
255
349
  - spec/spec_helper.rb
256
350
  - spec/unit/_lib.rb
257
351
  - spec/unit/abstract_response_spec.rb
258
- - spec/unit/exceptions_spec.rb
352
+ - spec/unit/exception_spec.rb
353
+ - spec/unit/exceptions/backwards_campatibility_spec.rb
354
+ - spec/unit/exceptions/exceptions_map_spec.rb
355
+ - spec/unit/exceptions/request_failed_spec.rb
356
+ - spec/unit/exceptions/server_broke_connection_spec.rb
357
+ - spec/unit/exceptions/timeout_spec.rb
358
+ - spec/unit/params_array/process_pair_spec.rb
259
359
  - spec/unit/params_array_spec.rb
360
+ - spec/unit/payload/multipart_spec.rb
361
+ - spec/unit/payload/streamed_spec.rb
362
+ - spec/unit/payload/url_encoded_spec.rb
260
363
  - spec/unit/payload_spec.rb
261
364
  - spec/unit/raw_response_spec.rb
365
+ - spec/unit/request/init/url/add_query_from_headers_spec.rb
366
+ - spec/unit/request/init/url/normalize_url_spec.rb
367
+ - spec/unit/request/init_spec.rb
262
368
  - spec/unit/request2_spec.rb
263
369
  - spec/unit/request_spec.rb
264
370
  - spec/unit/resource_spec.rb
265
371
  - spec/unit/response_spec.rb
266
372
  - spec/unit/restclient_spec.rb
267
373
  - spec/unit/utils_spec.rb
268
- - spec/unit/windows/root_certs_spec.rb
269
374
  homepage: https://github.com/rest-man/rest-man
270
375
  licenses:
271
376
  - MIT
@@ -278,14 +383,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
383
  requirements:
279
384
  - - ">="
280
385
  - !ruby/object:Gem::Version
281
- version: 2.0.0
386
+ version: 2.6.0
282
387
  required_rubygems_version: !ruby/object:Gem::Requirement
283
388
  requirements:
284
389
  - - ">="
285
390
  - !ruby/object:Gem::Version
286
391
  version: '0'
287
392
  requirements: []
288
- rubygems_version: 3.1.6
393
+ rubygems_version: 3.3.7
289
394
  signing_key:
290
395
  specification_version: 4
291
396
  summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
@@ -323,14 +428,25 @@ test_files:
323
428
  - spec/spec_helper.rb
324
429
  - spec/unit/_lib.rb
325
430
  - spec/unit/abstract_response_spec.rb
326
- - spec/unit/exceptions_spec.rb
431
+ - spec/unit/exception_spec.rb
432
+ - spec/unit/exceptions/backwards_campatibility_spec.rb
433
+ - spec/unit/exceptions/exceptions_map_spec.rb
434
+ - spec/unit/exceptions/request_failed_spec.rb
435
+ - spec/unit/exceptions/server_broke_connection_spec.rb
436
+ - spec/unit/exceptions/timeout_spec.rb
437
+ - spec/unit/params_array/process_pair_spec.rb
327
438
  - spec/unit/params_array_spec.rb
439
+ - spec/unit/payload/multipart_spec.rb
440
+ - spec/unit/payload/streamed_spec.rb
441
+ - spec/unit/payload/url_encoded_spec.rb
328
442
  - spec/unit/payload_spec.rb
329
443
  - spec/unit/raw_response_spec.rb
444
+ - spec/unit/request/init/url/add_query_from_headers_spec.rb
445
+ - spec/unit/request/init/url/normalize_url_spec.rb
446
+ - spec/unit/request/init_spec.rb
330
447
  - spec/unit/request2_spec.rb
331
448
  - spec/unit/request_spec.rb
332
449
  - spec/unit/resource_spec.rb
333
450
  - spec/unit/response_spec.rb
334
451
  - spec/unit/restclient_spec.rb
335
452
  - spec/unit/utils_spec.rb
336
- - spec/unit/windows/root_certs_spec.rb
@@ -1,238 +0,0 @@
1
- module RestMan
2
-
3
- # Hash of HTTP status code => message.
4
- #
5
- # 1xx: Informational - Request received, continuing process
6
- # 2xx: Success - The action was successfully received, understood, and
7
- # accepted
8
- # 3xx: Redirection - Further action must be taken in order to complete the
9
- # request
10
- # 4xx: Client Error - The request contains bad syntax or cannot be fulfilled
11
- # 5xx: Server Error - The server failed to fulfill an apparently valid
12
- # request
13
- #
14
- # @see
15
- # http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
16
- #
17
- STATUSES = {100 => 'Continue',
18
- 101 => 'Switching Protocols',
19
- 102 => 'Processing', #WebDAV
20
-
21
- 200 => 'OK',
22
- 201 => 'Created',
23
- 202 => 'Accepted',
24
- 203 => 'Non-Authoritative Information', # http/1.1
25
- 204 => 'No Content',
26
- 205 => 'Reset Content',
27
- 206 => 'Partial Content',
28
- 207 => 'Multi-Status', #WebDAV
29
- 208 => 'Already Reported', # RFC5842
30
- 226 => 'IM Used', # RFC3229
31
-
32
- 300 => 'Multiple Choices',
33
- 301 => 'Moved Permanently',
34
- 302 => 'Found',
35
- 303 => 'See Other', # http/1.1
36
- 304 => 'Not Modified',
37
- 305 => 'Use Proxy', # http/1.1
38
- 306 => 'Switch Proxy', # no longer used
39
- 307 => 'Temporary Redirect', # http/1.1
40
- 308 => 'Permanent Redirect', # RFC7538
41
-
42
- 400 => 'Bad Request',
43
- 401 => 'Unauthorized',
44
- 402 => 'Payment Required',
45
- 403 => 'Forbidden',
46
- 404 => 'Not Found',
47
- 405 => 'Method Not Allowed',
48
- 406 => 'Not Acceptable',
49
- 407 => 'Proxy Authentication Required',
50
- 408 => 'Request Timeout',
51
- 409 => 'Conflict',
52
- 410 => 'Gone',
53
- 411 => 'Length Required',
54
- 412 => 'Precondition Failed',
55
- 413 => 'Payload Too Large', # RFC7231 (renamed, see below)
56
- 414 => 'URI Too Long', # RFC7231 (renamed, see below)
57
- 415 => 'Unsupported Media Type',
58
- 416 => 'Range Not Satisfiable', # RFC7233 (renamed, see below)
59
- 417 => 'Expectation Failed',
60
- 418 => 'I\'m A Teapot', #RFC2324
61
- 421 => 'Too Many Connections From This IP',
62
- 422 => 'Unprocessable Entity', #WebDAV
63
- 423 => 'Locked', #WebDAV
64
- 424 => 'Failed Dependency', #WebDAV
65
- 425 => 'Unordered Collection', #WebDAV
66
- 426 => 'Upgrade Required',
67
- 428 => 'Precondition Required', #RFC6585
68
- 429 => 'Too Many Requests', #RFC6585
69
- 431 => 'Request Header Fields Too Large', #RFC6585
70
- 449 => 'Retry With', #Microsoft
71
- 450 => 'Blocked By Windows Parental Controls', #Microsoft
72
-
73
- 500 => 'Internal Server Error',
74
- 501 => 'Not Implemented',
75
- 502 => 'Bad Gateway',
76
- 503 => 'Service Unavailable',
77
- 504 => 'Gateway Timeout',
78
- 505 => 'HTTP Version Not Supported',
79
- 506 => 'Variant Also Negotiates',
80
- 507 => 'Insufficient Storage', #WebDAV
81
- 508 => 'Loop Detected', # RFC5842
82
- 509 => 'Bandwidth Limit Exceeded', #Apache
83
- 510 => 'Not Extended',
84
- 511 => 'Network Authentication Required', # RFC6585
85
- }
86
-
87
- STATUSES_COMPATIBILITY = {
88
- # The RFCs all specify "Not Found", but "Resource Not Found" was used in
89
- # earlier RestMan releases.
90
- 404 => ['ResourceNotFound'],
91
-
92
- # HTTP 413 was renamed to "Payload Too Large" in RFC7231.
93
- 413 => ['RequestEntityTooLarge'],
94
-
95
- # HTTP 414 was renamed to "URI Too Long" in RFC7231.
96
- 414 => ['RequestURITooLong'],
97
-
98
- # HTTP 416 was renamed to "Range Not Satisfiable" in RFC7233.
99
- 416 => ['RequestedRangeNotSatisfiable'],
100
- }
101
-
102
-
103
- # This is the base RestMan exception class. Rescue it if you want to
104
- # catch any exception that your request might raise
105
- # You can get the status code by e.http_code, or see anything about the
106
- # response via e.response.
107
- # For example, the entire result body (which is
108
- # probably an HTML error page) is e.response.
109
- class Exception < RuntimeError
110
- attr_accessor :response
111
- attr_accessor :original_exception
112
- attr_writer :message
113
-
114
- def initialize response = nil, initial_response_code = nil
115
- @response = response
116
- @message = nil
117
- @initial_response_code = initial_response_code
118
- end
119
-
120
- def http_code
121
- # return integer for compatibility
122
- if @response
123
- @response.code.to_i
124
- else
125
- @initial_response_code
126
- end
127
- end
128
-
129
- def http_headers
130
- @response.headers if @response
131
- end
132
-
133
- def http_body
134
- @response.body if @response
135
- end
136
-
137
- def to_s
138
- message
139
- end
140
-
141
- def message
142
- @message || default_message
143
- end
144
-
145
- def default_message
146
- self.class.name
147
- end
148
- end
149
-
150
- # Compatibility
151
- class ExceptionWithResponse < RestMan::Exception
152
- end
153
-
154
- # The request failed with an error code not managed by the code
155
- class RequestFailed < ExceptionWithResponse
156
-
157
- def default_message
158
- "HTTP status code #{http_code}"
159
- end
160
-
161
- def to_s
162
- message
163
- end
164
- end
165
-
166
- # RestMan exception classes. TODO: move all exceptions into this module.
167
- #
168
- # We will a create an exception for each status code, see
169
- # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
170
- #
171
- module Exceptions
172
- # Map http status codes to the corresponding exception class
173
- EXCEPTIONS_MAP = {}
174
- end
175
-
176
- # Create HTTP status exception classes
177
- STATUSES.each_pair do |code, message|
178
- klass = Class.new(RequestFailed) do
179
- send(:define_method, :default_message) {"#{http_code ? "#{http_code} " : ''}#{message}"}
180
- end
181
- klass_constant = const_set(message.delete(' \-\''), klass)
182
- Exceptions::EXCEPTIONS_MAP[code] = klass_constant
183
- end
184
-
185
- # Create HTTP status exception classes used for backwards compatibility
186
- STATUSES_COMPATIBILITY.each_pair do |code, compat_list|
187
- klass = Exceptions::EXCEPTIONS_MAP.fetch(code)
188
- compat_list.each do |old_name|
189
- const_set(old_name, klass)
190
- end
191
- end
192
-
193
- module Exceptions
194
- # We have to split the Exceptions module like we do here because the
195
- # EXCEPTIONS_MAP is under Exceptions, but we depend on
196
- # RestMan::RequestTimeout below.
197
-
198
- # Base class for request timeouts.
199
- #
200
- # NB: Previous releases of rest-man would raise RequestTimeout both for
201
- # HTTP 408 responses and for actual connection timeouts.
202
- class Timeout < RestMan::RequestTimeout
203
- def initialize(message=nil, original_exception=nil)
204
- super(nil, nil)
205
- self.message = message if message
206
- self.original_exception = original_exception if original_exception
207
- end
208
- end
209
-
210
- # Timeout when connecting to a server. Typically wraps Net::OpenTimeout (in
211
- # ruby 2.0 or greater).
212
- class OpenTimeout < Timeout
213
- def default_message
214
- 'Timed out connecting to server'
215
- end
216
- end
217
-
218
- # Timeout when reading from a server. Typically wraps Net::ReadTimeout (in
219
- # ruby 2.0 or greater).
220
- class ReadTimeout < Timeout
221
- def default_message
222
- 'Timed out reading data from server'
223
- end
224
- end
225
- end
226
-
227
-
228
- # The server broke the connection prior to the request completing. Usually
229
- # this means it crashed, or sometimes that your network connection was
230
- # severed before it could complete.
231
- class ServerBrokeConnection < RestMan::Exception
232
- def initialize(message = 'Server broke connection')
233
- super nil, nil
234
- self.message = message
235
- end
236
- end
237
-
238
- end
@@ -1,105 +0,0 @@
1
- require 'openssl'
2
- require 'ffi'
3
-
4
- # Adapted from Puppet, Copyright (c) Puppet Labs Inc,
5
- # licensed under the Apache License, Version 2.0.
6
- #
7
- # https://github.com/puppetlabs/puppet/blob/bbe30e0a/lib/puppet/util/windows/root_certs.rb
8
-
9
- # Represents a collection of trusted root certificates.
10
- #
11
- # @api public
12
- class RestMan::Windows::RootCerts
13
- include Enumerable
14
- extend FFI::Library
15
-
16
- typedef :ulong, :dword
17
- typedef :uintptr_t, :handle
18
-
19
- def initialize(roots)
20
- @roots = roots
21
- end
22
-
23
- # Enumerates each root certificate.
24
- # @yieldparam cert [OpenSSL::X509::Certificate] each root certificate
25
- # @api public
26
- def each
27
- @roots.each {|cert| yield cert}
28
- end
29
-
30
- # Returns a new instance.
31
- # @return [RestMan::Windows::RootCerts] object constructed from current root certificates
32
- def self.instance
33
- new(self.load_certs)
34
- end
35
-
36
- # Returns an array of root certificates.
37
- #
38
- # @return [Array<[OpenSSL::X509::Certificate]>] an array of root certificates
39
- # @api private
40
- def self.load_certs
41
- certs = []
42
-
43
- # This is based on a patch submitted to openssl:
44
- # http://www.mail-archive.com/openssl-dev@openssl.org/msg26958.html
45
- ptr = FFI::Pointer::NULL
46
- store = CertOpenSystemStoreA(nil, "ROOT")
47
- begin
48
- while (ptr = CertEnumCertificatesInStore(store, ptr)) and not ptr.null?
49
- context = CERT_CONTEXT.new(ptr)
50
- cert_buf = context[:pbCertEncoded].read_bytes(context[:cbCertEncoded])
51
- begin
52
- certs << OpenSSL::X509::Certificate.new(cert_buf)
53
- rescue => detail
54
- warn("Failed to import root certificate: #{detail.inspect}")
55
- end
56
- end
57
- ensure
58
- CertCloseStore(store, 0)
59
- end
60
-
61
- certs
62
- end
63
-
64
- private
65
-
66
- # typedef ULONG_PTR HCRYPTPROV_LEGACY;
67
- # typedef void *HCERTSTORE;
68
-
69
- class CERT_CONTEXT < FFI::Struct
70
- layout(
71
- :dwCertEncodingType, :dword,
72
- :pbCertEncoded, :pointer,
73
- :cbCertEncoded, :dword,
74
- :pCertInfo, :pointer,
75
- :hCertStore, :handle
76
- )
77
- end
78
-
79
- # HCERTSTORE
80
- # WINAPI
81
- # CertOpenSystemStoreA(
82
- # __in_opt HCRYPTPROV_LEGACY hProv,
83
- # __in LPCSTR szSubsystemProtocol
84
- # );
85
- ffi_lib :crypt32
86
- attach_function :CertOpenSystemStoreA, [:pointer, :string], :handle
87
-
88
- # PCCERT_CONTEXT
89
- # WINAPI
90
- # CertEnumCertificatesInStore(
91
- # __in HCERTSTORE hCertStore,
92
- # __in_opt PCCERT_CONTEXT pPrevCertContext
93
- # );
94
- ffi_lib :crypt32
95
- attach_function :CertEnumCertificatesInStore, [:handle, :pointer], :pointer
96
-
97
- # BOOL
98
- # WINAPI
99
- # CertCloseStore(
100
- # __in_opt HCERTSTORE hCertStore,
101
- # __in DWORD dwFlags
102
- # );
103
- ffi_lib :crypt32
104
- attach_function :CertCloseStore, [:handle, :dword], :bool
105
- end
@@ -1,8 +0,0 @@
1
- module RestMan
2
- module Windows
3
- end
4
- end
5
-
6
- if RestMan::Platform.windows?
7
- require_relative './windows/root_certs'
8
- end