defra_ruby_validators 2.7.1 → 3.0.0

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: fcc15d0837d498fd37fe5cfd1781d2b80b87165c0235b6e94aa50ad6463151a5
4
- data.tar.gz: de144f02848b1b2c8de4ccb5bdb4ec9963697eed004ccf07106139333078936e
3
+ metadata.gz: e34dff1331e6b8a942f51618779fbace633e14f091eb697ecb95fb5eadb8afba
4
+ data.tar.gz: 7767d4bd72710a2b020b0635a8b287b13a41a615be7e2aaf500cddd4a2c2feae
5
5
  SHA512:
6
- metadata.gz: bd502508cb5a172c6778bc20782dd799ea39f70fe0ada1291914c1ece812525cbe67c23c9de9687b76bba27fb3786cdab987720d798a1d478753527b5034e766
7
- data.tar.gz: 0500a197f3405f89bd4501e642103b3692f57a4f40997c2d184897a5fad055b8fa90b34f79daea5e5eafeb1a5e4cd43e84d5d6b787a64dbd9de2bcbe6cd6088d
6
+ metadata.gz: 7bd048c738c34dbc7bd22f0984989347e0b001ea586259ccf30a274d27e598b4a23ba8bc9bbe9fb737cb6dbbfb8c483101d51268c4eb2b1cd7ae1ee7e1d37cc7
7
+ data.tar.gz: 7057bcf0ec3b6dcc292aee79f3f344f164c7de8b8d15b5ec2f1ae540fcf9ed97e53d2d2b4fd32755c645d1765c444a17f33189a51cdab8f6292b0bab932e9b75
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rest-client"
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?(json_response)
16
+ return :unsupported_company_type unless company_type_is_allowed?(companies_house_response)
20
17
 
21
- status_is_allowed?(json_response) ? :active : :inactive
22
- rescue RestClient::ResourceNotFound
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?(json_response)
49
- %w[active voluntary-arrangement].include?(json_response["company_status"])
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?(json_response)
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.to_s == json_response["type"]
47
+ @permitted_types == companies_house_response[:company_type].to_s
59
48
  when Array
60
- @permitted_types.include?(json_response["type"])
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
- ATTRIBUTES = %i[
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
@@ -14,7 +14,7 @@ module DefraRuby
14
14
  private
15
15
 
16
16
  def valid_format?(record, attribute, value)
17
- return true if value.match?(/\A\d{1,10}(\.\d{1,2})?\z/)
17
+ return true if value.to_s.match?(/\A\d{1,10}(\.\d{1,2})?\z/)
18
18
 
19
19
  add_validation_error(record, attribute, :invalid_format)
20
20
  false
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DefraRuby
4
4
  module Validators
5
- VERSION = "2.7.1"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
11
+ date: 2024-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: defra_ruby_companies_house
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: i18n
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -177,7 +191,7 @@ licenses:
177
191
  metadata:
178
192
  allowed_push_host: https://rubygems.org
179
193
  rubygems_mfa_required: 'true'
180
- post_install_message:
194
+ post_install_message:
181
195
  rdoc_options: []
182
196
  require_paths:
183
197
  - lib
@@ -193,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
207
  version: '0'
194
208
  requirements: []
195
209
  rubygems_version: 3.3.7
196
- signing_key:
210
+ signing_key:
197
211
  specification_version: 4
198
212
  summary: Defra ruby on rails validations
199
213
  test_files: []