evil-client 0.3.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -11
  3. data/.gitignore +1 -0
  4. data/.rspec +0 -1
  5. data/.rubocop.yml +22 -19
  6. data/.travis.yml +1 -0
  7. data/CHANGELOG.md +251 -6
  8. data/LICENSE.txt +3 -1
  9. data/README.md +47 -81
  10. data/docs/helpers/body.md +93 -0
  11. data/docs/helpers/connection.md +19 -0
  12. data/docs/helpers/headers.md +72 -0
  13. data/docs/helpers/http_method.md +39 -0
  14. data/docs/helpers/let.md +14 -0
  15. data/docs/helpers/logger.md +24 -0
  16. data/docs/helpers/middleware.md +56 -0
  17. data/docs/helpers/operation.md +103 -0
  18. data/docs/helpers/option.md +50 -0
  19. data/docs/helpers/path.md +37 -0
  20. data/docs/helpers/query.md +59 -0
  21. data/docs/helpers/response.md +40 -0
  22. data/docs/helpers/scope.md +121 -0
  23. data/docs/helpers/security.md +102 -0
  24. data/docs/helpers/validate.md +68 -0
  25. data/docs/index.md +70 -78
  26. data/docs/license.md +5 -1
  27. data/docs/rspec.md +96 -0
  28. data/evil-client.gemspec +10 -8
  29. data/lib/evil/client.rb +126 -72
  30. data/lib/evil/client/builder.rb +47 -0
  31. data/lib/evil/client/builder/operation.rb +40 -0
  32. data/lib/evil/client/builder/scope.rb +31 -0
  33. data/lib/evil/client/chaining.rb +17 -0
  34. data/lib/evil/client/connection.rb +60 -20
  35. data/lib/evil/client/container.rb +66 -0
  36. data/lib/evil/client/container/operation.rb +23 -0
  37. data/lib/evil/client/container/scope.rb +28 -0
  38. data/lib/evil/client/exceptions/definition_error.rb +15 -0
  39. data/lib/evil/client/exceptions/name_error.rb +32 -0
  40. data/lib/evil/client/exceptions/response_error.rb +42 -0
  41. data/lib/evil/client/exceptions/type_error.rb +29 -0
  42. data/lib/evil/client/exceptions/validation_error.rb +27 -0
  43. data/lib/evil/client/formatter.rb +49 -0
  44. data/lib/evil/client/formatter/form.rb +45 -0
  45. data/lib/evil/client/formatter/multipart.rb +33 -0
  46. data/lib/evil/client/formatter/part.rb +66 -0
  47. data/lib/evil/client/formatter/text.rb +21 -0
  48. data/lib/evil/client/resolver.rb +84 -0
  49. data/lib/evil/client/resolver/body.rb +22 -0
  50. data/lib/evil/client/resolver/format.rb +30 -0
  51. data/lib/evil/client/resolver/headers.rb +46 -0
  52. data/lib/evil/client/resolver/http_method.rb +34 -0
  53. data/lib/evil/client/resolver/middleware.rb +36 -0
  54. data/lib/evil/client/resolver/query.rb +39 -0
  55. data/lib/evil/client/resolver/request.rb +96 -0
  56. data/lib/evil/client/resolver/response.rb +26 -0
  57. data/lib/evil/client/resolver/security.rb +113 -0
  58. data/lib/evil/client/resolver/uri.rb +35 -0
  59. data/lib/evil/client/rspec.rb +127 -0
  60. data/lib/evil/client/schema.rb +105 -0
  61. data/lib/evil/client/schema/operation.rb +177 -0
  62. data/lib/evil/client/schema/scope.rb +73 -0
  63. data/lib/evil/client/settings.rb +172 -0
  64. data/lib/evil/client/settings/validator.rb +64 -0
  65. data/mkdocs.yml +21 -15
  66. data/spec/features/custom_connection_spec.rb +17 -0
  67. data/spec/features/operation/middleware_spec.rb +50 -0
  68. data/spec/features/operation/options_spec.rb +71 -0
  69. data/spec/features/operation/request_spec.rb +94 -0
  70. data/spec/features/operation/response_spec.rb +48 -0
  71. data/spec/features/scope/options_spec.rb +52 -0
  72. data/spec/fixtures/locales/en.yml +16 -0
  73. data/spec/fixtures/test_client.rb +76 -0
  74. data/spec/spec_helper.rb +18 -6
  75. data/spec/support/fixtures_helper.rb +7 -0
  76. data/spec/unit/builder/operation_spec.rb +90 -0
  77. data/spec/unit/builder/scope_spec.rb +84 -0
  78. data/spec/unit/client_spec.rb +137 -0
  79. data/spec/unit/connection_spec.rb +78 -0
  80. data/spec/unit/container/operation_spec.rb +81 -0
  81. data/spec/unit/container/scope_spec.rb +61 -0
  82. data/spec/unit/container_spec.rb +107 -0
  83. data/spec/unit/exceptions/definition_error_spec.rb +15 -0
  84. data/spec/unit/exceptions/name_error_spec.rb +77 -0
  85. data/spec/unit/exceptions/response_error_spec.rb +22 -0
  86. data/spec/unit/exceptions/type_error_spec.rb +71 -0
  87. data/spec/unit/exceptions/validation_error_spec.rb +13 -0
  88. data/spec/unit/formatter/form_spec.rb +27 -0
  89. data/spec/unit/formatter/multipart_spec.rb +23 -0
  90. data/spec/unit/formatter/part_spec.rb +49 -0
  91. data/spec/unit/formatter/text_spec.rb +37 -0
  92. data/spec/unit/formatter_spec.rb +46 -0
  93. data/spec/unit/resolver/body_spec.rb +65 -0
  94. data/spec/unit/resolver/format_spec.rb +66 -0
  95. data/spec/unit/resolver/headers_spec.rb +93 -0
  96. data/spec/unit/resolver/http_method_spec.rb +67 -0
  97. data/spec/unit/resolver/middleware_spec.rb +83 -0
  98. data/spec/unit/resolver/query_spec.rb +85 -0
  99. data/spec/unit/resolver/request_spec.rb +121 -0
  100. data/spec/unit/resolver/response_spec.rb +64 -0
  101. data/spec/unit/resolver/security_spec.rb +156 -0
  102. data/spec/unit/resolver/uri_spec.rb +117 -0
  103. data/spec/unit/rspec_spec.rb +342 -0
  104. data/spec/unit/schema/operation_spec.rb +309 -0
  105. data/spec/unit/schema/scope_spec.rb +110 -0
  106. data/spec/unit/schema_spec.rb +157 -0
  107. data/spec/unit/settings/validator_spec.rb +128 -0
  108. data/spec/unit/settings_spec.rb +248 -0
  109. metadata +192 -135
  110. data/docs/base_url.md +0 -38
  111. data/docs/documentation.md +0 -9
  112. data/docs/headers.md +0 -59
  113. data/docs/http_method.md +0 -31
  114. data/docs/model.md +0 -173
  115. data/docs/operation.md +0 -0
  116. data/docs/overview.md +0 -0
  117. data/docs/path.md +0 -48
  118. data/docs/query.md +0 -99
  119. data/docs/responses.md +0 -66
  120. data/docs/security.md +0 -102
  121. data/docs/settings.md +0 -32
  122. data/lib/evil/client/connection/net_http.rb +0 -57
  123. data/lib/evil/client/dsl.rb +0 -127
  124. data/lib/evil/client/dsl/base.rb +0 -26
  125. data/lib/evil/client/dsl/files.rb +0 -37
  126. data/lib/evil/client/dsl/headers.rb +0 -16
  127. data/lib/evil/client/dsl/http_method.rb +0 -24
  128. data/lib/evil/client/dsl/operation.rb +0 -91
  129. data/lib/evil/client/dsl/operations.rb +0 -41
  130. data/lib/evil/client/dsl/path.rb +0 -25
  131. data/lib/evil/client/dsl/query.rb +0 -16
  132. data/lib/evil/client/dsl/response.rb +0 -61
  133. data/lib/evil/client/dsl/responses.rb +0 -29
  134. data/lib/evil/client/dsl/scope.rb +0 -27
  135. data/lib/evil/client/dsl/security.rb +0 -57
  136. data/lib/evil/client/dsl/verifier.rb +0 -35
  137. data/lib/evil/client/middleware.rb +0 -81
  138. data/lib/evil/client/middleware/base.rb +0 -11
  139. data/lib/evil/client/middleware/merge_security.rb +0 -20
  140. data/lib/evil/client/middleware/normalize_headers.rb +0 -17
  141. data/lib/evil/client/middleware/stringify_form.rb +0 -40
  142. data/lib/evil/client/middleware/stringify_json.rb +0 -19
  143. data/lib/evil/client/middleware/stringify_multipart.rb +0 -36
  144. data/lib/evil/client/middleware/stringify_multipart/part.rb +0 -36
  145. data/lib/evil/client/middleware/stringify_query.rb +0 -35
  146. data/lib/evil/client/operation.rb +0 -34
  147. data/lib/evil/client/operation/request.rb +0 -26
  148. data/lib/evil/client/operation/response.rb +0 -39
  149. data/lib/evil/client/operation/response_error.rb +0 -13
  150. data/lib/evil/client/operation/unexpected_response_error.rb +0 -19
  151. data/spec/features/instantiation_spec.rb +0 -68
  152. data/spec/features/middleware_spec.rb +0 -79
  153. data/spec/features/operation_with_documentation_spec.rb +0 -41
  154. data/spec/features/operation_with_files_spec.rb +0 -40
  155. data/spec/features/operation_with_form_body_spec.rb +0 -158
  156. data/spec/features/operation_with_headers_spec.rb +0 -99
  157. data/spec/features/operation_with_http_method_spec.rb +0 -45
  158. data/spec/features/operation_with_json_body_spec.rb +0 -156
  159. data/spec/features/operation_with_nested_responses_spec.rb +0 -95
  160. data/spec/features/operation_with_path_spec.rb +0 -47
  161. data/spec/features/operation_with_query_spec.rb +0 -84
  162. data/spec/features/operation_with_security_spec.rb +0 -228
  163. data/spec/features/scoping_spec.rb +0 -48
  164. data/spec/support/test_client.rb +0 -15
  165. data/spec/unit/evil/client/connection/net_http_spec.rb +0 -38
  166. data/spec/unit/evil/client/dsl/files_spec.rb +0 -37
  167. data/spec/unit/evil/client/dsl/operation_spec.rb +0 -374
  168. data/spec/unit/evil/client/dsl/operations_spec.rb +0 -29
  169. data/spec/unit/evil/client/dsl/scope_spec.rb +0 -32
  170. data/spec/unit/evil/client/dsl/security_spec.rb +0 -135
  171. data/spec/unit/evil/client/middleware/merge_security_spec.rb +0 -32
  172. data/spec/unit/evil/client/middleware/normalize_headers_spec.rb +0 -17
  173. data/spec/unit/evil/client/middleware/stringify_form_spec.rb +0 -63
  174. data/spec/unit/evil/client/middleware/stringify_json_spec.rb +0 -61
  175. data/spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb +0 -59
  176. data/spec/unit/evil/client/middleware/stringify_multipart_spec.rb +0 -62
  177. data/spec/unit/evil/client/middleware/stringify_query_spec.rb +0 -40
  178. data/spec/unit/evil/client/middleware_spec.rb +0 -46
  179. data/spec/unit/evil/client/operation/request_spec.rb +0 -49
  180. data/spec/unit/evil/client/operation/response_spec.rb +0 -63
@@ -1,40 +0,0 @@
1
- RSpec.describe Evil::Client::Middleware::StringifyQuery do
2
- let(:stack) { described_class.new(app) }
3
- let(:app) { double :app }
4
-
5
- def update!(env)
6
- @result = env
7
- end
8
-
9
- before { allow(app).to receive(:call) { |env| update! env } }
10
- subject { stack.call env, {}, {} }
11
-
12
- context "with a non-empty query:" do
13
- let(:env) do
14
- { query: { foo: :FOO, bar: [:BAR], baz: { qux: :QUX }, qux: nil } }
15
- end
16
-
17
- it "stringifies the query" do
18
- subject
19
- expect(@result[:query_string]).to eq "foo=FOO&bar[]=BAR&baz[qux]=QUX&qux="
20
- end
21
- end
22
-
23
- context "with empty query:" do
24
- let(:env) { { query: {} } }
25
-
26
- it "does nothing" do
27
- subject
28
- expect(@result).to eq env
29
- end
30
- end
31
-
32
- context "without a query:" do
33
- let(:env) { {} }
34
-
35
- it "does nothing" do
36
- subject
37
- expect(@result).to eq env
38
- end
39
- end
40
- end
@@ -1,46 +0,0 @@
1
- RSpec.describe Evil::Client::Middleware do
2
- before do
3
- class Test::Bar
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def call(env)
9
- @app.call(env) << " bar"
10
- end
11
- end
12
-
13
- class Test::Baz
14
- def initialize(app)
15
- @app = app
16
- end
17
-
18
- def call(env)
19
- @app.call(env) << " baz"
20
- end
21
- end
22
- end
23
-
24
- let(:connection) do
25
- double(:connection).tap do |conn|
26
- allow(conn).to receive(:call) { |value| value << " foo" }
27
- end
28
- end
29
-
30
- let(:middleware) do
31
- described_class.new do |settings|
32
- run Test::Baz if settings.baz
33
- run Test::Bar
34
- end
35
- end
36
-
37
- it "builds full stack parameterized by settings" do
38
- settings = double baz: false
39
- response = middleware.finalize(settings).call(connection).call("qux")
40
- expect(response).to eq "qux foo bar"
41
-
42
- settings = double baz: true
43
- response = middleware.finalize(settings).call(connection).call("qux")
44
- expect(response).to eq "qux foo bar baz"
45
- end
46
- end
@@ -1,49 +0,0 @@
1
- RSpec.describe Evil::Client::Operation::Request do
2
- before do
3
- class Test::Body < Evil::Struct
4
- attribute :foo
5
- end
6
-
7
- class Test::Query < Evil::Struct
8
- attribute :bar
9
- end
10
-
11
- class Test::Headers < Evil::Struct
12
- attribute :baz
13
- end
14
- end
15
-
16
- let(:request) { described_class.new(schema) }
17
- let(:file) { StringIO.new "Hi!" }
18
- let(:schema) do
19
- {
20
- format: "multipart",
21
- method: proc { "patch" },
22
- path: proc { |id:, **| "users/#{id}" },
23
- files: Evil::Client::DSL::Files.new { |file:, **| add file },
24
- security: Evil::Client::DSL::Security.new { basic_auth "qux", "abc" },
25
- query: Test::Query,
26
- body: Test::Body,
27
- headers: Test::Headers
28
- }
29
- end
30
-
31
- subject { request.build file: file, foo: :FOO, bar: :BAR, baz: :BAZ, id: 1 }
32
-
33
- it "builds final request env" do
34
- expect(subject).to eq \
35
- format: "multipart",
36
- http_method: "patch",
37
- path: "users/1",
38
- security: { headers: { "authorization" => "Basic cXV4OmFiYw==" } },
39
- files: [{
40
- file: file,
41
- type: MIME::Types["text/plain"].first,
42
- charset: "utf-8",
43
- filename: nil
44
- }],
45
- query: { bar: :BAR },
46
- body: { foo: :FOO },
47
- headers: { baz: :BAZ }
48
- end
49
- end
@@ -1,63 +0,0 @@
1
- RSpec.describe Evil::Client::Operation::Response do
2
- let(:response) { [status, {}, ["foo"]] }
3
- let(:schema) do
4
- {
5
- key: :find_user,
6
- doc: "http://example.com/users",
7
- responses: {
8
- success: {
9
- status: 200,
10
- coercer: proc { |body| body.upcase.to_sym },
11
- raise: false
12
- },
13
- error: {
14
- status: 400,
15
- coercer: proc { |body| body.upcase.to_sym },
16
- raise: true
17
- }
18
- }
19
- }
20
- end
21
-
22
- subject { described_class.new(schema).handle(response) }
23
-
24
- context "when response status should not cause an exception:" do
25
- let(:status) { 200 }
26
-
27
- it "returns coerced body" do
28
- expect(subject).to eq :FOO
29
- end
30
- end
31
-
32
- context "when response status should cause an exception:" do
33
- let(:status) { 400 }
34
-
35
- it "raises ResponseError with coerced response" do
36
- begin
37
- subject
38
- rescue Evil::Client::Operation::ResponseError => error
39
- expect(error.message).to include "find_user"
40
- expect(error.data).to eq :FOO
41
- else
42
- raise
43
- end
44
- end
45
- end
46
-
47
- context "when response status is unknown:" do
48
- let(:status) { 404 }
49
-
50
- it "raises UnexpectedResponseError with raw response" do
51
- begin
52
- subject
53
- rescue Evil::Client::Operation::UnexpectedResponseError => error
54
- expect(error.message).to include "find_user"
55
- expect(error.message).to include "http://example.com/users"
56
- expect(error.data).to eq "foo"
57
- expect(error.status).to eq 404
58
- else
59
- raise
60
- end
61
- end
62
- end
63
- end