companies_house_input_gateway 0.0.6

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/lib/base.rb +9 -0
  3. data/lib/companies_house_input_gateway/client.rb +46 -0
  4. data/lib/companies_house_input_gateway/config.rb +35 -0
  5. data/lib/companies_house_input_gateway/constants.rb +21 -0
  6. data/lib/companies_house_input_gateway/errors/api_error.rb +18 -0
  7. data/lib/companies_house_input_gateway/errors/companies_house_gateway_error.rb +20 -0
  8. data/lib/companies_house_input_gateway/errors/invalid_request_error.rb +12 -0
  9. data/lib/companies_house_input_gateway/errors/invalid_response_error.rb +6 -0
  10. data/lib/companies_house_input_gateway/form_validator.rb +29 -0
  11. data/lib/companies_house_input_gateway/forms/form_abstract_builder.rb +61 -0
  12. data/lib/companies_house_input_gateway/forms/form_company_data_request.rb +20 -0
  13. data/lib/companies_house_input_gateway/forms/form_confirmation_statement.rb +21 -0
  14. data/lib/companies_house_input_gateway/forms/form_get_submission_status.rb +21 -0
  15. data/lib/companies_house_input_gateway/forms/form_returnof_allotment_shares.rb +21 -0
  16. data/lib/companies_house_input_gateway/forms/form_submission.rb +39 -0
  17. data/lib/companies_house_input_gateway/middleware/check_response.rb +30 -0
  18. data/lib/companies_house_input_gateway/request.rb +57 -0
  19. data/lib/companies_house_input_gateway/requests/abstract_performer.rb +52 -0
  20. data/lib/companies_house_input_gateway/requests/company_data_request.rb +9 -0
  21. data/lib/companies_house_input_gateway/requests/confirmation_statement.rb +11 -0
  22. data/lib/companies_house_input_gateway/requests/get_submission_status.rb +9 -0
  23. data/lib/companies_house_input_gateway/requests/returnof_allotment_shares.rb +11 -0
  24. data/lib/companies_house_input_gateway/util.rb +28 -0
  25. data/lib/companies_house_input_gateway/validations/company_data_request.rb +20 -0
  26. data/lib/companies_house_input_gateway/validations/confirmation_statement.rb +96 -0
  27. data/lib/companies_house_input_gateway/validations/form_submission.rb +23 -0
  28. data/lib/companies_house_input_gateway/validations/get_submission_status.rb +24 -0
  29. data/lib/companies_house_input_gateway/validations/returnof_allotment_shares.rb +41 -0
  30. data/lib/companies_house_input_gateway/version.rb +5 -0
  31. data/lib/companies_house_input_gateway/xml_forms_binder.rb +81 -0
  32. data/lib/companies_house_input_gateway.rb +76 -0
  33. data/spec/client_spec.rb +59 -0
  34. data/spec/companies_house_input_gateway_spec.rb +47 -0
  35. data/spec/data_samples.rb +147 -0
  36. data/spec/fixtures/bad_response.xml +35 -0
  37. data/spec/fixtures/response_company_data_request.xml +330 -0
  38. data/spec/fixtures/response_confirmation_statement.xml +28 -0
  39. data/spec/fixtures/response_get_submission_status.xml +40 -0
  40. data/spec/fixtures/response_returnof_allotment_shares.xml +28 -0
  41. data/spec/form_validator_spec.rb +61 -0
  42. data/spec/request_spec.rb +132 -0
  43. data/spec/spec_helper.rb +32 -0
  44. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 76d1a45ee9a75590b55377e828568d02003f3f3fe39e912b7dc8cad6e73e305c
4
+ data.tar.gz: 5fb3eff3d7eb8a43775141f51f7807fc39e258a89f9c93ad33ea118c60848c7e
5
+ SHA512:
6
+ metadata.gz: 7f41ea2e376bd5f447b0e137b0fda339ad2a5b12b23514dfe510f647880d66d6f1d4a5ccd0933ec2ff2522484a7e78902d5b1bb4a505257c78e2432283736d5a
7
+ data.tar.gz: 5e96ab1ab1b0df528c86200d93a1b1e1bc0ab87da230f9f92cbd06cfa66c97d49dd39b40884eeff124af39c7580380dd57e68ad8d030be7f21623e749b12bcd2
data/lib/base.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class Base
5
+ def self.root
6
+ File.dirname __dir__
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class Client
5
+ def initialize(config = nil)
6
+ @config = (config || CompaniesHouseInputGateway.config).clone
7
+ end
8
+
9
+ def perform_check(*args)
10
+ request = Request.new(connection, @config)
11
+ request.perform(*args)
12
+ end
13
+
14
+ attr_reader :config
15
+
16
+ Constants::SUPPORTED_REQUESTS.each do |name|
17
+ class_eval <<-EOM
18
+ def #{Util.underscore(name)}(*args)
19
+ check = CompaniesHouseInputGateway::Requests.const_get(:#{name}).new(self)
20
+ check.perform(*args)
21
+ end
22
+ EOM
23
+ end
24
+
25
+ private
26
+
27
+ def connection
28
+ options = {
29
+ ssl: { verify: false },
30
+ url: @config[:api_endpoint],
31
+ headers: {
32
+ 'Accept' => 'application/xml',
33
+ 'User-Agent' => @config[:user_agent]
34
+ }
35
+ }
36
+
37
+ Faraday.new(options) do |c|
38
+ c.response :check_ch_response unless @config[:raw] # Check XML
39
+ c.response :xml unless @config[:raw] # Parse response
40
+ c.response :follow_redirects, limit: 3 # Follow redirect
41
+ c.response :raise_error # Raise errors
42
+ c.adapter @config[:adapter]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class Config
5
+ DEFAULT_OPTIONS = {
6
+ adapter: Faraday.default_adapter,
7
+ sender_id: nil,
8
+ password: nil,
9
+ email: nil,
10
+ gateway: nil,
11
+ raw: false,
12
+ api_endpoint: 'https://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/Gateway',
13
+ user_agent: "CompaniesHouseGateway Ruby Gem #{CompaniesHouseInputGateway::VERSION}",
14
+ open_timeout: 1,
15
+ timeout: 3
16
+ }.freeze
17
+
18
+ def initialize
19
+ @config = {}
20
+ yield self if block_given?
21
+ end
22
+
23
+ def [](name)
24
+ @config.fetch(name, DEFAULT_OPTIONS[name])
25
+ end
26
+
27
+ def []=(name, val)
28
+ @config[name] = val
29
+ end
30
+
31
+ def clone
32
+ Config.new { |config| @config.each { |k, v| config[k] = v } }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Constants
5
+ SUPPORTED_REQUESTS = %w[ReturnofAllotmentShares ConfirmationStatement GetSubmissionStatus CompanyDataRequest].freeze
6
+
7
+ COUNTRIES = %w[USA IRL DEU FRA ITA ESP PRT NLD POL BEL NOR SWE DNK
8
+ AUS NZL CAN ZAF AUT HRV CYP CZE EST HUN GRC LTU GBR GB-ENG GB-WLS GB-SCT GB-NIR].freeze
9
+
10
+ SPECIAL_FIELDS_MAPPER = {
11
+ dtr_5_applies: 'DTR5Applies',
12
+ psc_exempt_as_trading_on_regulated_market: 'PSCExemptAsTradingOnRegulatedMarket',
13
+ psc_exempt_as_shares_admitted_on_market: 'PSCExemptAsSharesAdmittedOnMarket',
14
+ psc_exempt_as_trading_on_uk_regulated_market: 'PSCExemptAsTradingOnUKRegulatedMarket',
15
+ sic_codes: 'SICCodes',
16
+ sic_code: 'SICCode',
17
+ presenter_id: 'PresenterID',
18
+ 'SICCode' => 'SICCode'
19
+ }.freeze
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class APIError < CompaniesHouseGatewayError
5
+ attr_accessor :error_code
6
+
7
+ def initialize(message = nil, error_code = nil, status = nil, response_body = nil)
8
+ super(message, status, response_body)
9
+ @error_code = error_code
10
+ end
11
+
12
+ def to_s
13
+ str = super
14
+ str += " [Error code: #{error_code}]" if error_code
15
+ str
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class CompaniesHouseGatewayError < StandardError
5
+ attr_reader :message
6
+ attr_reader :status
7
+ attr_reader :response_body
8
+
9
+ def initialize(message = nil, status = nil, _response = nil)
10
+ @message = message
11
+ @status = status
12
+ @response_body = response_body
13
+ end
14
+
15
+ def to_s
16
+ status_string = @status.nil? ? '' : "(Status #{@status}) "
17
+ "#{status_string}#{@message}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class InvalidRequestError < CompaniesHouseGatewayError
5
+ attr_accessor :param
6
+
7
+ def initialize(message = nil, param = nil, status = nil, response_body = nil)
8
+ super(message, status, response_body)
9
+ @param = param
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class InvalidResponseError < CompaniesHouseGatewayError
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class FormValidator
5
+ def self.validate(data, request_class)
6
+ form_validator = new(data, request_class)
7
+ validation = form_validator.validate_data
8
+
9
+ if validation.failure?
10
+ msg = "#{request_class} - has request parameters error: #{validation.errors.to_hash}"
11
+ raise InvalidRequestError.new(msg, data)
12
+ end
13
+ validation
14
+ end
15
+
16
+ def initialize(data, request_class)
17
+ @data = data
18
+ @request_class = request_class
19
+ end
20
+
21
+ def validate_data
22
+ Validations.const_get(:"#{request_class}").call(data)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :data, :request_class
28
+ end
29
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Forms
5
+ class FormAbstractBuilder
6
+ attr_reader :xml, :data
7
+
8
+ def initialize(xml: nil, data: {})
9
+ @xml = xml
10
+ @data = data
11
+ end
12
+
13
+ def build_form(_request_type, _requested_form = nil)
14
+ raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
15
+ end
16
+
17
+ def generate_xml_from_incoming_data(data, request_type, parent = nil, first_iteration = false)
18
+ return if data.to_s.empty?
19
+ return unless data.is_a?(Hash)
20
+
21
+ unless parent
22
+ builder = Nokogiri::XML::Builder.new do |xml|
23
+ xml.send(request_type, form_namespace) do
24
+ generate_xml_from_incoming_data(data, request_type, xml)
25
+ end
26
+ end
27
+
28
+ return builder
29
+ end
30
+
31
+ if first_iteration
32
+ request_type = Util.camelize(request_type)
33
+ parent.send(request_type, form_namespace) do
34
+ generate_xml_from_incoming_data(data, request_type, parent)
35
+ end
36
+
37
+ return parent
38
+ end
39
+
40
+ data.each do |label, value|
41
+ label = Constants::SPECIAL_FIELDS_MAPPER[label] || Util.camelize(label)
42
+ if value.is_a?(Hash)
43
+ parent.send(label) do
44
+ generate_xml_from_incoming_data(value, request_type, parent)
45
+ end
46
+
47
+ elsif value.is_a?(Array)
48
+ value.each do |el|
49
+ el = { label => el }
50
+ generate_xml_from_incoming_data(el, request_type, parent)
51
+ end
52
+
53
+ else
54
+ value = value.is_a?(BigDecimal) ? value.to_f : value
55
+ parent.send(label, value)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Forms
5
+ class FormCompanyDataRequest < FormAbstractBuilder
6
+ def build_form(request_type, requested_form = nil)
7
+ generate_xml_from_incoming_data(data, request_type, requested_form, true)
8
+ end
9
+
10
+ def form_namespace
11
+ {
12
+
13
+ 'xmlns' => 'http://xmlgw.companieshouse.gov.uk',
14
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
15
+ 'xsi:schemaLocation' => 'http://xmlgw.companieshouse.gov.uk http://xmlgw.companieshouse.gov.uk/v2-1/schema/CompanyData-v3-4.xsd'
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Forms
5
+ class FormConfirmationStatement < FormAbstractBuilder
6
+ def build_form(request_type, requested_form = nil)
7
+ generate_xml_from_incoming_data(data, request_type, requested_form, true)
8
+ end
9
+
10
+ def form_namespace
11
+ {
12
+
13
+ 'xmlns' => 'http://xmlgw.companieshouse.gov.uk',
14
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
15
+ 'xsi:schemaLocation' => 'http://xmlgw.companieshouse.gov.uk http://xmlgw.companieshouse.gov.uk/v1-0/schema/forms/ConfirmationStatement-v1-2.xsd'
16
+
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Forms
5
+ class FormGetSubmissionStatus < FormAbstractBuilder
6
+ def build_form(request_type, requested_form = nil)
7
+ generate_xml_from_incoming_data(data, request_type, requested_form, true)
8
+ end
9
+
10
+ def form_namespace
11
+ {
12
+
13
+ 'xmlns' => 'http://xmlgw.companieshouse.gov.uk',
14
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
15
+ 'xsi:schemaLocation' => 'http://xmlgw.companieshouse.gov.uk http://xmlgw.companieshouse.gov.uk/v1-0/schema/forms/GetSubmissionStatus-v2-9.xsd'
16
+
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Forms
5
+ class FormReturnofAllotmentShares < FormAbstractBuilder
6
+ def build_form(request_type, requested_form = nil)
7
+ generate_xml_from_incoming_data(data, request_type, requested_form, true)
8
+ end
9
+
10
+ def form_namespace
11
+ {
12
+
13
+ 'xmlns' => 'http://xmlgw.companieshouse.gov.uk',
14
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
15
+ 'xsi:schemaLocation' => 'http://xmlgw.companieshouse.gov.uk http://xmlgw.companieshouse.gov.uk/v1-0/schema/forms/ReturnofAllotmentShares-v3-0.xsd'
16
+
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Forms
5
+ class FormSubmission < FormAbstractBuilder
6
+ def build_form(request_type, requested_form = nil)
7
+ FormValidator.validate(data, Util.demodulize(self.class))
8
+
9
+ xml.FormSubmission(submission_namespace) do
10
+ form_header(xml, request_type, data)
11
+ xml.DateSigned data[:date_signed] # "2015-07-01"
12
+ xml.Form do
13
+ requested_form.build_form(request_type, xml)
14
+ end
15
+ end
16
+ end
17
+
18
+ def submission_namespace
19
+ {
20
+ 'xmlns' => 'http://xmlgw.companieshouse.gov.uk/Header',
21
+ 'xmlns:bs' => 'http://xmlgw.companieshouse.gov.uk',
22
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
23
+ 'xsi:schemaLocation' => 'http://xmlgw.companieshouse.gov.uk/Header http://xmlgw.companieshouse.gov.uk/v1-0/schema/forms/FormSubmission-v2-9.xsd'
24
+ }
25
+ end
26
+
27
+ def form_header(root_xml, request_type, data)
28
+ root_xml.FormHeader do
29
+ root_xml.CompanyNumber data[:company_number]
30
+ root_xml.CompanyName data[:company_name]
31
+ root_xml.CompanyAuthenticationCode data[:company_authentication_code]
32
+ root_xml.PackageReference data[:package_reference]
33
+ root_xml.FormIdentifier Util.camelize(request_type)
34
+ root_xml.SubmissionNumber data[:submission_number]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Middleware
5
+ class CheckResponse < Faraday::Middleware
6
+ def call(env)
7
+ @app.call(env).on_complete do |item|
8
+ check_for_errors(item)
9
+ response_values(item)
10
+ end
11
+ end
12
+
13
+ def response_values(env)
14
+ { status: env[:status], headers: env[:headers], body: env[:body] }
15
+ end
16
+
17
+ def check_for_errors(env)
18
+ body = env[:body]['GovTalkMessage']
19
+ raise InvalidResponseError.new(env[:body], env[:status], env) unless body && body['GovTalkDetails']
20
+
21
+ if body['GovTalkDetails']['GovTalkErrors']
22
+ error = body['GovTalkDetails']['GovTalkErrors'].values.flatten.first
23
+ raise APIError.new(error['Text'], error['Number'], env[:status], env)
24
+ end
25
+ end
26
+ end
27
+
28
+ Faraday::Response.register_middleware check_ch_response: CheckResponse
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ class Request
5
+ def initialize(connection, config)
6
+ @connection = connection
7
+ @config = config
8
+ end
9
+
10
+ def perform(request_type, request_data = {}, require_submission_form)
11
+ xml_form = XmlFormsBinder.new(request_type, @config, request_data)
12
+
13
+ request_type = Util.camelize(request_type)
14
+ unless Constants::SUPPORTED_REQUESTS.include?(request_type)
15
+ msg = "Unsupported request type #{request_type}"
16
+ raise CompaniesHouseGatewayError, msg
17
+ end
18
+
19
+ response = @connection.post do |request|
20
+ request.path = @config[:api_endpoint]
21
+ request_body = xml_form.build_request_xml(require_submission_form).to_s
22
+ if defined?(Rails)
23
+ Rails.logger.tagged('CompaniesHouseInputGateway', 'XmlRequest') do
24
+ Rails.logger.info xml_data: request_body
25
+ end
26
+ end
27
+ request.body = request_body
28
+ request.options.open_timeout = @config[:open_timeout]
29
+ request.options.timeout = @config[:timeout]
30
+ end
31
+
32
+ xml_response = @config[:raw] ? response : response.body
33
+ if defined?(Rails)
34
+ Rails.logger.tagged('CompaniesHouseInputGateway', 'XmlResponse') do
35
+ Rails.logger.info xml_data: xml_response
36
+ end
37
+ end
38
+ xml_response
39
+ rescue Faraday::ClientError => e
40
+ if e.response.nil?
41
+ raise CompaniesHouseGatewayError
42
+ else
43
+ raise CompaniesHouseGatewayError.new(e.response[:body],
44
+ e.response[:status],
45
+ e.response)
46
+ end
47
+ rescue Faraday::ServerError => e
48
+ raise CompaniesHouseGatewayError.new(e.response[:body],
49
+ e.response[:status],
50
+ e.response)
51
+ rescue Faraday::ParsingError => e
52
+ raise CompaniesHouseGatewayError.new(e.response[:body],
53
+ e.response[:status],
54
+ e.response)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Requests
5
+ module AbstractPerformer
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ def perform(data = {})
15
+ require_submission_form = self.class.submission_form
16
+ validate_params(data, Util.demodulize(self.class))
17
+ check_type = Util.underscore(Util.demodulize(self.class))
18
+ response = @client.perform_check(check_type, data, require_submission_form)
19
+
20
+ @client.config[:raw] ? response : response_body(response)
21
+ end
22
+
23
+ private
24
+
25
+ def validate_params(data, request_class)
26
+ FormValidator.validate(data[:request_data], request_class)
27
+ end
28
+
29
+ def response_body(response)
30
+ body = response['GovTalkMessage']['Body']
31
+
32
+ return response if body.nil?
33
+
34
+ body[Util.demodulize(self.class)] || body.dig('SubmissionStatus', 'Status') || body['CompanyData']
35
+ end
36
+
37
+ module ClassMethods
38
+ def require_submission_form(value)
39
+ unless [true, false].include?(value)
40
+ raise ArgumentError, "The method #{__method__} in called in accepts only Boolean true, false values"
41
+ end
42
+
43
+ @submission_form = value
44
+ end
45
+
46
+ def submission_form
47
+ @submission_form
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Requests
5
+ class CompanyDataRequest
6
+ include AbstractPerformer
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Requests
5
+ class ConfirmationStatement
6
+ include AbstractPerformer
7
+
8
+ require_submission_form true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Requests
5
+ class GetSubmissionStatus
6
+ include AbstractPerformer
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Requests
5
+ class ReturnofAllotmentShares
6
+ include AbstractPerformer
7
+
8
+ require_submission_form true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module CompaniesHouseInputGateway
6
+ module Util
7
+ module_function
8
+
9
+ def camelize(str)
10
+ str.to_s.split('_').map(&:capitalize).join
11
+ end
12
+
13
+ def underscore(str)
14
+ str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
15
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
16
+ .tr('-', '_')
17
+ .downcase
18
+ end
19
+
20
+ def demodulize(str)
21
+ str.to_s.split('::').last
22
+ end
23
+
24
+ def create_digest(value)
25
+ Digest::MD5.hexdigest(value)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseInputGateway
4
+ module Validations
5
+ CompanyDataRequest = Dry::Validation.Schema do
6
+ configure do
7
+ config.messages_file = File.join(Base.root, './errors.yml')
8
+
9
+ def company_number_format?(value)
10
+ value ? value.match(/^([\d]*\d){8}$/) : true
11
+ end
12
+ end
13
+
14
+ required(:company_number).filled(:str?)
15
+ required(:company_authentication_code).filled(:str?, size?: 6)
16
+ required(:made_up_date).filled(:date?)
17
+ required(:company_number).filled(:company_number_format?)
18
+ end
19
+ end
20
+ end