defra_ruby_validators 2.7.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6206b70eb2b95385d8ee3eaae2600048973784b8d0aec0d6ed8ad6b7160a09c1
4
- data.tar.gz: 9882d021eef58fe6912b86df0a464e71efd2b3a366a16fe8a7b327a54aba3e72
3
+ metadata.gz: e34dff1331e6b8a942f51618779fbace633e14f091eb697ecb95fb5eadb8afba
4
+ data.tar.gz: 7767d4bd72710a2b020b0635a8b287b13a41a615be7e2aaf500cddd4a2c2feae
5
5
  SHA512:
6
- metadata.gz: e8030181c4ca547e313e626b90eea3955935d186ee9703011e319de10fe4bd4bec133ae75a84e9509ae04199448c72086e1e64de28078e006fe4d174b53eb863
7
- data.tar.gz: 0f77ecfb97c54d08817461737c07b5d926995e2c37c5d968495e8b52e83b3b7ed482b2725645a5aca2316ddada502972c310256b475a023993963925ef7fea24
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DefraRuby
4
4
  module Validators
5
- VERSION = "2.7.2"
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.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-14 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