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
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe CompaniesHouseGateway::Request do
4
+ let(:request) { CompaniesHouseGateway::Request.new(connection, config) }
5
+ let(:config) { CompaniesHouseGateway::Config.new }
6
+ let(:connection) do
7
+ CompaniesHouseGateway::Client.new(config).send(:connection)
8
+ end
9
+
10
+ let(:response_hash) { { status: status, body: body } }
11
+ let(:status) { 200 }
12
+ let(:body) { "<Results><Errors/></Results>" }
13
+ before { stub_request(:post, config[:api_endpoint]).to_return(response_hash) }
14
+
15
+ let(:request_type) { :name_search }
16
+ let(:request_data) { {} }
17
+
18
+ describe '#build_request_xml' do
19
+ subject(:request_xml) do
20
+ request.build_request_xml(request_type, request_data)
21
+ end
22
+ let(:xml_schema) { load_fixture('request.xsd') }
23
+ let(:xsd) { Nokogiri::XML::Schema(xml_schema) }
24
+
25
+ it "generates a valid XML request" do
26
+ xsd.validate(request_xml).should == []
27
+ end
28
+
29
+ context "with an email address" do
30
+ before { config[:email] = "grey@gocardless.com" }
31
+
32
+ it "generates a valid XML request" do
33
+ xsd.validate(request_xml).should == []
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#perform" do
39
+ subject(:perform_check) { request.perform(request_type, request_data) }
40
+
41
+ it "makes a get request" do
42
+ perform_check
43
+ a_request(:post, config[:api_endpoint]).should have_been_made
44
+ end
45
+
46
+ context "when the config[:raw] is true" do
47
+ before { config[:raw] = true }
48
+ it { should be_a Faraday::Response }
49
+ its(:body) { should be_a String }
50
+ end
51
+
52
+ context "when the config[:raw] is false" do
53
+ it { should be_a Hash }
54
+ it { should include "Results" }
55
+
56
+ context "errors" do
57
+ context "500" do
58
+ let(:status) { 500 }
59
+
60
+ it "wraps the error" do
61
+ expect { perform_check }.
62
+ to raise_error CompaniesHouseGateway::CompaniesHouseGatewayError
63
+ end
64
+ end
65
+
66
+ context "400" do
67
+ let(:status) { 400 }
68
+
69
+ it "wraps the error" do
70
+ expect { perform_check }.
71
+ to raise_error CompaniesHouseGateway::CompaniesHouseGatewayError
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,40 @@
1
+ shared_examples 'it validates presence' do |property|
2
+ let(:client) { CompaniesHouseGateway::Client.new(config) }
3
+ let(:config) { CompaniesHouseGateway::Config.new }
4
+ subject(:perform_check) { described_class.new(client).perform(check_data) }
5
+
6
+ context "with a missing #{property}" do
7
+ before { check_data.delete(property) }
8
+
9
+ it "raises and error" do
10
+ expect { perform_check }.
11
+ to raise_error CompaniesHouseGateway::CompaniesHouseGatewayError
12
+ end
13
+ end
14
+ end
15
+
16
+ shared_examples 'it generates_valid_xml' do
17
+ let(:request) { CompaniesHouseGateway::Request.new(connection, config) }
18
+ let(:client) { CompaniesHouseGateway::Client.new(config) }
19
+ let(:config) { CompaniesHouseGateway::Config.new }
20
+ let(:connection) { client.send(:connection) }
21
+ let(:klass) { described_class.name.split("::").last }
22
+
23
+ let(:request_xml) do
24
+ builder = Nokogiri::XML::Builder.new do |xml|
25
+ request.send(:request_body, xml, klass, check_data)
26
+ end
27
+ builder.doc
28
+ end
29
+
30
+ let(:xsd_path) do
31
+ fixture_path('checks',
32
+ "#{CompaniesHouseGateway::Util.underscore(klass)}.xsd")
33
+ end
34
+ let(:xsd_doc) { Nokogiri::XML(File.read(xsd_path), xsd_path) }
35
+ let(:xsd) { Nokogiri::XML::Schema.from_document(xsd_doc) }
36
+
37
+ it "generates a valid XML request" do
38
+ xsd.validate(request_xml).should == []
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ require 'companies_house_gateway'
2
+ require 'webmock/rspec'
3
+ require 'shared_examples'
4
+ RSpec.configure { |config| config.include WebMock::API }
5
+
6
+ def configure_companies_house_gateway
7
+ CompaniesHouseGateway.configure { |config| config[:sender_id] = "Grey" }
8
+ end
9
+
10
+ def load_fixture(*filename)
11
+ File.open(fixture_path(filename)).read
12
+ end
13
+
14
+ def fixture_path(*filename)
15
+ File.join('spec', 'fixtures', *filename)
16
+ end
17
+
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: companies-house-gateway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Grey Baker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_xml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby wrapper for the Companies House XML Gateway
98
+ email:
99
+ - grey@gocardless.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - companies_house_gateway.gemspec
110
+ - lib/companies_house_gateway.rb
111
+ - lib/companies_house_gateway/checks/check.rb
112
+ - lib/companies_house_gateway/checks/company_appointments.rb
113
+ - lib/companies_house_gateway/checks/company_details.rb
114
+ - lib/companies_house_gateway/checks/document.rb
115
+ - lib/companies_house_gateway/checks/document_info.rb
116
+ - lib/companies_house_gateway/checks/filing_history.rb
117
+ - lib/companies_house_gateway/checks/mortgages.rb
118
+ - lib/companies_house_gateway/checks/name_search.rb
119
+ - lib/companies_house_gateway/checks/number_search.rb
120
+ - lib/companies_house_gateway/checks/officer_details.rb
121
+ - lib/companies_house_gateway/checks/officer_search.rb
122
+ - lib/companies_house_gateway/client.rb
123
+ - lib/companies_house_gateway/config.rb
124
+ - lib/companies_house_gateway/constants.rb
125
+ - lib/companies_house_gateway/errors/companies_house_gateway_error.rb
126
+ - lib/companies_house_gateway/request.rb
127
+ - lib/companies_house_gateway/util.rb
128
+ - lib/companies_house_gateway/version.rb
129
+ - spec/checks/company_appointments_spec.rb
130
+ - spec/checks/company_details_spec.rb
131
+ - spec/checks/document_info_spec.rb
132
+ - spec/checks/document_spec.rb
133
+ - spec/checks/filing_history_spec.rb
134
+ - spec/checks/mortgages_spec.rb
135
+ - spec/checks/name_search_spec.rb
136
+ - spec/checks/number_search_spec.rb
137
+ - spec/checks/officer_details_spec.rb
138
+ - spec/checks/officer_search_spec.rb
139
+ - spec/client_spec.rb
140
+ - spec/companies_house_gateway_spec.rb
141
+ - spec/fixtures/checks/chbase.xsd
142
+ - spec/fixtures/checks/company_appointments.xsd
143
+ - spec/fixtures/checks/company_details.xsd
144
+ - spec/fixtures/checks/document.xsd
145
+ - spec/fixtures/checks/document_info.xsd
146
+ - spec/fixtures/checks/filing_history.xsd
147
+ - spec/fixtures/checks/mortgages.xsd
148
+ - spec/fixtures/checks/name_search.xsd
149
+ - spec/fixtures/checks/number_search.xsd
150
+ - spec/fixtures/checks/officer_details.xsd
151
+ - spec/fixtures/checks/officer_search.xsd
152
+ - spec/fixtures/request.xsd
153
+ - spec/request_spec.rb
154
+ - spec/shared_examples.rb
155
+ - spec/spec_helper.rb
156
+ homepage: https://github.com/gocardless/companies-house-gateway-ruby
157
+ licenses: []
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.2.2
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Ruby wrapper for the Companies House XML Gateway
179
+ test_files:
180
+ - spec/checks/company_appointments_spec.rb
181
+ - spec/checks/company_details_spec.rb
182
+ - spec/checks/document_info_spec.rb
183
+ - spec/checks/document_spec.rb
184
+ - spec/checks/filing_history_spec.rb
185
+ - spec/checks/mortgages_spec.rb
186
+ - spec/checks/name_search_spec.rb
187
+ - spec/checks/number_search_spec.rb
188
+ - spec/checks/officer_details_spec.rb
189
+ - spec/checks/officer_search_spec.rb
190
+ - spec/client_spec.rb
191
+ - spec/companies_house_gateway_spec.rb
192
+ - spec/fixtures/checks/chbase.xsd
193
+ - spec/fixtures/checks/company_appointments.xsd
194
+ - spec/fixtures/checks/company_details.xsd
195
+ - spec/fixtures/checks/document.xsd
196
+ - spec/fixtures/checks/document_info.xsd
197
+ - spec/fixtures/checks/filing_history.xsd
198
+ - spec/fixtures/checks/mortgages.xsd
199
+ - spec/fixtures/checks/name_search.xsd
200
+ - spec/fixtures/checks/number_search.xsd
201
+ - spec/fixtures/checks/officer_details.xsd
202
+ - spec/fixtures/checks/officer_search.xsd
203
+ - spec/fixtures/request.xsd
204
+ - spec/request_spec.rb
205
+ - spec/shared_examples.rb
206
+ - spec/spec_helper.rb