boechat 0.0.1
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.
- checksums.yaml +7 -0
- data/.rubocop.yml +32 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +110 -0
- data/LICENSE.txt +21 -0
- data/README.md +7 -0
- data/Rakefile +8 -0
- data/TODO.md +6 -0
- data/boechat.gemspec +43 -0
- data/config/boechat.yml +10 -0
- data/lib/boechat/core.rb +10 -0
- data/lib/boechat/core/config/reader.rb +33 -0
- data/lib/boechat/core/config/schema_validator.rb +27 -0
- data/lib/boechat/core/config/wrapper.rb +17 -0
- data/lib/boechat/core/service/request.rb +76 -0
- data/lib/boechat/core/service/request_list.rb +36 -0
- data/lib/boechat/core/service/result.rb +26 -0
- data/lib/boechat/core/service/verifier.rb +38 -0
- data/lib/boechat/internal/constants.rb +22 -0
- data/lib/boechat/internal/errors.rb +12 -0
- data/lib/boechat/internal/string_extensions.rb +15 -0
- data/lib/boechat/internal/version.rb +7 -0
- data/lib/boechat_core.rb +3 -0
- metadata +153 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 666155b02a02293152a1fe3ab9f25517f47c4795224d33b0e1124d2a31adb219
|
|
4
|
+
data.tar.gz: 630e27e95ce5160648c4d4a31efa9580146ec89a9d55770b40ab2da85f85d623
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b6637c22a3f0b67c59af54032c45c120ad972179a3298b996584d12c609ddd6a2898e2a1a887e693c3531076423a196a3b61777ad220ead863bae7554814b70f
|
|
7
|
+
data.tar.gz: 1e79404dfd944972e195215b459ae3c41e4369a8b9b930f1210dcc1740e88f250878b750d2a04a47647c627c1464027c357a693b86f23c90f6c0fe04c2912c6d
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: '2.5'
|
|
3
|
+
|
|
4
|
+
Lint/UselessAssignment:
|
|
5
|
+
Exclude:
|
|
6
|
+
- 'lib/boechat/internal/version.rb'
|
|
7
|
+
|
|
8
|
+
Metrics/LineLength:
|
|
9
|
+
Max: 120
|
|
10
|
+
Exclude:
|
|
11
|
+
- '**/*_spec.rb'
|
|
12
|
+
|
|
13
|
+
Metrics/ModuleLength:
|
|
14
|
+
Exclude:
|
|
15
|
+
- '**/*_spec.rb'
|
|
16
|
+
|
|
17
|
+
Metrics/BlockLength:
|
|
18
|
+
Exclude:
|
|
19
|
+
- '**/*_spec.rb'
|
|
20
|
+
|
|
21
|
+
Style/ClassAndModuleChildren:
|
|
22
|
+
EnforcedStyle: nested
|
|
23
|
+
|
|
24
|
+
Style/Documentation:
|
|
25
|
+
Exclude:
|
|
26
|
+
- 'spec/**/*'
|
|
27
|
+
- 'test/**/*'
|
|
28
|
+
|
|
29
|
+
Lint/HandleExceptions:
|
|
30
|
+
Exclude:
|
|
31
|
+
- 'spec/**/*'
|
|
32
|
+
- 'test/**/*'
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.5.0@boechat
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
gemspec
|
|
6
|
+
|
|
7
|
+
gem 'dry-validation'
|
|
8
|
+
gem 'typhoeus'
|
|
9
|
+
|
|
10
|
+
group :test do
|
|
11
|
+
gem 'codeclimate-test-reporter', require: false
|
|
12
|
+
gem 'simplecov', require: false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :tools do
|
|
16
|
+
gem 'pry'
|
|
17
|
+
gem 'rubocop'
|
|
18
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
boechat (0.0.1)
|
|
5
|
+
dry-validation (~> 0.11.1)
|
|
6
|
+
oj (~> 3.5.0)
|
|
7
|
+
typhoeus (~> 1.3.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
ast (2.4.0)
|
|
13
|
+
codeclimate-test-reporter (1.0.8)
|
|
14
|
+
simplecov (<= 0.13)
|
|
15
|
+
coderay (1.1.2)
|
|
16
|
+
concurrent-ruby (1.0.5)
|
|
17
|
+
diff-lcs (1.3)
|
|
18
|
+
docile (1.1.5)
|
|
19
|
+
dry-configurable (0.7.0)
|
|
20
|
+
concurrent-ruby (~> 1.0)
|
|
21
|
+
dry-container (0.6.0)
|
|
22
|
+
concurrent-ruby (~> 1.0)
|
|
23
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
|
24
|
+
dry-core (0.4.5)
|
|
25
|
+
concurrent-ruby (~> 1.0)
|
|
26
|
+
dry-equalizer (0.2.1)
|
|
27
|
+
dry-logic (0.4.2)
|
|
28
|
+
dry-container (~> 0.2, >= 0.2.6)
|
|
29
|
+
dry-core (~> 0.2)
|
|
30
|
+
dry-equalizer (~> 0.2)
|
|
31
|
+
dry-types (0.12.2)
|
|
32
|
+
concurrent-ruby (~> 1.0)
|
|
33
|
+
dry-configurable (~> 0.1)
|
|
34
|
+
dry-container (~> 0.3)
|
|
35
|
+
dry-core (~> 0.2, >= 0.2.1)
|
|
36
|
+
dry-equalizer (~> 0.2)
|
|
37
|
+
dry-logic (~> 0.4, >= 0.4.2)
|
|
38
|
+
inflecto (~> 0.0.0, >= 0.0.2)
|
|
39
|
+
dry-validation (0.11.1)
|
|
40
|
+
concurrent-ruby (~> 1.0)
|
|
41
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
|
42
|
+
dry-core (~> 0.2, >= 0.2.1)
|
|
43
|
+
dry-equalizer (~> 0.2)
|
|
44
|
+
dry-logic (~> 0.4, >= 0.4.0)
|
|
45
|
+
dry-types (~> 0.12.0)
|
|
46
|
+
dry-validation-matchers (0.4.0)
|
|
47
|
+
ethon (0.11.0)
|
|
48
|
+
ffi (>= 1.3.0)
|
|
49
|
+
ffi (1.9.23)
|
|
50
|
+
inflecto (0.0.2)
|
|
51
|
+
json (2.1.0)
|
|
52
|
+
method_source (0.9.0)
|
|
53
|
+
oj (3.5.1)
|
|
54
|
+
parallel (1.12.1)
|
|
55
|
+
parser (2.5.1.0)
|
|
56
|
+
ast (~> 2.4.0)
|
|
57
|
+
powerpack (0.1.1)
|
|
58
|
+
pry (0.11.3)
|
|
59
|
+
coderay (~> 1.1.0)
|
|
60
|
+
method_source (~> 0.9.0)
|
|
61
|
+
rainbow (3.0.0)
|
|
62
|
+
rake (10.5.0)
|
|
63
|
+
rspec (3.7.0)
|
|
64
|
+
rspec-core (~> 3.7.0)
|
|
65
|
+
rspec-expectations (~> 3.7.0)
|
|
66
|
+
rspec-mocks (~> 3.7.0)
|
|
67
|
+
rspec-core (3.7.1)
|
|
68
|
+
rspec-support (~> 3.7.0)
|
|
69
|
+
rspec-expectations (3.7.0)
|
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
71
|
+
rspec-support (~> 3.7.0)
|
|
72
|
+
rspec-mocks (3.7.0)
|
|
73
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
74
|
+
rspec-support (~> 3.7.0)
|
|
75
|
+
rspec-support (3.7.1)
|
|
76
|
+
rubocop (0.55.0)
|
|
77
|
+
parallel (~> 1.10)
|
|
78
|
+
parser (>= 2.5)
|
|
79
|
+
powerpack (~> 0.1)
|
|
80
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
81
|
+
ruby-progressbar (~> 1.7)
|
|
82
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
83
|
+
ruby-progressbar (1.9.0)
|
|
84
|
+
simplecov (0.13.0)
|
|
85
|
+
docile (~> 1.1.0)
|
|
86
|
+
json (>= 1.8, < 3)
|
|
87
|
+
simplecov-html (~> 0.10.0)
|
|
88
|
+
simplecov-html (0.10.2)
|
|
89
|
+
typhoeus (1.3.0)
|
|
90
|
+
ethon (>= 0.9.0)
|
|
91
|
+
unicode-display_width (1.3.2)
|
|
92
|
+
|
|
93
|
+
PLATFORMS
|
|
94
|
+
ruby
|
|
95
|
+
|
|
96
|
+
DEPENDENCIES
|
|
97
|
+
boechat!
|
|
98
|
+
bundler (~> 1.16)
|
|
99
|
+
codeclimate-test-reporter
|
|
100
|
+
dry-validation
|
|
101
|
+
dry-validation-matchers (~> 0.4.0)
|
|
102
|
+
pry
|
|
103
|
+
rake (~> 10.0)
|
|
104
|
+
rspec (~> 3.0)
|
|
105
|
+
rubocop
|
|
106
|
+
simplecov
|
|
107
|
+
typhoeus
|
|
108
|
+
|
|
109
|
+
BUNDLED WITH
|
|
110
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Nikita Shilnikov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/TODO.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
## TODO's
|
|
2
|
+
|
|
3
|
+
+ [DONE] Create Result class to store the result after call each request
|
|
4
|
+
+ [DONE] Define boechat.yml expected format and adapt config classes
|
|
5
|
+
+ [WIP ] Write tests for Core classes
|
|
6
|
+
+ [ ] Fix call for multiple services, that have error with Typhoeus Hydra...
|
data/boechat.gemspec
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'boechat/internal/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'boechat'
|
|
9
|
+
spec.version = Boechat::Internal::VERSION
|
|
10
|
+
spec.authors = ['Danilo Barion Nogueira']
|
|
11
|
+
spec.email = ['danilo.barion@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Version verifier for BFFs and APIs'
|
|
14
|
+
spec.description = 'Verify the version of external APIs that your project depends on!'
|
|
15
|
+
spec.homepage = 'https://github.com/danilobarion1986/boechat'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
20
|
+
# rubocop:disable Style/GuardClause
|
|
21
|
+
if spec.respond_to?(:metadata)
|
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
23
|
+
else
|
|
24
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
|
25
|
+
end
|
|
26
|
+
# rubocop:enable Style/GuardClause
|
|
27
|
+
|
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
|
|
29
|
+
spec.bindir = 'exe'
|
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
31
|
+
spec.require_paths = ['lib']
|
|
32
|
+
spec.required_ruby_version = '>= 2.5.0'
|
|
33
|
+
|
|
34
|
+
# Dependencies that your gem needs at runtime
|
|
35
|
+
spec.add_runtime_dependency 'dry-validation', '~> 0.11.1'
|
|
36
|
+
spec.add_runtime_dependency 'oj', '~> 3.5'
|
|
37
|
+
spec.add_runtime_dependency 'typhoeus', '~> 1.3'
|
|
38
|
+
|
|
39
|
+
# Dependencies that your gem needs only for development
|
|
40
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
41
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
43
|
+
end
|
data/config/boechat.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Describe all API healthcheck/status endpoints's that your application depends on!
|
|
2
|
+
services:
|
|
3
|
+
- name: empresas
|
|
4
|
+
base_url: http://empresasservice.ad.vagastec.com.br
|
|
5
|
+
status_endpoint: status
|
|
6
|
+
http_verb: get
|
|
7
|
+
- name: processos
|
|
8
|
+
base_url: http://qa-processosseletivosservice.ad.vagastec.com.br
|
|
9
|
+
status_endpoint: healthcheck
|
|
10
|
+
http_verb: get
|
data/lib/boechat/core.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
require_relative 'wrapper'
|
|
5
|
+
require_relative 'schema_validator'
|
|
6
|
+
|
|
7
|
+
module Boechat
|
|
8
|
+
module Core
|
|
9
|
+
module Config
|
|
10
|
+
# Class responsible for read the boechat.yml file, that describes all endpoints to call
|
|
11
|
+
class Reader
|
|
12
|
+
attr_reader :config_path
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
app_root = Pathname.new(File.expand_path('../../../../', __dir__))
|
|
16
|
+
@config_path = File.join(app_root, 'config', 'boechat.yml')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def call
|
|
20
|
+
result = validate_config_schema
|
|
21
|
+
output = result.success? ? result.output : {}
|
|
22
|
+
Wrapper.new(output, result.errors)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def validate_config_schema
|
|
28
|
+
SchemaValidator.call(File.read(@config_path))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'dry-validation'
|
|
4
|
+
|
|
5
|
+
module Boechat
|
|
6
|
+
module Core
|
|
7
|
+
module Config
|
|
8
|
+
# Class responsible for validate the schema of the boechat.yml configuration file
|
|
9
|
+
class SchemaValidator
|
|
10
|
+
CONFIG_SCHEMA = Dry::Validation.Schema do
|
|
11
|
+
required('services').each do
|
|
12
|
+
schema do
|
|
13
|
+
required('name').filled(:str?)
|
|
14
|
+
required('base_url').filled(:str?)
|
|
15
|
+
optional('status_endpoint').filled(:str?)
|
|
16
|
+
optional('http_verb').filled(included_in?: %w[get post])
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.call(config)
|
|
22
|
+
CONFIG_SCHEMA.call(YAML.safe_load(config))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boechat
|
|
4
|
+
module Core
|
|
5
|
+
module Config
|
|
6
|
+
# Class responsible for save all configurations readed from boechat.yml file
|
|
7
|
+
class Wrapper
|
|
8
|
+
attr_reader :config, :errors
|
|
9
|
+
|
|
10
|
+
def initialize(config, errors)
|
|
11
|
+
@config = config
|
|
12
|
+
@errors = errors
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'oj'
|
|
4
|
+
require_relative '../../internal/string_extensions'
|
|
5
|
+
require_relative 'result'
|
|
6
|
+
|
|
7
|
+
module Boechat
|
|
8
|
+
module Core
|
|
9
|
+
# Module to group all classes related to the Request/Response/Validation cycle
|
|
10
|
+
module Service
|
|
11
|
+
using StringExtensions
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Class responsible for make the request to one service
|
|
15
|
+
class Request
|
|
16
|
+
attr_reader :request, :response, :result, :service_uri, :verb, :parameters, :body, :headers
|
|
17
|
+
HTTP_UNPROCESSABLE_ENTITY = 422
|
|
18
|
+
BASIC_HEADER = { 'User-Agent' => 'Boechat - API Version Verifier' }
|
|
19
|
+
|
|
20
|
+
def initialize(service_uri, verb: :get, parameters: nil, body: nil, headers: nil)
|
|
21
|
+
@service_uri = service_uri
|
|
22
|
+
@verb = verb
|
|
23
|
+
@parameters = parameters
|
|
24
|
+
@body = body
|
|
25
|
+
@headers = headers
|
|
26
|
+
@request = Typhoeus::Request.new(@service_uri, method: @verb, params: @parameters,
|
|
27
|
+
body: @body, headers: http_header)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def call
|
|
31
|
+
handle_request
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def http_header
|
|
37
|
+
return BASIC_HEADER.merge(@headers) if @headers
|
|
38
|
+
BASIC_HEADER
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def handle_request
|
|
42
|
+
@request.on_complete do |res|
|
|
43
|
+
@response = res
|
|
44
|
+
@result = Result.new(valid_response(res))
|
|
45
|
+
end
|
|
46
|
+
@request.run
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def valid_response(response)
|
|
50
|
+
body = response.body
|
|
51
|
+
|
|
52
|
+
return response_error(response) if body.empty?
|
|
53
|
+
return response_invalid_format unless body.valid_json?
|
|
54
|
+
Oj.load(body, symbol_keys: true).merge(status: response.code)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def response_error(response)
|
|
58
|
+
code = response.code
|
|
59
|
+
|
|
60
|
+
case code
|
|
61
|
+
when 404
|
|
62
|
+
Oj.load({ error: 'Not Found', code: code }.to_json, symbol_keys: true)
|
|
63
|
+
when 500
|
|
64
|
+
Oj.load({ error: 'Service Internal Error', code: code }.to_json, symbol_keys: true)
|
|
65
|
+
else
|
|
66
|
+
Oj.load({ error: 'Service Unexpected Error', code: code }.to_json, symbol_keys: true)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def response_invalid_format
|
|
71
|
+
Oj.load({ error: 'Invalid JSON format', status: HTTP_UNPROCESSABLE_ENTITY }.to_json)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boechat
|
|
4
|
+
module Core
|
|
5
|
+
module Service
|
|
6
|
+
# Class to save all user request objects to execute them one at a time or all in parallel
|
|
7
|
+
class RequestList
|
|
8
|
+
attr_reader :requests
|
|
9
|
+
|
|
10
|
+
def initialize(requests = {})
|
|
11
|
+
@requests = requests
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call(request_identifier = nil)
|
|
15
|
+
if request_identifier.nil?
|
|
16
|
+
hydra = Typhoeus::Hydra.hydra
|
|
17
|
+
requests.each_pair { |_key, request| hydra.queue(request.call) }
|
|
18
|
+
hydra.run
|
|
19
|
+
elsif requests.key?(request_identifier)
|
|
20
|
+
requests[request_identifier].call
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
self
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def []=(key, requester)
|
|
27
|
+
requests[key] = requester
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def [](key)
|
|
31
|
+
requests[key]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'oj'
|
|
4
|
+
|
|
5
|
+
module Boechat
|
|
6
|
+
module Core
|
|
7
|
+
module Service
|
|
8
|
+
# Class responsible for store the response of the Request class
|
|
9
|
+
class Result
|
|
10
|
+
attr_reader :parsed_response
|
|
11
|
+
|
|
12
|
+
def initialize(parsed_response)
|
|
13
|
+
@parsed_response = parsed_response
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def success?
|
|
17
|
+
@parsed_response && @parsed_response[:status] < 400
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def failure?
|
|
21
|
+
@parsed_response && @parsed_response[:status] >= 400
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative './request'
|
|
4
|
+
require_relative './request_list'
|
|
5
|
+
require_relative '../config/reader'
|
|
6
|
+
require 'typhoeus'
|
|
7
|
+
require 'json'
|
|
8
|
+
|
|
9
|
+
module Boechat
|
|
10
|
+
module Core
|
|
11
|
+
module Service
|
|
12
|
+
# Class responsible for call the endpoints and return all the results
|
|
13
|
+
class Verifier
|
|
14
|
+
attr_reader :config, :request_list
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@config = ConfigReader.new.call.config
|
|
18
|
+
build_request_list
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def call(service = nil)
|
|
22
|
+
@request_list.call(service)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def build_request_list
|
|
28
|
+
@request_list = RequestList.new
|
|
29
|
+
|
|
30
|
+
@config['services'].each do |service|
|
|
31
|
+
key, value = service.first
|
|
32
|
+
@request_list.requests[key] = Request.new(value['url'])
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boechat
|
|
4
|
+
module Internal
|
|
5
|
+
# A list of constants you can use to avoid memory allocations or identity checks.
|
|
6
|
+
#
|
|
7
|
+
# @example Just include this module to your class or module
|
|
8
|
+
# class Foo
|
|
9
|
+
# include Boechat::Internal::Constants
|
|
10
|
+
#
|
|
11
|
+
# def call(value = EMPTY_ARRAY)
|
|
12
|
+
# value.map(&:to_s)
|
|
13
|
+
# end
|
|
14
|
+
# end
|
|
15
|
+
module Constants
|
|
16
|
+
# Source: https://github.com/semver/semver/issues/232
|
|
17
|
+
# rubocop:disable Metrics/LineLength
|
|
18
|
+
REGEX_SEMVER_FORMAT = /^(v\d*|0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/
|
|
19
|
+
# rubocop:enable Metrics/LineLength
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Module for safely include methods in String built-in class
|
|
4
|
+
module StringExtensions
|
|
5
|
+
refine String do
|
|
6
|
+
# Verifies if the string is a valid JSON format
|
|
7
|
+
# If valid, returns true; otherwise false
|
|
8
|
+
def valid_json?
|
|
9
|
+
JSON.parse(self)
|
|
10
|
+
true
|
|
11
|
+
rescue JSON::ParserError
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/boechat_core.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: boechat
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Danilo Barion Nogueira
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: dry-validation
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.11.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.11.1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: oj
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.5'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.5'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: typhoeus
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.3'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.16'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.16'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
description: Verify the version of external APIs that your project depends on!
|
|
98
|
+
email:
|
|
99
|
+
- danilo.barion@gmail.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".rubocop.yml"
|
|
105
|
+
- ".ruby-version"
|
|
106
|
+
- CHANGELOG.md
|
|
107
|
+
- Gemfile
|
|
108
|
+
- Gemfile.lock
|
|
109
|
+
- LICENSE.txt
|
|
110
|
+
- README.md
|
|
111
|
+
- Rakefile
|
|
112
|
+
- TODO.md
|
|
113
|
+
- boechat.gemspec
|
|
114
|
+
- config/boechat.yml
|
|
115
|
+
- lib/boechat/core.rb
|
|
116
|
+
- lib/boechat/core/config/reader.rb
|
|
117
|
+
- lib/boechat/core/config/schema_validator.rb
|
|
118
|
+
- lib/boechat/core/config/wrapper.rb
|
|
119
|
+
- lib/boechat/core/service/request.rb
|
|
120
|
+
- lib/boechat/core/service/request_list.rb
|
|
121
|
+
- lib/boechat/core/service/result.rb
|
|
122
|
+
- lib/boechat/core/service/verifier.rb
|
|
123
|
+
- lib/boechat/internal/constants.rb
|
|
124
|
+
- lib/boechat/internal/errors.rb
|
|
125
|
+
- lib/boechat/internal/string_extensions.rb
|
|
126
|
+
- lib/boechat/internal/version.rb
|
|
127
|
+
- lib/boechat_core.rb
|
|
128
|
+
homepage: https://github.com/danilobarion1986/boechat
|
|
129
|
+
licenses:
|
|
130
|
+
- MIT
|
|
131
|
+
metadata:
|
|
132
|
+
allowed_push_host: https://rubygems.org
|
|
133
|
+
post_install_message:
|
|
134
|
+
rdoc_options: []
|
|
135
|
+
require_paths:
|
|
136
|
+
- lib
|
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: 2.5.0
|
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
|
+
requirements:
|
|
144
|
+
- - ">="
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '0'
|
|
147
|
+
requirements: []
|
|
148
|
+
rubyforge_project:
|
|
149
|
+
rubygems_version: 2.7.3
|
|
150
|
+
signing_key:
|
|
151
|
+
specification_version: 4
|
|
152
|
+
summary: Version verifier for BFFs and APIs
|
|
153
|
+
test_files: []
|