glia-errors 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/.prettierignore +2 -0
- data/.prettierrc +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +13 -0
- data/Appraisals +9 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +73 -0
- data/LICENSE +21 -0
- data/README.md +123 -0
- data/Rakefile +36 -0
- data/gemfiles/dry_validation_v0.gemfile +16 -0
- data/gemfiles/dry_validation_v1.gemfile +16 -0
- data/glia-errors.gemspec +23 -0
- data/lib/glia/errors.rb +22 -0
- data/lib/glia/errors/error.rb +51 -0
- data/lib/glia/errors/error_types.rb +14 -0
- data/lib/glia/errors/mapper.rb +158 -0
- data/lib/glia/errors/validation_errors.rb +115 -0
- data/test_cases/invalid_format_error_case.json +74 -0
- data/test_cases/invalid_length_error_case.json +106 -0
- data/test_cases/invalid_number_error_case.json +90 -0
- data/test_cases/invalid_type_error_case.json +98 -0
- data/test_cases/invalid_value_error_case.json +125 -0
- data/test_cases/missing_value_error_case.json +16 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23c0be62fe5b91fe4914d5b6812cfd678a11497e9591291a0664823e6ef1938b
|
4
|
+
data.tar.gz: 51680c69eaf02641ecc47857d67679fb3e64208f2e008471dffbe64d422d41d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3600850fc2f82f50c3608cbba041ef6af9bc9f15a387a64250e465b284ae26316532386443848a8718e4008b37a651c0c876bfb7ddac3e279990b2e11d9e49a7
|
7
|
+
data.tar.gz: 46a878503202ae5bdb3ba9f8df49c76fd1d122ca76aa9456f0d477753f6f312cd6f01514d59d1babd5a0259b72e2b9f383dc5e0442e7c446a0c9a869350ffc3d
|
data/.gitignore
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
gemfiles/*gemfile.lock
|
data/.prettierignore
ADDED
data/.prettierrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
printWidth: 100
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem 'prettier', '~> 0.21'
|
6
|
+
gem 'rake', '~> 13.0'
|
7
|
+
gem 'rspec', '~> 3.10'
|
8
|
+
gem 'rubocop', '~> 1.5'
|
9
|
+
gem 'rubocop-rake', '~> 0.5'
|
10
|
+
gem 'rubocop-rspec', '~> 2.0'
|
11
|
+
gem 'super_diff'
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'appraisal'
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
appraisal (2.3.0)
|
5
|
+
bundler
|
6
|
+
rake
|
7
|
+
thor (>= 0.14.0)
|
8
|
+
ast (2.4.1)
|
9
|
+
attr_extras (6.2.4)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.20.1)
|
12
|
+
parser (2.7.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
patience_diff (1.1.0)
|
15
|
+
trollop (~> 1.16)
|
16
|
+
prettier (0.21.0)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (13.0.1)
|
19
|
+
regexp_parser (2.0.0)
|
20
|
+
rexml (3.2.4)
|
21
|
+
rspec (3.10.0)
|
22
|
+
rspec-core (~> 3.10.0)
|
23
|
+
rspec-expectations (~> 3.10.0)
|
24
|
+
rspec-mocks (~> 3.10.0)
|
25
|
+
rspec-core (3.10.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-expectations (3.10.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-mocks (3.10.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.10.0)
|
33
|
+
rspec-support (3.10.0)
|
34
|
+
rubocop (1.5.2)
|
35
|
+
parallel (~> 1.10)
|
36
|
+
parser (>= 2.7.1.5)
|
37
|
+
rainbow (>= 2.2.2, < 4.0)
|
38
|
+
regexp_parser (>= 1.8, < 3.0)
|
39
|
+
rexml
|
40
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
43
|
+
rubocop-ast (1.3.0)
|
44
|
+
parser (>= 2.7.1.5)
|
45
|
+
rubocop-rake (0.5.1)
|
46
|
+
rubocop
|
47
|
+
rubocop-rspec (2.0.1)
|
48
|
+
rubocop (~> 1.0)
|
49
|
+
rubocop-ast (>= 1.1.0)
|
50
|
+
ruby-progressbar (1.10.1)
|
51
|
+
super_diff (0.5.2)
|
52
|
+
attr_extras (>= 6.2.4)
|
53
|
+
diff-lcs
|
54
|
+
patience_diff
|
55
|
+
thor (1.0.1)
|
56
|
+
trollop (1.16.2)
|
57
|
+
unicode-display_width (1.7.0)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
appraisal
|
64
|
+
prettier (~> 0.21)
|
65
|
+
rake (~> 13.0)
|
66
|
+
rspec (~> 3.10)
|
67
|
+
rubocop (~> 1.5)
|
68
|
+
rubocop-rake (~> 0.5)
|
69
|
+
rubocop-rspec (~> 2.0)
|
70
|
+
super_diff
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.2.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Glia Inc.
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# glia-errors-ruby
|
2
|
+
Glia REST API errors (WIP)
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/salemove/glia-errors-ruby.svg?branch=master)](https://travis-ci.org/salemove/glia-errors-ruby)
|
5
|
+
|
6
|
+
The library provides a list of errors that are used in Glia REST API and utilities to easily construct them.
|
7
|
+
|
8
|
+
It is used by Glia developers to map application specific errors to one of standardized Glia errors.
|
9
|
+
Glia REST API integrators can use the library as a collection of constants to match Glia error response with the error
|
10
|
+
type, see the example below.
|
11
|
+
|
12
|
+
# Usage
|
13
|
+
|
14
|
+
## Require library
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'glia/errors'
|
18
|
+
```
|
19
|
+
|
20
|
+
## For Glia developers
|
21
|
+
|
22
|
+
### Map from `dry-validation` result
|
23
|
+
|
24
|
+
Currently 2 `dry-validation` versions are supported:
|
25
|
+
* `v0` up to `0.13`
|
26
|
+
* `v1` up to `1.6`
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
schema = Dry::Validation.Schema do
|
30
|
+
# ...
|
31
|
+
end
|
32
|
+
result = schema.(input)
|
33
|
+
error = Glia::Errors.from_dry_validation_result(result)
|
34
|
+
response = error.to_h
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Specifying mapping for custom error message
|
38
|
+
|
39
|
+
If you have custom `dry-validation` predicates and error messages you can specify a custom error map.
|
40
|
+
Custom error map takes priority over standard error mapping.
|
41
|
+
|
42
|
+
When custom error appears to be quite common consider adding it to this library instead.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
ERROR_MAP = {
|
46
|
+
'must be custom format' => lambda do |field, value, error_message|
|
47
|
+
Glia::Errors::InvalidFormatError.new(field: field)
|
48
|
+
end
|
49
|
+
}
|
50
|
+
error = Glia::Errors.from_dry_validation_result(result, ERROR_MAP)
|
51
|
+
response = error.to_h
|
52
|
+
```
|
53
|
+
|
54
|
+
## For REST API integrators
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'uri'
|
58
|
+
require 'net/http'
|
59
|
+
require 'openssl'
|
60
|
+
require 'json'
|
61
|
+
|
62
|
+
url = URI('https://api.glia.com/engagement_requests')
|
63
|
+
|
64
|
+
http = Net::HTTP.new(url.host, url.port)
|
65
|
+
http.use_ssl = true
|
66
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
67
|
+
request = Net::HTTP::Post.new(url)
|
68
|
+
request["Accept"] = 'application/json'
|
69
|
+
request["Content-Type"] = 'application/json'
|
70
|
+
request.body = '{}'
|
71
|
+
|
72
|
+
response = http.request(request)
|
73
|
+
code = response.code.to_i
|
74
|
+
|
75
|
+
if code >= 200 || code <= 299
|
76
|
+
# Success
|
77
|
+
elsif response.header['Content-Type'] == 'application/json'
|
78
|
+
# Glia error
|
79
|
+
error = JSON.parse(response.read_body)
|
80
|
+
case error['type']
|
81
|
+
when Glia::Errors::INPUT_VALIDATION_ERROR
|
82
|
+
# ...
|
83
|
+
when Glia::Errors::UNKNOWN_ERROR
|
84
|
+
# ...
|
85
|
+
else
|
86
|
+
# ...
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
# Other error
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
# Contributing
|
95
|
+
|
96
|
+
## Testing
|
97
|
+
|
98
|
+
Glia errors support multiple versions of `dry-validation` and tests are run against each supported major version.
|
99
|
+
Under the hood we use `Appraisal` gem which generals additional gemfiles for each of the versions.
|
100
|
+
|
101
|
+
To run all tests use:
|
102
|
+
|
103
|
+
```
|
104
|
+
bundle exec rake test
|
105
|
+
```
|
106
|
+
|
107
|
+
To run tests only for `dry-validation` v1:
|
108
|
+
|
109
|
+
```
|
110
|
+
bundle exec rake test_dry_validation_v1
|
111
|
+
```
|
112
|
+
|
113
|
+
To run tests only for `dry-validation` v0:
|
114
|
+
|
115
|
+
```
|
116
|
+
bundle exec rake test_dry_validation_v0
|
117
|
+
```
|
118
|
+
|
119
|
+
## Formatting
|
120
|
+
|
121
|
+
```
|
122
|
+
bundle exec rake format
|
123
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
RuboCop::RakeTask.new(:rubocop)
|
10
|
+
RuboCop::RakeTask.new do |task|
|
11
|
+
task.requires << 'rubocop-rspec'
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: %i[lint test]
|
15
|
+
|
16
|
+
task :lint do
|
17
|
+
sh "rubocop && rbprettier --check '**/*.rb'"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :format do
|
21
|
+
sh "rbprettier --write '**/*.rb'"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :install_test_deps do
|
25
|
+
sh 'bundle exec appraisal install'
|
26
|
+
end
|
27
|
+
|
28
|
+
task test: %i[test_dry_validation_v1 test_dry_validation_v0]
|
29
|
+
|
30
|
+
task test_dry_validation_v1: :install_test_deps do
|
31
|
+
sh 'bundle exec appraisal dry_validation_v1 rspec'
|
32
|
+
end
|
33
|
+
|
34
|
+
task test_dry_validation_v0: :install_test_deps do
|
35
|
+
sh 'bundle exec appraisal dry_validation_v0 rspec --tag dry_validation_v0'
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "prettier", "~> 0.21"
|
6
|
+
gem "rake", "~> 13.0"
|
7
|
+
gem "rspec", "~> 3.10"
|
8
|
+
gem "rubocop", "~> 1.5"
|
9
|
+
gem "rubocop-rake", "~> 0.5"
|
10
|
+
gem "rubocop-rspec", "~> 2.0"
|
11
|
+
gem "super_diff"
|
12
|
+
gem "dry-validation", "~> 0.13.0"
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem "appraisal"
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "prettier", "~> 0.21"
|
6
|
+
gem "rake", "~> 13.0"
|
7
|
+
gem "rspec", "~> 3.10"
|
8
|
+
gem "rubocop", "~> 1.5"
|
9
|
+
gem "rubocop-rake", "~> 0.5"
|
10
|
+
gem "rubocop-rspec", "~> 2.0"
|
11
|
+
gem "super_diff"
|
12
|
+
gem "dry-validation", "~> 1.6"
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem "appraisal"
|
16
|
+
end
|
data/glia-errors.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'glia-errors'
|
8
|
+
spec.version = '0.0.0'
|
9
|
+
spec.authors = ['Glia TechMovers']
|
10
|
+
spec.email = ['techmovers@glia.com']
|
11
|
+
|
12
|
+
spec.summary = 'Glia REST API errors'
|
13
|
+
spec.description = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.required_ruby_version = '~> 2.5'
|
23
|
+
end
|