companies-house-gateway 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/CHANGELOG.md +20 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +22 -0
  6. data/README.md +28 -0
  7. data/companies_house_gateway.gemspec +22 -0
  8. data/lib/companies_house_gateway.rb +60 -0
  9. data/lib/companies_house_gateway/checks/check.rb +66 -0
  10. data/lib/companies_house_gateway/checks/company_appointments.rb +14 -0
  11. data/lib/companies_house_gateway/checks/company_details.rb +11 -0
  12. data/lib/companies_house_gateway/checks/document.rb +10 -0
  13. data/lib/companies_house_gateway/checks/document_info.rb +11 -0
  14. data/lib/companies_house_gateway/checks/filing_history.rb +12 -0
  15. data/lib/companies_house_gateway/checks/mortgages.rb +16 -0
  16. data/lib/companies_house_gateway/checks/name_search.rb +17 -0
  17. data/lib/companies_house_gateway/checks/number_search.rb +13 -0
  18. data/lib/companies_house_gateway/checks/officer_details.rb +12 -0
  19. data/lib/companies_house_gateway/checks/officer_search.rb +16 -0
  20. data/lib/companies_house_gateway/client.rb +45 -0
  21. data/lib/companies_house_gateway/config.rb +31 -0
  22. data/lib/companies_house_gateway/constants.rb +8 -0
  23. data/lib/companies_house_gateway/errors/companies_house_gateway_error.rb +18 -0
  24. data/lib/companies_house_gateway/request.rb +105 -0
  25. data/lib/companies_house_gateway/util.rb +20 -0
  26. data/lib/companies_house_gateway/version.rb +3 -0
  27. data/spec/checks/company_appointments_spec.rb +16 -0
  28. data/spec/checks/company_details_spec.rb +10 -0
  29. data/spec/checks/document_info_spec.rb +16 -0
  30. data/spec/checks/document_spec.rb +11 -0
  31. data/spec/checks/filing_history_spec.rb +10 -0
  32. data/spec/checks/mortgages_spec.rb +16 -0
  33. data/spec/checks/name_search_spec.rb +10 -0
  34. data/spec/checks/number_search_spec.rb +10 -0
  35. data/spec/checks/officer_details_spec.rb +11 -0
  36. data/spec/checks/officer_search_spec.rb +11 -0
  37. data/spec/client_spec.rb +58 -0
  38. data/spec/companies_house_gateway_spec.rb +49 -0
  39. data/spec/fixtures/checks/chbase.xsd +1037 -0
  40. data/spec/fixtures/checks/company_appointments.xsd +74 -0
  41. data/spec/fixtures/checks/company_details.xsd +108 -0
  42. data/spec/fixtures/checks/document.xsd +56 -0
  43. data/spec/fixtures/checks/document_info.xsd +56 -0
  44. data/spec/fixtures/checks/filing_history.xsd +77 -0
  45. data/spec/fixtures/checks/mortgages.xsd +58 -0
  46. data/spec/fixtures/checks/name_search.xsd +41 -0
  47. data/spec/fixtures/checks/number_search.xsd +29 -0
  48. data/spec/fixtures/checks/officer_details.xsd +99 -0
  49. data/spec/fixtures/checks/officer_search.xsd +37 -0
  50. data/spec/fixtures/request.xsd +290 -0
  51. data/spec/request_spec.rb +77 -0
  52. data/spec/shared_examples.rb +40 -0
  53. data/spec/spec_helper.rb +17 -0
  54. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35fc32ab120eec1eda0045fb17825c8002d74a0e
4
+ data.tar.gz: 75bccea34dd2828c0a8b043653f3af63ea0578cd
5
+ SHA512:
6
+ metadata.gz: 4c2e6547c39056632631be167c1073a4453cc706e66290ea3646b1c60cda828a57b510e5bb678f467f22c28daee37ab10ae7ccd42e5adbefaea3ce407396a5e2
7
+ data.tar.gz: 796529dcddcc0e3decc0e7820e272b8657bd4a89ca87a0f363d3b5ec065865d52fd9d3619475fb328f51859fbb23a321018d1fdc658cca5d53549657fe920da6
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .bundle
3
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ ## 0.2.0 - February 23, 2014
2
+
3
+ - Add filing_history and document_info and document classes. Gem now covers
4
+ all possible request types
5
+
6
+ ## 0.1.2 - February 23, 2014
7
+
8
+ - Add officer_details and officer_search classes
9
+
10
+ ## 0.1.1 - February 22, 2014
11
+
12
+ - Add company_appointments class
13
+
14
+ ## 0.1.0 - February 22, 2014
15
+
16
+ - Add name_search and number_search classes
17
+
18
+ ## 0.0.1 - February 19, 2014
19
+
20
+ - Initial commit
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Grey Baker
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Companies House XML Gateway Ruby Client Library
2
+
3
+ Simple Ruby Gem for interacting with the Companies House XML Gateway API. Wraps
4
+ the XML submissions and responses required so you can deal with Ruby hashes
5
+ instead.
6
+
7
+ ## Usage
8
+
9
+ ### Installation
10
+
11
+ You don't need this source code unless you want to modify the gem. If you just
12
+ want to use it, you should run:
13
+
14
+ ```ruby
15
+ gem install companies_house_gateway
16
+ ````
17
+
18
+ ### Initialising the gem
19
+ Requires your Companies House XML Gateway credentials. If you don't have any,
20
+ you'll need to get in touch with
21
+ [Companies House](http://xmlgw.companieshouse.gov.uk/).
22
+
23
+ ```ruby
24
+ CompaniesHouseGateway.configure do |config|
25
+ config[:sender_id] = YOUR_SENDER_ID
26
+ config[:password] = YOUR_PASSWORD
27
+ end
28
+ ```
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../lib/companies_house_gateway/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.add_runtime_dependency 'faraday', '~> 0.8.0'
5
+ gem.add_runtime_dependency 'faraday_middleware', '>= 0.8.2'
6
+ gem.add_runtime_dependency 'multi_xml', '~> 0.5.1'
7
+ gem.add_runtime_dependency 'nokogiri', '~> 1.4'
8
+
9
+ gem.add_development_dependency 'rspec'
10
+ gem.add_development_dependency 'webmock'
11
+
12
+ gem.authors = ['Grey Baker']
13
+ gem.description = %q{Ruby wrapper for the Companies House XML Gateway}
14
+ gem.email = ['grey@gocardless.com']
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.homepage = 'https://github.com/gocardless/companies-house-gateway-ruby'
17
+ gem.name = 'companies-house-gateway'
18
+ gem.require_paths = ['lib']
19
+ gem.summary = %q{Ruby wrapper for the Companies House XML Gateway}
20
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ gem.version = CompaniesHouseGateway::VERSION.dup
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'faraday_middleware'
2
+ require 'nokogiri'
3
+
4
+ require 'companies_house_gateway/version'
5
+ require 'companies_house_gateway/constants'
6
+ require 'companies_house_gateway/util'
7
+ require 'companies_house_gateway/config'
8
+ require 'companies_house_gateway/request'
9
+ require 'companies_house_gateway/client'
10
+
11
+ require 'companies_house_gateway/errors/companies_house_gateway_error'
12
+
13
+ require 'companies_house_gateway/checks/check'
14
+ require 'companies_house_gateway/checks/name_search'
15
+ require 'companies_house_gateway/checks/number_search'
16
+ require 'companies_house_gateway/checks/company_appointments'
17
+ require 'companies_house_gateway/checks/company_details'
18
+ require 'companies_house_gateway/checks/officer_search'
19
+ require 'companies_house_gateway/checks/officer_details'
20
+ require 'companies_house_gateway/checks/mortgages'
21
+ require 'companies_house_gateway/checks/filing_history'
22
+ require 'companies_house_gateway/checks/document_info'
23
+ require 'companies_house_gateway/checks/document'
24
+
25
+ module CompaniesHouseGateway
26
+ def self.configure(&block)
27
+ @config = Config.new(&block)
28
+ end
29
+
30
+ def self.perform_check(*args)
31
+ client.perform_check(*args)
32
+ end
33
+
34
+ Constants::SUPPORTED_REQUESTS.each do |name|
35
+ class_eval <<-EOM
36
+ def self.#{Util.underscore(name)}(*args)
37
+ client.send(:#{Util.underscore(name)}, *args)
38
+ end
39
+ EOM
40
+ end
41
+
42
+ # Require configuration before use
43
+ def self.config
44
+ if @config
45
+ @config
46
+ else
47
+ msg = "No config found. Use CompaniesHouseGateway.configure to set "
48
+ "username and password. See " +
49
+ "https://github.com/gocardless/companies-house-gateway " +
50
+ "for details."
51
+ raise CompaniesHouseGatewayError.new(msg)
52
+ end
53
+ end
54
+
55
+ def self.client
56
+ @client ||= Client.new(config)
57
+ end
58
+ private_class_method :client
59
+ end
60
+
@@ -0,0 +1,66 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ module Check
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def perform(data = {})
13
+ data = self.class.default_inputs.merge(data)
14
+ check_params(data)
15
+ check_type = Util.underscore(Util.demodulize(self.class))
16
+ @client.perform_check(check_type, data)
17
+ end
18
+
19
+ private
20
+
21
+ def check_params(data)
22
+ self.class.required_inputs.each do |param|
23
+ if data[param].nil?
24
+ msg = "#{Util.demodulize(self.class)} requires a #{param}"
25
+ raise CompaniesHouseGatewayError.new(msg)
26
+ end
27
+ end
28
+
29
+ data.keys.each do |param|
30
+ unless self.class.allowed_inputs.include?(param)
31
+ msg = "#{Util.demodulize(self.class)} does not accept " +
32
+ "#{param}. Only the following inputs are permitted: " +
33
+ "#{self.class.allowed_inputs.to_a}"
34
+ raise CompaniesHouseGatewayError.new(msg)
35
+ end
36
+ end
37
+ end
38
+
39
+ module ClassMethods
40
+ # Add one or more required arguments
41
+ def required_input(*inputs)
42
+ @required_inputs = self.required_inputs.union(inputs)
43
+ end
44
+
45
+ # Accessor for the check's required arguments
46
+ def required_inputs
47
+ @required_inputs ||= Set.new
48
+ end
49
+
50
+ # Add one or more default arguments
51
+ def default_input(input)
52
+ @default_inputs = input.merge(self.default_inputs)
53
+ end
54
+
55
+ # Accessor for the check's default arguments
56
+ def default_inputs
57
+ @default_inputs ||= {}
58
+ end
59
+
60
+ def allowed_inputs
61
+ self.required_inputs.union(self.default_inputs.keys)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,14 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class CompanyAppointments
4
+ include Check
5
+
6
+ required_input :company_name,
7
+ :company_number,
8
+ :user_reference
9
+
10
+ default_input continuation_key: nil,
11
+ include_resigned_ind: false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class CompanyDetails
4
+ include Check
5
+
6
+ required_input :company_number
7
+
8
+ default_input give_mort_totals: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class Document
4
+ include Check
5
+
6
+ required_input :doc_request_key,
7
+ :user_reference
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class DocumentInfo
4
+ include Check
5
+
6
+ required_input :company_name,
7
+ :company_number,
8
+ :image_key
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class FilingHistory
4
+ include Check
5
+
6
+ required_input :company_number
7
+
8
+ default_input capital_doc_ind: false,
9
+ continuation_key: nil
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class Mortgages
4
+ include Check
5
+
6
+ required_input :company_name,
7
+ :company_number,
8
+ :user_reference
9
+
10
+ default_input satisfied_charges_ind: false,
11
+ start_date: nil,
12
+ end_date: nil,
13
+ continuation_key: nil
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class NameSearch
4
+ include Check
5
+
6
+ required_input :company_name,
7
+ :data_set
8
+
9
+ default_input data_set: "LIVE",
10
+ same_as: false,
11
+ search_rows: 20,
12
+ continuation_key: nil,
13
+ regression_key: nil
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class NumberSearch
4
+ include Check
5
+
6
+ required_input :partial_company_number,
7
+ :data_set
8
+
9
+ default_input data_set: "LIVE",
10
+ search_rows: 20
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class OfficerDetails
4
+ include Check
5
+
6
+ required_input :person_id,
7
+ :user_reference
8
+
9
+ default_input continuation_key: nil
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module CompaniesHouseGateway
2
+ module Checks
3
+ class OfficerSearch
4
+ include Check
5
+
6
+ required_input :surname,
7
+ :officer_type
8
+
9
+ default_input forename: nil,
10
+ post_town: nil,
11
+ country_of_residence: nil,
12
+ continuation_key: nil,
13
+ include_resigned_ind: false
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,45 @@
1
+ module CompaniesHouseGateway
2
+ class Client
3
+ def initialize(config=nil)
4
+ @config = (config || CompaniesHouseGateway.config).clone
5
+ end
6
+
7
+ def perform_check(*args)
8
+ request = Request.new(connection, @config)
9
+ request.perform(*args)
10
+ end
11
+
12
+ def config
13
+ @config
14
+ end
15
+
16
+ Constants::SUPPORTED_REQUESTS.each do |name|
17
+ class_eval <<-EOM
18
+ def #{Util.underscore(name)}(*args)
19
+ check = CompaniesHouseGateway::Checks.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 |conn|
38
+ conn.response :xml unless @config[:raw] # Parse response
39
+ conn.response :follow_redirects, limit: 3 # Follow redirect
40
+ conn.response :raise_error # Raise errors
41
+ conn.adapter @config[:adapter]
42
+ end
43
+ end
44
+ end
45
+ end