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
@@ -1,108 +0,0 @@
1
- require_relative '_lib'
2
-
3
- describe RestMan::Exception do
4
- it "returns a 'message' equal to the class name if the message is not set, because 'message' should not be nil" do
5
- e = RestMan::Exception.new
6
- expect(e.message).to eq "RestMan::Exception"
7
- end
8
-
9
- it "returns the 'message' that was set" do
10
- e = RestMan::Exception.new
11
- message = "An explicitly set message"
12
- e.message = message
13
- expect(e.message).to eq message
14
- end
15
-
16
- it "sets the exception message to ErrorMessage" do
17
- expect(RestMan::ResourceNotFound.new.message).to eq 'Not Found'
18
- end
19
-
20
- it "contains exceptions in RestMan" do
21
- expect(RestMan::Unauthorized.new).to be_a_kind_of(RestMan::Exception)
22
- expect(RestMan::ServerBrokeConnection.new).to be_a_kind_of(RestMan::Exception)
23
- end
24
- end
25
-
26
- describe RestMan::ServerBrokeConnection do
27
- it "should have a default message of 'Server broke connection'" do
28
- e = RestMan::ServerBrokeConnection.new
29
- expect(e.message).to eq 'Server broke connection'
30
- end
31
- end
32
-
33
- describe RestMan::RequestFailed do
34
- before do
35
- @response = double('HTTP Response', :code => '502')
36
- end
37
-
38
- it "stores the http response on the exception" do
39
- response = "response"
40
- begin
41
- raise RestMan::RequestFailed, response
42
- rescue RestMan::RequestFailed => e
43
- expect(e.response).to eq response
44
- end
45
- end
46
-
47
- it "http_code convenience method for fetching the code as an integer" do
48
- expect(RestMan::RequestFailed.new(@response).http_code).to eq 502
49
- end
50
-
51
- it "http_body convenience method for fetching the body (decoding when necessary)" do
52
- expect(RestMan::RequestFailed.new(@response).http_code).to eq 502
53
- expect(RestMan::RequestFailed.new(@response).message).to eq 'HTTP status code 502'
54
- end
55
-
56
- it "shows the status code in the message" do
57
- expect(RestMan::RequestFailed.new(@response).to_s).to match(/502/)
58
- end
59
- end
60
-
61
- describe RestMan::ResourceNotFound do
62
- it "also has the http response attached" do
63
- response = "response"
64
- begin
65
- raise RestMan::ResourceNotFound, response
66
- rescue RestMan::ResourceNotFound => e
67
- expect(e.response).to eq response
68
- end
69
- end
70
-
71
- it 'stores the body on the response of the exception' do
72
- body = "body"
73
- stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
74
- begin
75
- RestMan.get "www.example.com"
76
- raise
77
- rescue RestMan::ResourceNotFound => e
78
- expect(e.response.body).to eq body
79
- end
80
- end
81
- end
82
-
83
- describe "backwards compatibility" do
84
- it 'aliases RestMan::NotFound as ResourceNotFound' do
85
- expect(RestMan::ResourceNotFound).to eq RestMan::NotFound
86
- end
87
-
88
- it 'aliases old names for HTTP 413, 414, 416' do
89
- expect(RestMan::RequestEntityTooLarge).to eq RestMan::PayloadTooLarge
90
- expect(RestMan::RequestURITooLong).to eq RestMan::URITooLong
91
- expect(RestMan::RequestedRangeNotSatisfiable).to eq RestMan::RangeNotSatisfiable
92
- end
93
-
94
- it 'subclasses NotFound from RequestFailed, ExceptionWithResponse' do
95
- expect(RestMan::NotFound).to be < RestMan::RequestFailed
96
- expect(RestMan::NotFound).to be < RestMan::ExceptionWithResponse
97
- end
98
-
99
- it 'subclasses timeout from RestMan::RequestTimeout, RequestFailed, EWR' do
100
- expect(RestMan::Exceptions::OpenTimeout).to be < RestMan::Exceptions::Timeout
101
- expect(RestMan::Exceptions::ReadTimeout).to be < RestMan::Exceptions::Timeout
102
-
103
- expect(RestMan::Exceptions::Timeout).to be < RestMan::RequestTimeout
104
- expect(RestMan::Exceptions::Timeout).to be < RestMan::RequestFailed
105
- expect(RestMan::Exceptions::Timeout).to be < RestMan::ExceptionWithResponse
106
- end
107
-
108
- end
@@ -1,22 +0,0 @@
1
- require_relative '../_lib'
2
-
3
- describe 'RestMan::Windows::RootCerts',
4
- :if => RestMan::Platform.windows? do
5
- let(:x509_store) { RestMan::Windows::RootCerts.instance.to_a }
6
-
7
- it 'should return at least one X509 certificate' do
8
- expect(x509_store.to_a.size).to be >= 1
9
- end
10
-
11
- it 'should return an X509 certificate with a subject' do
12
- x509 = x509_store.first
13
-
14
- expect(x509.subject.to_s).to match(/CN=.*/)
15
- end
16
-
17
- it 'should return X509 certificate objects' do
18
- x509_store.each do |cert|
19
- expect(cert).to be_a(OpenSSL::X509::Certificate)
20
- end
21
- end
22
- end