defra_ruby_validators 2.7.2 → 3.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e71fe5778e8e21ba88af8230696cc2b27945e0f2d93b596f1c662cab90bfee0
|
|
4
|
+
data.tar.gz: 6de129130f3cf5f15efe684b9a6c442d0a1d63f4c64df45a89d7b2d3e7df7891
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59c38ea607d53c77fa38f5aecdc38a68687e1aa1c92ab15e6c07ffbb14cbb2cfe4a18f1ae67ae24ef6c0de9a35951a5359259217827f396d6245e74336373796
|
|
7
|
+
data.tar.gz: 41f073a068c11e7932b86e1aefe37a7d636e66e44c8c1f7c8c2d284b7e7c40943c216bd510c05bbf99a488ab00a9cb71a70c35fc09b001f706b77932e1f315b3
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "defra_ruby/companies_house"
|
|
4
4
|
|
|
5
5
|
module DefraRuby
|
|
6
6
|
module Validators
|
|
@@ -10,33 +10,22 @@ module DefraRuby
|
|
|
10
10
|
@permitted_types = permitted_types
|
|
11
11
|
|
|
12
12
|
validate_permitted_types
|
|
13
|
-
|
|
14
|
-
@url = "#{DefraRuby::Validators.configuration.companies_house_host}#{@company_number}"
|
|
15
|
-
@api_key = DefraRuby::Validators.configuration.companies_house_api_key
|
|
16
13
|
end
|
|
17
14
|
|
|
18
15
|
def status
|
|
19
|
-
return :unsupported_company_type unless company_type_is_allowed?(
|
|
16
|
+
return :unsupported_company_type unless company_type_is_allowed?(companies_house_response)
|
|
20
17
|
|
|
21
|
-
status_is_allowed?(
|
|
22
|
-
rescue
|
|
18
|
+
status_is_allowed?(companies_house_response) ? :active : :inactive
|
|
19
|
+
rescue DefraRuby::CompaniesHouse::CompanyNotFoundError
|
|
23
20
|
:not_found
|
|
24
21
|
end
|
|
25
22
|
|
|
26
|
-
def json_response
|
|
27
|
-
@_json_response ||=
|
|
28
|
-
JSON.parse(
|
|
29
|
-
RestClient::Request.execute(
|
|
30
|
-
method: :get,
|
|
31
|
-
url: @url,
|
|
32
|
-
user: @api_key,
|
|
33
|
-
password: ""
|
|
34
|
-
)
|
|
35
|
-
)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
23
|
private
|
|
39
24
|
|
|
25
|
+
def companies_house_response
|
|
26
|
+
@companies_house_response ||= DefraRuby::CompaniesHouse::API.run(company_number: @company_number)
|
|
27
|
+
end
|
|
28
|
+
|
|
40
29
|
def validate_permitted_types
|
|
41
30
|
return if @permitted_types.nil?
|
|
42
31
|
|
|
@@ -45,19 +34,19 @@ module DefraRuby
|
|
|
45
34
|
raise ArgumentError, I18n.t("defra_ruby.validators.CompaniesHouseNumberValidator.argument_error")
|
|
46
35
|
end
|
|
47
36
|
|
|
48
|
-
def status_is_allowed?(
|
|
49
|
-
%
|
|
37
|
+
def status_is_allowed?(companies_house_response)
|
|
38
|
+
%i[active voluntary-arrangement].include?(companies_house_response[:company_status])
|
|
50
39
|
end
|
|
51
40
|
|
|
52
|
-
def company_type_is_allowed?(
|
|
41
|
+
def company_type_is_allowed?(companies_house_response)
|
|
53
42
|
# if permitted_types has not been defined in the validator, we skip this check
|
|
54
43
|
return true if @permitted_types.blank?
|
|
55
44
|
|
|
56
45
|
case @permitted_types
|
|
57
46
|
when String
|
|
58
|
-
@permitted_types
|
|
47
|
+
@permitted_types == companies_house_response[:company_type].to_s
|
|
59
48
|
when Array
|
|
60
|
-
@permitted_types.include?(
|
|
49
|
+
@permitted_types.include?(companies_house_response[:company_type].to_s)
|
|
61
50
|
else
|
|
62
51
|
raise ArgumentError, I18n.t("defra_ruby.validators.CompaniesHouseNumberValidator.argument_error")
|
|
63
52
|
end
|
|
@@ -12,24 +12,7 @@ module DefraRuby
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
class Configuration
|
|
15
|
-
|
|
16
|
-
companies_house_host
|
|
17
|
-
companies_house_api_key
|
|
18
|
-
].freeze
|
|
19
|
-
|
|
20
|
-
attr_accessor(*ATTRIBUTES)
|
|
21
|
-
|
|
22
|
-
def initialize
|
|
23
|
-
@companies_house_host = "https://api.companieshouse.gov.uk/company/"
|
|
24
|
-
@companies_house_api_key = nil
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def ensure_valid
|
|
28
|
-
missing_attributes = ATTRIBUTES.select { |a| public_send(a).nil? }
|
|
29
|
-
return true if missing_attributes.empty?
|
|
30
|
-
|
|
31
|
-
raise "The following DefraRuby::Validators configuration attributes are missing: #{missing_attributes}"
|
|
32
|
-
end
|
|
15
|
+
# Removed companies house configuration but laving the class in place to avoid knock-on impacts on apps.
|
|
33
16
|
end
|
|
34
17
|
end
|
|
35
18
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: defra_ruby_validators
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Defra
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activemodel
|
|
@@ -24,6 +23,20 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: defra_ruby_companies_house
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: i18n
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -177,7 +190,6 @@ licenses:
|
|
|
177
190
|
metadata:
|
|
178
191
|
allowed_push_host: https://rubygems.org
|
|
179
192
|
rubygems_mfa_required: 'true'
|
|
180
|
-
post_install_message:
|
|
181
193
|
rdoc_options: []
|
|
182
194
|
require_paths:
|
|
183
195
|
- lib
|
|
@@ -185,15 +197,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
185
197
|
requirements:
|
|
186
198
|
- - ">="
|
|
187
199
|
- !ruby/object:Gem::Version
|
|
188
|
-
version: '3.
|
|
200
|
+
version: '3.2'
|
|
189
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
202
|
requirements:
|
|
191
203
|
- - ">="
|
|
192
204
|
- !ruby/object:Gem::Version
|
|
193
205
|
version: '0'
|
|
194
206
|
requirements: []
|
|
195
|
-
rubygems_version: 3.
|
|
196
|
-
signing_key:
|
|
207
|
+
rubygems_version: 3.6.9
|
|
197
208
|
specification_version: 4
|
|
198
209
|
summary: Defra ruby on rails validations
|
|
199
210
|
test_files: []
|