companies-house 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +0 -2
- data/companies-house.gemspec +3 -3
- data/lib/companies_house.rb +35 -9
- data/spec/lib/companies_house_spec.rb +76 -24
- metadata +4 -6
- data/spec/spec.opts +0 -7
- data/spec/spec_helper.rb +0 -9
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/companies-house.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{companies-house}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Rob McKinnon"]
|
9
|
-
s.date = %q{2010-10-
|
9
|
+
s.date = %q{2010-10-22}
|
10
10
|
s.description = %q{Ruby API to UK Companies House XML Gateway.
|
11
11
|
}
|
12
12
|
s.email = ["rob ~@nospam@~ rubyforge.org"]
|
13
13
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
|
14
|
-
s.files = ["CHANGELOG", "companies-house.yml.example", "init.rb", "lib/companies_house/company_details.haml", "lib/companies_house/exception.rb", "lib/companies_house/name_search.haml", "lib/companies_house/number_search.haml", "lib/companies_house/request.haml", "lib/companies_house/request.rb", "lib/companies_house.rb", "LICENSE", "Manifest", "Rakefile", "README", "README.rdoc", "spec/lib/companies_house/request_spec.rb", "spec/lib/companies_house_spec.rb", "
|
14
|
+
s.files = ["CHANGELOG", "companies-house.yml.example", "init.rb", "lib/companies_house/company_details.haml", "lib/companies_house/exception.rb", "lib/companies_house/name_search.haml", "lib/companies_house/number_search.haml", "lib/companies_house/request.haml", "lib/companies_house/request.rb", "lib/companies_house.rb", "LICENSE", "Manifest", "Rakefile", "README", "README.rdoc", "spec/lib/companies_house/request_spec.rb", "spec/lib/companies_house_spec.rb", "companies-house.gemspec"]
|
15
15
|
s.homepage = %q{}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Companies-house", "--main", "README", "--inline-source"]
|
17
17
|
s.require_paths = ["lib"]
|
data/lib/companies_house.rb
CHANGED
@@ -14,7 +14,7 @@ require File.dirname(__FILE__) + '/companies_house/exception'
|
|
14
14
|
$KCODE = 'UTF8' unless RUBY_VERSION >= "1.9"
|
15
15
|
|
16
16
|
module CompaniesHouse
|
17
|
-
VERSION = "0.0.
|
17
|
+
VERSION = "0.0.6" unless defined? CompaniesHouse::VERSION
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
@@ -83,9 +83,40 @@ module CompaniesHouse
|
|
83
83
|
|
84
84
|
def objectify response_xml
|
85
85
|
doc = Hpricot.XML(response_xml)
|
86
|
-
|
87
|
-
if
|
88
|
-
|
86
|
+
qualifier = doc.at('Qualifier')
|
87
|
+
if qualifier && qualifier.inner_text.to_s[/error/]
|
88
|
+
raise_error doc
|
89
|
+
else
|
90
|
+
body = doc.at('Body')
|
91
|
+
if body && body.children.select(&:elem?).size > 0
|
92
|
+
objectify_body body
|
93
|
+
else
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def add_to_message attribute, error, message, suffix=''
|
102
|
+
if value = error.at(attribute)
|
103
|
+
message << "#{value.inner_text}#{suffix}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def raise_error doc
|
108
|
+
message = []
|
109
|
+
if error = doc.at('Error')
|
110
|
+
add_to_message 'RaisedBy', error, message
|
111
|
+
add_to_message 'Type', error, message
|
112
|
+
add_to_message 'Number', error, message, ':'
|
113
|
+
add_to_message 'Text', error, message
|
114
|
+
end
|
115
|
+
raise CompaniesHouse::Exception.new(message.join(' '))
|
116
|
+
end
|
117
|
+
|
118
|
+
def objectify_body body
|
119
|
+
xml = body.children.select(&:elem?).first.to_s
|
89
120
|
hash = Hash.from_xml(xml)
|
90
121
|
object = Morph.from_hash(hash, CompaniesHouse)
|
91
122
|
if object && object.class.name == 'CompaniesHouse::CompanyDetails'
|
@@ -101,12 +132,7 @@ module CompaniesHouse
|
|
101
132
|
end
|
102
133
|
end
|
103
134
|
object
|
104
|
-
else
|
105
|
-
nil
|
106
135
|
end
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
136
|
|
111
137
|
def get_response(data, root_element='NameSearch')
|
112
138
|
begin
|
@@ -3,37 +3,89 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
3
3
|
describe CompaniesHouse do
|
4
4
|
|
5
5
|
describe 'when objectifying xml' do
|
6
|
-
|
7
|
-
|
8
|
-
object = CompaniesHouse.objectify xml
|
9
|
-
object.class.name.should == 'CompaniesHouse::CompanyDetails'
|
10
|
-
end
|
11
|
-
describe 'and xml contains expanded unicode' do
|
12
|
-
it 'should convert to utf8' do
|
6
|
+
describe 'and xml contains response in Body' do
|
7
|
+
it 'should return an instance of CompaniesHouse::CompanyDetails' do
|
13
8
|
xml = '<Body><company_details><company_name>£IBRA FINANCIAL SERVICES LIMITED</company_name></company_details></Body>'
|
14
9
|
object = CompaniesHouse.objectify xml
|
15
|
-
object.
|
10
|
+
object.class.name.should == 'CompaniesHouse::CompanyDetails'
|
16
11
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
describe 'and xml contains expanded unicode' do
|
13
|
+
it 'should convert to utf8' do
|
14
|
+
xml = '<Body><company_details><company_name>£IBRA FINANCIAL SERVICES LIMITED</company_name></company_details></Body>'
|
15
|
+
object = CompaniesHouse.objectify xml
|
16
|
+
object.company_name.should == "£IBRA FINANCIAL SERVICES LIMITED"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe 'and xml contains single sic_text' do
|
20
|
+
it 'should convert to sic_code sic_texts' do
|
21
|
+
xml = '<Body><company_details><sic_codes><sic_text>9261 - Operate sports arenas & stadiums</sic_text></sic_codes></company_details></Body>'
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
object = CompaniesHouse.objectify xml
|
24
|
+
object.sic_codes.sic_text.should == '9261 - Operate sports arenas & stadiums'
|
25
|
+
object.sic_codes.sic_texts.should == ['9261 - Operate sports arenas & stadiums']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
describe 'and xml contains no sic_text' do
|
29
|
+
it 'should return empty sic_code sic_texts' do
|
30
|
+
xml = '<Body><company_details><sic_codes></sic_codes></company_details></Body>'
|
31
|
+
object = CompaniesHouse.objectify xml
|
32
|
+
object.sic_codes.sic_texts.should == []
|
33
|
+
end
|
34
|
+
it 'should return empty sic_code sic_texts again' do
|
35
|
+
xml = '<Body><company_details><sic_codes><sic_text></sic_text></sic_codes></company_details></Body>'
|
36
|
+
object = CompaniesHouse.objectify xml
|
37
|
+
object.sic_codes.sic_texts.should == []
|
38
|
+
end
|
25
39
|
end
|
26
40
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
|
42
|
+
describe 'and xml contains Error' do
|
43
|
+
it 'should raise CompaniesHouse::Exception' do
|
44
|
+
xml = xml_error
|
45
|
+
lambda { CompaniesHouse.objectify xml }.should raise_error(CompaniesHouse::Exception)
|
32
46
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
|
48
|
+
it 'should include error message in exception' do
|
49
|
+
xml = xml_error
|
50
|
+
lambda { CompaniesHouse.objectify xml }.should raise_error(CompaniesHouse::Exception, 'NameSearch fatal 503: Repeat/non-incremental Transaction ID sent with request - Rejecting')
|
51
|
+
end
|
52
|
+
|
53
|
+
def xml_error
|
54
|
+
%Q|<?xml version="1.0" encoding="UTF-8" ?>
|
55
|
+
<GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader http://xmlgw.companieshouse.gov.uk/v1-0/schema/Egov_ch.xsd" xmlns="http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
|
56
|
+
<EnvelopeVersion>1.0</EnvelopeVersion>
|
57
|
+
<Header>
|
58
|
+
<MessageDetails>
|
59
|
+
<Class>NameSearch</Class>
|
60
|
+
<Qualifier>error</Qualifier>
|
61
|
+
<TransactionID>1287070383</TransactionID>
|
62
|
+
<GatewayTimestamp>2010-10-14T16:33:04-00:00</GatewayTimestamp>
|
63
|
+
</MessageDetails>
|
64
|
+
<SenderDetails>
|
65
|
+
<IDAuthentication>
|
66
|
+
<SenderID>63884537357901904930357805221487</SenderID>
|
67
|
+
<Authentication>
|
68
|
+
<Method>CHMD5</Method>
|
69
|
+
<Value>3985a067aa3f4613adcf3589b420f4e2</Value>
|
70
|
+
</Authentication>
|
71
|
+
</IDAuthentication>
|
72
|
+
</SenderDetails>
|
73
|
+
</Header>
|
74
|
+
<GovTalkDetails>
|
75
|
+
<Keys/>
|
76
|
+
<GovTalkErrors>
|
77
|
+
<Error>
|
78
|
+
<RaisedBy>NameSearch</RaisedBy>
|
79
|
+
<Number>503</Number>
|
80
|
+
<Type>fatal</Type>
|
81
|
+
<Text>Repeat/non-incremental Transaction ID sent with request - Rejecting</Text>
|
82
|
+
<Location></Location>
|
83
|
+
</Error>
|
84
|
+
</GovTalkErrors>
|
85
|
+
</GovTalkDetails>
|
86
|
+
<Body>
|
87
|
+
</Body>
|
88
|
+
</GovTalkMessage>|
|
37
89
|
end
|
38
90
|
end
|
39
91
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: companies-house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rob McKinnon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-22 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -96,8 +96,6 @@ files:
|
|
96
96
|
- README.rdoc
|
97
97
|
- spec/lib/companies_house/request_spec.rb
|
98
98
|
- spec/lib/companies_house_spec.rb
|
99
|
-
- spec/spec.opts
|
100
|
-
- spec/spec_helper.rb
|
101
99
|
- companies-house.gemspec
|
102
100
|
has_rdoc: true
|
103
101
|
homepage: ""
|
data/spec/spec.opts
DELETED