endpoint-flux 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/CONTRIBUTING.md +18 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +37 -0
  6. data/README.md +607 -0
  7. data/circle.yml +14 -0
  8. data/endpoint_flux.gemspec +18 -0
  9. data/lib/endpoint_flux.rb +20 -0
  10. data/lib/endpoint_flux/class_loader.rb +58 -0
  11. data/lib/endpoint_flux/config.rb +85 -0
  12. data/lib/endpoint_flux/config/interceptor.rb +23 -0
  13. data/lib/endpoint_flux/config/middleware.rb +38 -0
  14. data/lib/endpoint_flux/config/rescue_from.rb +28 -0
  15. data/lib/endpoint_flux/endpoint.rb +81 -0
  16. data/lib/endpoint_flux/exceptions.rb +10 -0
  17. data/lib/endpoint_flux/exceptions/base.rb +21 -0
  18. data/lib/endpoint_flux/exceptions/forbidden.rb +12 -0
  19. data/lib/endpoint_flux/exceptions/not_found.rb +12 -0
  20. data/lib/endpoint_flux/exceptions/service_unavailable.rb +12 -0
  21. data/lib/endpoint_flux/exceptions/unauthorized.rb +12 -0
  22. data/lib/endpoint_flux/exceptions/validation.rb +13 -0
  23. data/lib/endpoint_flux/middlewares.rb +8 -0
  24. data/lib/endpoint_flux/middlewares/authenticator/skip.rb +11 -0
  25. data/lib/endpoint_flux/middlewares/authorizator/skip.rb +11 -0
  26. data/lib/endpoint_flux/middlewares/decorator/add_status.rb +12 -0
  27. data/lib/endpoint_flux/middlewares/decorator/skip.rb +11 -0
  28. data/lib/endpoint_flux/middlewares/policy/skip.rb +11 -0
  29. data/lib/endpoint_flux/middlewares/validator/empty.rb +12 -0
  30. data/lib/endpoint_flux/rails/concerns/endpoint_controller.rb +43 -0
  31. data/lib/endpoint_flux/request.rb +17 -0
  32. data/lib/endpoint_flux/response.rb +30 -0
  33. data/lib/endpoint_flux/version.rb +3 -0
  34. data/spec/lib/class_loader_spec.rb +31 -0
  35. data/spec/lib/config/default_middlewares_spec.rb +21 -0
  36. data/spec/lib/config/endpoints_namespace_spec.rb +13 -0
  37. data/spec/lib/config/flow_spec.rb +8 -0
  38. data/spec/lib/config/interceptor_spec.rb +34 -0
  39. data/spec/lib/config/middleware_spec.rb +62 -0
  40. data/spec/lib/config/rescue_from_spec.rb +45 -0
  41. data/spec/lib/endpoint/flow_spec.rb +43 -0
  42. data/spec/lib/endpoint/middlewares_spec.rb +110 -0
  43. data/spec/lib/endpoint/perform_spec.rb +61 -0
  44. data/spec/lib/endpoint/rescue_from_spec.rb +61 -0
  45. data/spec/lib/endpoint_flux/rails/concerns/endpoint_controller_spec.rb +75 -0
  46. data/spec/lib/endpoint_flux/request_spec.rb +44 -0
  47. data/spec/lib/exceptions/forbidden_spec.rb +12 -0
  48. data/spec/lib/exceptions/not_found_spec.rb +12 -0
  49. data/spec/lib/exceptions/service_unavailable_spec.rb +12 -0
  50. data/spec/lib/exceptions/unauthorized_spec.rb +12 -0
  51. data/spec/lib/exceptions/validation_spec.rb +14 -0
  52. data/spec/lib/middlewares/authenticator/skip_spec.rb +5 -0
  53. data/spec/lib/middlewares/authorizator/skip_spec.rb +5 -0
  54. data/spec/lib/middlewares/decorator/add_status_spec.rb +17 -0
  55. data/spec/lib/middlewares/decorator/skip_spec.rb +5 -0
  56. data/spec/lib/middlewares/policy/skip_spec.rb +5 -0
  57. data/spec/lib/middlewares/shared_examples.rb +19 -0
  58. data/spec/lib/middlewares/validator/empty_spec.rb +15 -0
  59. data/spec/lib/response_spec.rb +131 -0
  60. data/spec/spec_helper.rb +52 -0
  61. metadata +157 -0
@@ -0,0 +1,5 @@
1
+ require_relative '../../middlewares/shared_examples'
2
+
3
+ RSpec.describe EndpointFlux::Middlewares::Decorator::Skip do
4
+ include_examples 'perform does not change the params'
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative '../../middlewares/shared_examples'
2
+
3
+ RSpec.describe EndpointFlux::Middlewares::Policy::Skip do
4
+ include_examples 'perform does not change the params'
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.shared_context 'perform does not change the params', shared_context: :metadata do
4
+ describe '#perform' do
5
+ let(:params) { { some: 'value' } }
6
+ let(:headers) { { 'Authorization' => 'valid' } }
7
+ let(:request) { EndpointFlux::Request.new(headers: headers, params: params) }
8
+ let(:response) { EndpointFlux::Response.new(headers: {}, body: {}) }
9
+
10
+ it 'returns not changed params' do
11
+ middleware_request, middleware_response = subject.perform(request, response, {})
12
+
13
+ expect(middleware_request.params).to eq(params)
14
+ expect(middleware_request.headers).to eq(headers)
15
+ expect(middleware_response.headers).to eq({})
16
+ expect(middleware_response.body).to eq({})
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.describe EndpointFlux::Middlewares::Validator::Empty do
2
+ describe '#perform' do
3
+ let(:params) { { some: 'value' } }
4
+ let(:request) { EndpointFlux::Request.new(headers: {}, params: params) }
5
+ let(:response) { EndpointFlux::Response.new }
6
+
7
+ it 'returns empty params' do
8
+ middleware_request, middleware_response = subject.perform(request, response, {})
9
+
10
+ expect(middleware_request.params).to eq({})
11
+ expect(middleware_response.headers).to eq({})
12
+ expect(middleware_response.body).to eq({})
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe EndpointFlux::Response do
4
+ subject { EndpointFlux::Response.new(params) }
5
+ let(:empty_subject) { EndpointFlux::Response.new() }
6
+
7
+ describe '#success?' do
8
+ context 'when valid params given' do
9
+ Array(200..209).each do |status|
10
+ let(:params) { { headers: {}, body: {status: status} } }
11
+ it "returns true for status #{status}" do
12
+ expect(subject.success?).to be_truthy
13
+ end
14
+ end
15
+ end
16
+
17
+ context 'when wrong params given' do
18
+ let(:status) { 400 }
19
+ let(:params) { { headers: {}, body: {status: status} } }
20
+ it 'returns false for not a success status' do
21
+ expect(subject.success?).to be_falsey
22
+ end
23
+
24
+ describe 'when Response initialized without params' do
25
+ it 'returns false for not a success status' do
26
+ expect(empty_subject.success?).to be_falsey
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#invalid?' do
33
+ let(:params) { { headers: {}, body: {status: status} } }
34
+ context 'when valid params given' do
35
+ let(:status) { 422 }
36
+
37
+ it 'returns true for status 422' do
38
+ expect(subject.invalid?).to be_truthy
39
+ end
40
+ end
41
+
42
+ context 'when wrong params given' do
43
+ let(:status) { 400 }
44
+
45
+ it 'returns false for not an invalid status' do
46
+ expect(subject.invalid?).to be_falsey
47
+ end
48
+
49
+ describe 'when Response initialized without params' do
50
+ it 'returns false for not an invalid status' do
51
+ expect(empty_subject.invalid?).to be_falsey
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#forbidden?' do
58
+ let(:params) { { headers: {}, body: {status: status} } }
59
+ context 'when valid params given' do
60
+ let(:status) { 403 }
61
+
62
+ it 'returns true for status 403' do
63
+ expect(subject.forbidden?).to be_truthy
64
+ end
65
+ end
66
+
67
+ context 'when wrong params given' do
68
+ let(:status) { 400 }
69
+
70
+ it 'returns false for not a forbidden status' do
71
+ expect(subject.forbidden?).to be_falsey
72
+ end
73
+
74
+ describe 'when Response initialized without params' do
75
+ it 'returns false for not a forbidden status' do
76
+ expect(empty_subject.forbidden?).to be_falsey
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#unauthorized?' do
83
+ let(:params) { { headers: {}, body: {status: status} } }
84
+ context 'when valid params given' do
85
+ let(:status) { 401 }
86
+
87
+ it 'returns true for status 401' do
88
+ expect(subject.unauthorized?).to be_truthy
89
+ end
90
+ end
91
+
92
+ context 'when wrong params given' do
93
+ let(:status) { 400 }
94
+
95
+ it 'returns false for not a unauthorized status' do
96
+ expect(subject.unauthorized?).to be_falsey
97
+ end
98
+
99
+ describe 'when Response initialized without params' do
100
+ it 'returns false for not a unauthorized status' do
101
+ expect(empty_subject.unauthorized?).to be_falsey
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#unauthorized?' do
108
+ let(:params) { { headers: {}, body: {status: status} } }
109
+ context 'when valid params given' do
110
+ let(:status) { 404 }
111
+
112
+ it 'returns true for status 404' do
113
+ expect(subject.not_found?).to be_truthy
114
+ end
115
+ end
116
+
117
+ context 'when wrong params given' do
118
+ let(:status) { 400 }
119
+
120
+ it 'returns false for not a not_found status' do
121
+ expect(subject.not_found?).to be_falsey
122
+ end
123
+
124
+ describe 'when Response initialized without params' do
125
+ it 'returns false for not a not_found status' do
126
+ expect(empty_subject.not_found?).to be_falsey
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,52 @@
1
+ require 'byebug'
2
+ require 'endpoint_flux'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
+ # have no way to turn it off -- the option exists only for backwards
48
+ # compatibility in RSpec 3). It causes shared context metadata to be
49
+ # inherited by the metadata hash of host groups and examples, rather than
50
+ # triggering implicit auto-inclusion in groups with matching metadata.
51
+ config.shared_context_metadata_behavior = :apply_to_host_groups
52
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: endpoint-flux
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Arturs Kreipans https://github.com/fragallia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '9.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '9.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.5.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.0
41
+ description: A simple way to organise API endpoints
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - CONTRIBUTING.md
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - README.md
52
+ - circle.yml
53
+ - endpoint_flux.gemspec
54
+ - lib/endpoint_flux.rb
55
+ - lib/endpoint_flux/class_loader.rb
56
+ - lib/endpoint_flux/config.rb
57
+ - lib/endpoint_flux/config/interceptor.rb
58
+ - lib/endpoint_flux/config/middleware.rb
59
+ - lib/endpoint_flux/config/rescue_from.rb
60
+ - lib/endpoint_flux/endpoint.rb
61
+ - lib/endpoint_flux/exceptions.rb
62
+ - lib/endpoint_flux/exceptions/base.rb
63
+ - lib/endpoint_flux/exceptions/forbidden.rb
64
+ - lib/endpoint_flux/exceptions/not_found.rb
65
+ - lib/endpoint_flux/exceptions/service_unavailable.rb
66
+ - lib/endpoint_flux/exceptions/unauthorized.rb
67
+ - lib/endpoint_flux/exceptions/validation.rb
68
+ - lib/endpoint_flux/middlewares.rb
69
+ - lib/endpoint_flux/middlewares/authenticator/skip.rb
70
+ - lib/endpoint_flux/middlewares/authorizator/skip.rb
71
+ - lib/endpoint_flux/middlewares/decorator/add_status.rb
72
+ - lib/endpoint_flux/middlewares/decorator/skip.rb
73
+ - lib/endpoint_flux/middlewares/policy/skip.rb
74
+ - lib/endpoint_flux/middlewares/validator/empty.rb
75
+ - lib/endpoint_flux/rails/concerns/endpoint_controller.rb
76
+ - lib/endpoint_flux/request.rb
77
+ - lib/endpoint_flux/response.rb
78
+ - lib/endpoint_flux/version.rb
79
+ - spec/lib/class_loader_spec.rb
80
+ - spec/lib/config/default_middlewares_spec.rb
81
+ - spec/lib/config/endpoints_namespace_spec.rb
82
+ - spec/lib/config/flow_spec.rb
83
+ - spec/lib/config/interceptor_spec.rb
84
+ - spec/lib/config/middleware_spec.rb
85
+ - spec/lib/config/rescue_from_spec.rb
86
+ - spec/lib/endpoint/flow_spec.rb
87
+ - spec/lib/endpoint/middlewares_spec.rb
88
+ - spec/lib/endpoint/perform_spec.rb
89
+ - spec/lib/endpoint/rescue_from_spec.rb
90
+ - spec/lib/endpoint_flux/rails/concerns/endpoint_controller_spec.rb
91
+ - spec/lib/endpoint_flux/request_spec.rb
92
+ - spec/lib/exceptions/forbidden_spec.rb
93
+ - spec/lib/exceptions/not_found_spec.rb
94
+ - spec/lib/exceptions/service_unavailable_spec.rb
95
+ - spec/lib/exceptions/unauthorized_spec.rb
96
+ - spec/lib/exceptions/validation_spec.rb
97
+ - spec/lib/middlewares/authenticator/skip_spec.rb
98
+ - spec/lib/middlewares/authorizator/skip_spec.rb
99
+ - spec/lib/middlewares/decorator/add_status_spec.rb
100
+ - spec/lib/middlewares/decorator/skip_spec.rb
101
+ - spec/lib/middlewares/policy/skip_spec.rb
102
+ - spec/lib/middlewares/shared_examples.rb
103
+ - spec/lib/middlewares/validator/empty_spec.rb
104
+ - spec/lib/response_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/resolving/endpoint-flux
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 2.5.3
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: EndpointFlux!
130
+ test_files:
131
+ - spec/lib/class_loader_spec.rb
132
+ - spec/lib/config/default_middlewares_spec.rb
133
+ - spec/lib/config/endpoints_namespace_spec.rb
134
+ - spec/lib/config/flow_spec.rb
135
+ - spec/lib/config/interceptor_spec.rb
136
+ - spec/lib/config/middleware_spec.rb
137
+ - spec/lib/config/rescue_from_spec.rb
138
+ - spec/lib/endpoint/flow_spec.rb
139
+ - spec/lib/endpoint/middlewares_spec.rb
140
+ - spec/lib/endpoint/perform_spec.rb
141
+ - spec/lib/endpoint/rescue_from_spec.rb
142
+ - spec/lib/endpoint_flux/rails/concerns/endpoint_controller_spec.rb
143
+ - spec/lib/endpoint_flux/request_spec.rb
144
+ - spec/lib/exceptions/forbidden_spec.rb
145
+ - spec/lib/exceptions/not_found_spec.rb
146
+ - spec/lib/exceptions/service_unavailable_spec.rb
147
+ - spec/lib/exceptions/unauthorized_spec.rb
148
+ - spec/lib/exceptions/validation_spec.rb
149
+ - spec/lib/middlewares/authenticator/skip_spec.rb
150
+ - spec/lib/middlewares/authorizator/skip_spec.rb
151
+ - spec/lib/middlewares/decorator/add_status_spec.rb
152
+ - spec/lib/middlewares/decorator/skip_spec.rb
153
+ - spec/lib/middlewares/policy/skip_spec.rb
154
+ - spec/lib/middlewares/shared_examples.rb
155
+ - spec/lib/middlewares/validator/empty_spec.rb
156
+ - spec/lib/response_spec.rb
157
+ - spec/spec_helper.rb