freckle_io 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -5
- data/freckle-io.gemspec +3 -3
- data/lib/freckle_io/client/entries.rb +1 -26
- data/lib/freckle_io/client/project_groups.rb +0 -2
- data/lib/freckle_io/client/projects.rb +1 -13
- data/lib/freckle_io/client/tags.rb +1 -6
- data/lib/freckle_io/client/users.rb +1 -6
- data/lib/freckle_io/configuration.rb +5 -5
- data/lib/freckle_io/connection.rb +1 -3
- data/lib/freckle_io/params.rb +5 -10
- data/lib/freckle_io/request/multiple_pages.rb +3 -3
- data/lib/freckle_io/request/single_page.rb +2 -2
- data/lib/freckle_io/validator/base_contract.rb +16 -0
- data/lib/freckle_io/validator/entry.rb +26 -50
- data/lib/freckle_io/validator/project.rb +13 -39
- data/lib/freckle_io/validator/project_group.rb +5 -24
- data/lib/freckle_io/validator/tag.rb +5 -24
- data/lib/freckle_io/validator/user.rb +13 -37
- data/lib/freckle_io/validator/validation.yml +8 -13
- data/lib/freckle_io.rb +1 -1
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/_all/returns_a_entry_for_each_response.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/with_unknow_params/doesn_t_raise_a_invalid_params_error.yml +53 -0
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/with_valid_params/params_should_be_valid.yml +22 -17
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/with_validator/call_entry_s_validator.yml +24 -19
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +261 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/_all/returns_a_project_group_for_each_response.yml +262 -36
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/with_unknow_params/doesn_t_raises_a_invalid_params_error.yml +325 -0
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/with_valid_params/params_should_be_valid.yml +22 -17
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/with_validator/call_project_group_s_validator.yml +261 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +501 -225
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_all/returns_a_project_for_each_response.yml +501 -225
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_show/get_a_spacific_project.yml +24 -19
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_show/raw_links_should_be_a_empty_array.yml +24 -19
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/with_unknow_params/doesn_t_raises_a_invalid_params_error.yml +865 -0
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/with_valid_params/params_should_be_valid.yml +22 -17
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/with_validator/call_project_s_validator.yml +502 -226
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/_all/returns_a_tag_for_each_response.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/with_unknow_params/doesn_t_raise_a_invalid_params_error.yml +53 -0
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/with_valid_params/params_should_be_valid.yml +22 -17
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/with_validator/call_tag_s_validator.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/_all/returns_a_user_for_each_response.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/with_unknow_params/doesn_t_raise_a_invalid_params_error.yml +109 -0
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/with_valid_params/params_should_be_valid.yml +22 -17
- data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/with_validator/call_user_s_validator.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_a_valid_response/must_be_a_json_format.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_freckle_token_authentication/set_X-FreckleToken.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_header/set_user_agent.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_invalid_url/raises_a_resource_not_found_error_for_invalid_resource.yml +13 -16
- data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_page_param/response_must_be_success.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_per_page_param/response_must_have_per_page_elements.yml +24 -19
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_MultiplePages/with_configuration/_get/returns_an_array_of_faraday_response.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_MultiplePages/with_configuration/_get/returns_freckle_default_per_page_elements.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_MultiplePages/with_per_page/_get/return_per_page_number_elements.yml +74 -59
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_first/next_page_should_be_a_SinglePage.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_first/prev_page_should_be_nil.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_first/when_get_last_page_from_the_first_page/next_should_be_nil.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_get/returns_correct_raw_links_for_the_first_page.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_last/next_page_should_be_nil.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_last/returns_correct_raw_links_for_the_last_page.yml +45 -35
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_last/when_get_prev_page_from_the_last_page/prev_should_be_nil.yml +67 -52
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_next/previous_page_is_a_SinglePage.yml +67 -52
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_next/previous_page_should_be_not_nil.yml +67 -52
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_prev/next_page_is_a_SinglePage.yml +89 -69
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_prev/when_get_prev_page_from_the_first_page/prev_should_be_nil.yml +67 -52
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_total_page/with_first_page/returns_the_range_of_pages.yml +23 -18
- data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_total_page/with_next_page/returns_an_empty_array.yml +45 -35
- data/spec/freckle_io/client/entries_spec.rb +23 -32
- data/spec/freckle_io/client/project_groups_spec.rb +11 -20
- data/spec/freckle_io/client/projects_spec.rb +15 -21
- data/spec/freckle_io/client/tags_spec.rb +10 -19
- data/spec/freckle_io/client/users_spec.rb +13 -21
- data/spec/freckle_io/configuration_spec.rb +7 -4
- data/spec/freckle_io/connection_spec.rb +1 -1
- data/spec/freckle_io/paginator_spec.rb +8 -8
- data/spec/freckle_io/params_spec.rb +1 -1
- data/spec/freckle_io/request/single_page_spec.rb +6 -6
- data/spec/spec_helper.rb +3 -3
- data/spec/support/anonymize/entries.rb +9 -8
- data/spec/support/anonymize/project_groups.rb +4 -3
- data/spec/support/anonymize/projects.rb +9 -8
- data/spec/support/anonymize/tags.rb +5 -4
- data/spec/support/anonymize/users.rb +13 -15
- data/spec/support/anonymize_interaction.rb +5 -5
- metadata +27 -22
- data/lib/freckle_io/validator/restricted_hash.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09c8ed65bf1bde96bbb41d1a60ec5efff20fb078663921277acddd6db61604fd'
|
4
|
+
data.tar.gz: a8c0b02dd374c6c479a0e22b491ae9e4b9c00dae960cacf23968fcee2ec954e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5952aed31584850de9eb2164797d03dde8369a0d2a8204b635a7f17c49a29f0295693cfcc4733a4a76f9415b4fef72119e79ba3f6a7d0f70f05038c9446574bc
|
7
|
+
data.tar.gz: 5f8e1266dffb1b5c179e736a11f174fd69fed1f6f3632ac31e452f869b50fae1e1e1d7871ba07cebc7b0764280a5b66951fab68d3bbd5c616bca3f8c795d82c6
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.7
|
5
|
+
NewCops: enable
|
5
6
|
Exclude:
|
6
7
|
- "bin/**/*"
|
7
8
|
- ".bundle/**/*"
|
@@ -10,15 +11,18 @@ AllCops:
|
|
10
11
|
- "node_modules/**/*"
|
11
12
|
- "**/*.gemspec"
|
12
13
|
|
13
|
-
Layout/
|
14
|
+
Layout/ParameterAlignment:
|
14
15
|
EnforcedStyle: with_fixed_indentation
|
15
16
|
Layout/DotPosition:
|
16
17
|
EnforcedStyle: trailing
|
17
18
|
Layout/SpaceInsideHashLiteralBraces:
|
18
19
|
EnforcedStyle: no_space
|
20
|
+
Layout/LineLength:
|
21
|
+
Enabled: true
|
22
|
+
Max: 80
|
19
23
|
|
20
24
|
Metrics/BlockLength:
|
21
|
-
|
25
|
+
AllowedPatterns:
|
22
26
|
- context
|
23
27
|
- describe
|
24
28
|
- feature
|
@@ -28,8 +32,6 @@ Metrics/BlockLength:
|
|
28
32
|
- namespace
|
29
33
|
- draw
|
30
34
|
|
31
|
-
Style/ClassAndModuleChildren:
|
32
|
-
EnforcedStyle: compact
|
33
35
|
Style/Documentation:
|
34
36
|
Enabled: false
|
35
37
|
Style/FrozenStringLiteralComment:
|
data/freckle-io.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "freckle_io"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "1.0.0"
|
7
7
|
spec.authors = ["Domenico Giuseppe Garofoli"]
|
8
8
|
spec.email = ["sirion1987@gmail.com"]
|
9
9
|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.license = "MIT"
|
14
14
|
spec.require_path = ["lib"]
|
15
15
|
|
16
|
-
spec.required_ruby_version = '>= 2.
|
16
|
+
spec.required_ruby_version = '>= 2.7.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0")
|
19
19
|
spec.test_files = Dir["spec/**/*.rb"]
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "webmock"
|
31
31
|
|
32
32
|
spec.add_runtime_dependency "dotenv"
|
33
|
-
spec.add_runtime_dependency "dry-validation", "~>
|
33
|
+
spec.add_runtime_dependency "dry-validation", "~> 1.9.0"
|
34
34
|
spec.add_runtime_dependency "faraday", ">= 0.15.2"
|
35
35
|
spec.add_runtime_dependency "faraday_middleware", ">= 0.12"
|
36
36
|
spec.add_runtime_dependency "typhoeus"
|
@@ -2,27 +2,6 @@ module FreckleIO
|
|
2
2
|
module Client
|
3
3
|
class Entries
|
4
4
|
ENTRY_ENDPOINT = "/v2/entries".freeze
|
5
|
-
ALLOWED_KEYS = %i(
|
6
|
-
user_ids
|
7
|
-
description
|
8
|
-
project_ids
|
9
|
-
tag_ids
|
10
|
-
tag_filter_type
|
11
|
-
invoice_ids
|
12
|
-
import_ids
|
13
|
-
from
|
14
|
-
to
|
15
|
-
invoiced
|
16
|
-
invoiced_at_from
|
17
|
-
invoiced_at_to
|
18
|
-
updated_from
|
19
|
-
updated_to
|
20
|
-
billable
|
21
|
-
approved_at_from
|
22
|
-
approved_at_to
|
23
|
-
approved_by_ids
|
24
|
-
per_page
|
25
|
-
).freeze
|
26
5
|
VALIDATOR_MODULE = "FreckleIO::Validator::Entry".freeze
|
27
6
|
|
28
7
|
def all(params = {})
|
@@ -42,11 +21,7 @@ module FreckleIO
|
|
42
21
|
end
|
43
22
|
|
44
23
|
def entry_params(params)
|
45
|
-
@entry_params = Params.new(
|
46
|
-
params,
|
47
|
-
ALLOWED_KEYS,
|
48
|
-
VALIDATOR_MODULE
|
49
|
-
).call
|
24
|
+
@entry_params = Params.new(params, VALIDATOR_MODULE).call
|
50
25
|
end
|
51
26
|
end
|
52
27
|
end
|
@@ -2,7 +2,6 @@ module FreckleIO
|
|
2
2
|
module Client
|
3
3
|
class ProjectGroups
|
4
4
|
PROJECT_GROUPS_ENDPOINT = "/v2/project_groups".freeze
|
5
|
-
ALLOWED_KEYS = %i(name project_ids per_page).freeze
|
6
5
|
VALIDATOR_MODULE = "FreckleIO::Validator::ProjectGroup".freeze
|
7
6
|
|
8
7
|
def all(params = {})
|
@@ -27,7 +26,6 @@ module FreckleIO
|
|
27
26
|
def project_groups_params(params)
|
28
27
|
@project_groups_params = Params.new(
|
29
28
|
params,
|
30
|
-
ALLOWED_KEYS,
|
31
29
|
VALIDATOR_MODULE
|
32
30
|
).call
|
33
31
|
end
|
@@ -2,14 +2,6 @@ module FreckleIO
|
|
2
2
|
module Client
|
3
3
|
class Projects
|
4
4
|
PROJECT_ENDPOINT = "/v2/projects".freeze
|
5
|
-
ALLOWED_KEYS = %i(
|
6
|
-
name
|
7
|
-
project_group_ids
|
8
|
-
billing_increment
|
9
|
-
enabled
|
10
|
-
billable
|
11
|
-
per_page
|
12
|
-
).freeze
|
13
5
|
VALIDATOR_MODULE = "FreckleIO::Validator::Project".freeze
|
14
6
|
|
15
7
|
def all(params = {})
|
@@ -31,11 +23,7 @@ module FreckleIO
|
|
31
23
|
end
|
32
24
|
|
33
25
|
def project_params(params)
|
34
|
-
@project_params = Params.new(
|
35
|
-
params,
|
36
|
-
ALLOWED_KEYS,
|
37
|
-
VALIDATOR_MODULE
|
38
|
-
).call
|
26
|
+
@project_params = Params.new(params, VALIDATOR_MODULE).call
|
39
27
|
end
|
40
28
|
end
|
41
29
|
end
|
@@ -2,7 +2,6 @@ module FreckleIO
|
|
2
2
|
module Client
|
3
3
|
class Tags
|
4
4
|
TAG_ENDPOINT = "/v2/tags".freeze
|
5
|
-
ALLOWED_KEYS = %i(name billable per_page).freeze
|
6
5
|
VALIDATOR_MODULE = "FreckleIO::Validator::Tag".freeze
|
7
6
|
|
8
7
|
def all(params = {})
|
@@ -22,11 +21,7 @@ module FreckleIO
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def tag_params(params)
|
25
|
-
@tag_params = Params.new(
|
26
|
-
params,
|
27
|
-
ALLOWED_KEYS,
|
28
|
-
VALIDATOR_MODULE
|
29
|
-
).call
|
24
|
+
@tag_params = Params.new(params, VALIDATOR_MODULE).call
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
@@ -2,7 +2,6 @@ module FreckleIO
|
|
2
2
|
module Client
|
3
3
|
class Users
|
4
4
|
USER_ENDPOINT = "/v2/users".freeze
|
5
|
-
ALLOWED_KEYS = %i(name email role state per_page).freeze
|
6
5
|
VALIDATOR_MODULE = "FreckleIO::Validator::User".freeze
|
7
6
|
|
8
7
|
def all(params = {})
|
@@ -24,11 +23,7 @@ module FreckleIO
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def user_params(params)
|
27
|
-
@user_params = Params.new(
|
28
|
-
params,
|
29
|
-
ALLOWED_KEYS,
|
30
|
-
VALIDATOR_MODULE
|
31
|
-
).call
|
26
|
+
@user_params = Params.new(params, VALIDATOR_MODULE).call
|
32
27
|
end
|
33
28
|
end
|
34
29
|
end
|
@@ -6,11 +6,11 @@ module FreckleIO
|
|
6
6
|
|
7
7
|
DEFAULT_URL = "https://api.nokotime.com/v2".freeze
|
8
8
|
|
9
|
-
attr_writer :auth_type
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
attr_writer :auth_type,
|
10
|
+
:token,
|
11
|
+
:url,
|
12
|
+
:per_page,
|
13
|
+
:max_concurrency
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@token = nil
|
@@ -8,13 +8,11 @@ module FreckleIO
|
|
8
8
|
|
9
9
|
# rubocop:disable Metrics/MethodLength
|
10
10
|
def get(path, params: {}, request_options: {})
|
11
|
-
|
11
|
+
connection.get do |request|
|
12
12
|
authorize_request(request)
|
13
13
|
set_request_options(request, request_options)
|
14
14
|
request.url path, params
|
15
15
|
end
|
16
|
-
|
17
|
-
response
|
18
16
|
rescue Faraday::ConnectionFailed => e
|
19
17
|
raise Errors::Connection::Failed.new(e), e.message
|
20
18
|
rescue Faraday::ResourceNotFound => e
|
data/lib/freckle_io/params.rb
CHANGED
@@ -1,21 +1,18 @@
|
|
1
1
|
module FreckleIO
|
2
2
|
class Params
|
3
|
-
attr_reader :params
|
4
|
-
|
5
|
-
attr_reader :validator_module
|
3
|
+
attr_reader :params,
|
4
|
+
:validator_module
|
6
5
|
|
7
6
|
def initialize(
|
8
7
|
params,
|
9
|
-
allowed_keys,
|
10
8
|
validator_module
|
11
9
|
)
|
12
10
|
@params = params
|
13
|
-
@allowed_keys = allowed_keys
|
14
11
|
@validator_module = validator_module
|
15
12
|
end
|
16
13
|
|
17
14
|
def call
|
18
|
-
return validator.
|
15
|
+
return validator.to_h if valid?
|
19
16
|
|
20
17
|
raise Errors::Params::InvalidParams.new, validator_messages
|
21
18
|
end
|
@@ -27,7 +24,7 @@ module FreckleIO
|
|
27
24
|
end
|
28
25
|
|
29
26
|
def validator
|
30
|
-
@validator ||= which_validator_module.
|
27
|
+
@validator ||= which_validator_module.new.call(params)
|
31
28
|
end
|
32
29
|
|
33
30
|
def which_validator_module
|
@@ -37,9 +34,7 @@ module FreckleIO
|
|
37
34
|
end
|
38
35
|
|
39
36
|
def validator_messages
|
40
|
-
messages = validator.
|
41
|
-
return messages.values.join(",") if messages.is_a?(Hash)
|
42
|
-
|
37
|
+
messages = validator.errors(full: true).messages
|
43
38
|
messages.join(",")
|
44
39
|
end
|
45
40
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module FreckleIO
|
2
|
+
module Validator
|
3
|
+
class BaseContract < Dry::Validation::Contract
|
4
|
+
EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.freeze
|
5
|
+
|
6
|
+
config.messages.backend = :i18n
|
7
|
+
config.messages.load_paths << File.join(__dir__, "validation.yml")
|
8
|
+
|
9
|
+
register_macro(:email_format) do
|
10
|
+
if !value.nil? && !EMAIL_REGEX.match?(value)
|
11
|
+
key.failure(:invalid_email_format)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,57 +1,33 @@
|
|
1
1
|
module FreckleIO
|
2
2
|
module Validator
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
class Entry < FreckleIO::Validator::BaseContract
|
4
|
+
schema do
|
5
|
+
optional(:user_ids).filled(:string)
|
6
|
+
optional(:description).filled(:string)
|
7
|
+
optional(:project_ids).filled(:string)
|
8
|
+
optional(:tag_ids).filled(:string)
|
9
|
+
optional(:tag_filter_type).filled(:string)
|
10
|
+
optional(:invoice_ids).filled(:string)
|
11
|
+
optional(:import_ids).filled(:string)
|
12
|
+
optional(:from).filled(:string)
|
13
|
+
optional(:to).filled(:string)
|
14
|
+
optional(:invoiced).filled(:bool)
|
15
|
+
optional(:invoiced_at_from).filled(:string)
|
16
|
+
optional(:invoiced_at_to).filled(:string)
|
17
|
+
optional(:updated_from).filled(:string)
|
18
|
+
optional(:updated_to).filled(:string)
|
19
|
+
optional(:billable).filled(:bool)
|
20
|
+
optional(:approved_at_from).filled(:string)
|
21
|
+
optional(:approved_at_to).filled(:string)
|
22
|
+
optional(:approved_by_ids).filled(:string)
|
23
|
+
optional(:per_page).filled(:integer)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
optional(:tag_ids).filled :str?
|
30
|
-
optional(:tag_filter_type).filled :str?
|
31
|
-
optional(
|
32
|
-
:tag_filter_type
|
33
|
-
).value(included_in?: valid_tag_filter_type)
|
34
|
-
optional(:invoice_ids).filled :str?
|
35
|
-
optional(:import_ids).filled :str?
|
36
|
-
optional(:from).filled :str?
|
37
|
-
optional(:to).filled :str?
|
38
|
-
optional(:invoiced).filled :bool?
|
39
|
-
optional(:invoiced_at_from).filled :str?
|
40
|
-
optional(:invoiced_at_to).filled :str?
|
41
|
-
optional(:updated_from).filled :str?
|
42
|
-
optional(:updated_to).filled :str?
|
43
|
-
optional(:billable).filled :bool?
|
44
|
-
optional(:approved_at_from).filled :str?
|
45
|
-
optional(:approved_at_to).filled :str?
|
46
|
-
optional(:approved_by_ids).filled :str?
|
47
|
-
optional(:per_page).filled :int?
|
48
|
-
end
|
49
|
-
end.with(allowed_keys: valid_keys).call(params)
|
26
|
+
rule(:tag_filter_type) do
|
27
|
+
if !value.nil? && !["and", "combination of"].include?(value)
|
28
|
+
key.failure(:invalid_tag_filter_type)
|
29
|
+
end
|
50
30
|
end
|
51
|
-
# rubocop:enable Metrics/MethodLength,
|
52
|
-
# rubocop:enable Metrics/AbcSize,
|
53
|
-
# rubocop:enable Lint/NestedMethodDefinition
|
54
|
-
# rubocop:enable Metrics/BlockLength,
|
55
31
|
end
|
56
32
|
end
|
57
33
|
end
|
@@ -1,46 +1,20 @@
|
|
1
1
|
module FreckleIO
|
2
2
|
module Validator
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
)
|
13
|
-
config.namespace = :project
|
14
|
-
|
15
|
-
predicates(RestrictedHash)
|
16
|
-
|
17
|
-
option :allowed_keys
|
18
|
-
|
19
|
-
def valid_increment
|
20
|
-
%w(1 5 6 10 15)
|
21
|
-
end
|
22
|
-
|
23
|
-
def valid_increment?(_options, values)
|
24
|
-
values.split(",").all? do |value|
|
25
|
-
valid_increment.include?(value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
3
|
+
class Project < FreckleIO::Validator::BaseContract
|
4
|
+
schema do
|
5
|
+
optional(:name).filled(:string)
|
6
|
+
optional(:project_group_ids).filled(:string)
|
7
|
+
optional(:billing_increment).filled(:string)
|
8
|
+
optional(:enabled).filled(:bool)
|
9
|
+
optional(:billable).filled(:bool)
|
10
|
+
optional(:per_page).filled(:integer)
|
11
|
+
end
|
29
12
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
optional(:billing_increment).filled(valid_increment?: {})
|
35
|
-
optional(:enabled).filled :bool?
|
36
|
-
optional(:billable).filled :bool?
|
37
|
-
optional(:per_page).filled :int?
|
38
|
-
end
|
39
|
-
end.with(allowed_keys: valid_keys).call(params)
|
13
|
+
rule(:billing_increment) do
|
14
|
+
if !value.nil? && !%w(1 5 6 10 15).include?(value)
|
15
|
+
key.failure(:invalid_billing_increment)
|
16
|
+
end
|
40
17
|
end
|
41
|
-
# rubocop:enable Metrics/MethodLength,
|
42
|
-
# rubocop:enable Metrics/AbcSize,
|
43
|
-
# rubocop:enable Lint/NestedMethodDefinition
|
44
18
|
end
|
45
19
|
end
|
46
20
|
end
|
@@ -1,30 +1,11 @@
|
|
1
1
|
module FreckleIO
|
2
2
|
module Validator
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
configure do
|
9
|
-
config.messages_file = File.join(
|
10
|
-
__dir__, "validation.yml"
|
11
|
-
)
|
12
|
-
config.namespace = :project_group
|
13
|
-
|
14
|
-
predicates(RestrictedHash)
|
15
|
-
|
16
|
-
option :allowed_keys
|
17
|
-
end
|
18
|
-
|
19
|
-
restricted_hash?(allowed_keys) do
|
20
|
-
optional(:name).filled :str?
|
21
|
-
optional(:project_ids).filled :str?
|
22
|
-
optional(:per_page).filled :int?
|
23
|
-
end
|
24
|
-
end.with(allowed_keys: valid_keys).call(params)
|
3
|
+
class ProjectGroup < FreckleIO::Validator::BaseContract
|
4
|
+
schema do
|
5
|
+
optional(:name).filled(:string)
|
6
|
+
optional(:project_ids).filled(:string)
|
7
|
+
optional(:per_page).filled(:integer)
|
25
8
|
end
|
26
|
-
# rubocop:enable Metrics/MethodLength,
|
27
|
-
# rubocop:enable Metrics/AbcSize,
|
28
9
|
end
|
29
10
|
end
|
30
11
|
end
|
@@ -1,30 +1,11 @@
|
|
1
1
|
module FreckleIO
|
2
2
|
module Validator
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
configure do
|
9
|
-
config.messages_file = File.join(
|
10
|
-
__dir__, "validation.yml"
|
11
|
-
)
|
12
|
-
config.namespace = :tag
|
13
|
-
|
14
|
-
predicates(RestrictedHash)
|
15
|
-
|
16
|
-
option :allowed_keys
|
17
|
-
end
|
18
|
-
|
19
|
-
restricted_hash?(allowed_keys) do
|
20
|
-
optional(:name).filled :str?
|
21
|
-
optional(:billable).filled :bool?
|
22
|
-
optional(:per_page).filled :int?
|
23
|
-
end
|
24
|
-
end.with(allowed_keys: valid_keys).call(params)
|
3
|
+
class Tag < FreckleIO::Validator::BaseContract
|
4
|
+
schema do
|
5
|
+
optional(:name).filled(:string)
|
6
|
+
optional(:billable).filled(:bool)
|
7
|
+
optional(:per_page).filled(:integer)
|
25
8
|
end
|
26
|
-
# rubocop:enable Metrics/MethodLength,
|
27
|
-
# rubocop:enable Metrics/AbcSize,
|
28
9
|
end
|
29
10
|
end
|
30
11
|
end
|
@@ -1,43 +1,19 @@
|
|
1
1
|
module FreckleIO
|
2
2
|
module Validator
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
predicates(RestrictedHash)
|
16
|
-
|
17
|
-
option :allowed_keys
|
18
|
-
|
19
|
-
def valid_roles
|
20
|
-
%w(supervisor leader coworker contractor)
|
21
|
-
end
|
22
|
-
|
23
|
-
def valid_states
|
24
|
-
%w(disabled pending active suspended)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
restricted_hash?(allowed_keys) do
|
29
|
-
optional(:name).filled :str?
|
30
|
-
optional(:email).filled :str?
|
31
|
-
optional(:email).value(format?: /\A[^@\s]+@[^@\s]+\z/)
|
32
|
-
optional(:role).value(included_in?: valid_roles)
|
33
|
-
optional(:state).value(included_in?: valid_states)
|
34
|
-
optional(:per_page).filled :int?
|
35
|
-
end
|
36
|
-
end.with(allowed_keys: valid_keys).call(params)
|
3
|
+
class User < FreckleIO::Validator::BaseContract
|
4
|
+
schema do
|
5
|
+
optional(:name).filled(:string)
|
6
|
+
optional(:email).filled(:string)
|
7
|
+
optional(:per_page).filled(:integer)
|
8
|
+
optional(:role).value(
|
9
|
+
included_in?: %w(supervisor leader coworker contractor)
|
10
|
+
)
|
11
|
+
optional(:state).value(
|
12
|
+
included_in?: %w(disabled pending active suspended)
|
13
|
+
)
|
37
14
|
end
|
38
|
-
|
39
|
-
|
40
|
-
# rubocop:enable Lint/NestedMethodDefinition
|
15
|
+
|
16
|
+
rule(:email).validate(:email_format)
|
41
17
|
end
|
42
18
|
end
|
43
19
|
end
|
@@ -1,14 +1,9 @@
|
|
1
1
|
en:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
restricted_hash?: "has unknown keys. Allowed keys are: user_ids, description, project_ids, tag_ids, tag_filter_type, invoice_ids, import_ids, from, to, invoiced, invoice_at_from, invoice_at_to, updated_from, updated_to, billable, approved_at_from, approved_at_to, approved_by_ids and per_page"
|
11
|
-
tag:
|
12
|
-
restricted_hash?: "has unknown keys. Allowed keys are: name, billable and per_page"
|
13
|
-
project_group:
|
14
|
-
restricted_hash?: "has unknown keys. Allowed keys are: name, project ids and per_page"
|
2
|
+
dry_validation:
|
3
|
+
errors:
|
4
|
+
invalid_email_format: "not a valid email format"
|
5
|
+
rules:
|
6
|
+
billing_increment:
|
7
|
+
invalid_billing_increment: "has invalid values. Allowed values are: 1, 5, 6, 10, 15"
|
8
|
+
tag_filter_type:
|
9
|
+
invalid_tag_filter_type: "has invalid values. Allowed values are: and, combination of"
|
data/lib/freckle_io.rb
CHANGED
@@ -8,7 +8,7 @@ require "freckle_io/errors/connection"
|
|
8
8
|
require "freckle_io/errors/params"
|
9
9
|
require "freckle_io/request/multiple_pages"
|
10
10
|
require "freckle_io/request/single_page"
|
11
|
-
require "freckle_io/validator/
|
11
|
+
require "freckle_io/validator/base_contract"
|
12
12
|
require "freckle_io/validator/user"
|
13
13
|
require "freckle_io/validator/project"
|
14
14
|
require "freckle_io/validator/entry"
|