companies-house 0.0.1 → 0.0.2

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.
data/CHANGELOG CHANGED
@@ -1 +1,3 @@
1
+ v0.0.2. better responses when errors occur
2
+
1
3
  v0.0.1. initial release
data/Manifest CHANGED
@@ -1,15 +1,19 @@
1
1
  CHANGELOG
2
+ companies-house.yml.example
3
+ init.rb
4
+ lib/companies_house/company_details.haml
5
+ lib/companies_house/exception.rb
2
6
  lib/companies_house/name_search.haml
3
7
  lib/companies_house/number_search.haml
4
8
  lib/companies_house/request.haml
5
9
  lib/companies_house/request.rb
6
10
  lib/companies_house.rb
7
11
  LICENSE
12
+ Manifest
8
13
  Rakefile
9
14
  README
10
- companies-house.yml.example
15
+ README.rdoc
11
16
  spec/lib/companies_house/request_spec.rb
12
17
  spec/lib/companies_house_spec.rb
13
18
  spec/spec.opts
14
19
  spec/spec_helper.rb
15
- Manifest
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ Ruby API to UK Companies House XML Gateway.
2
+
3
+ = Companies House XML Gateway
4
+
5
+ The Companies House XML Gateway offers electronic access to a core range of
6
+ company information from Companies House Databases. The service is accessible
7
+ online over the internet by authorised XML Gateway customers.
8
+
9
+ For more details about the Companies House XML Gateway, including how to become
10
+ a registered user see: http://xmlgw.companieshouse.gov.uk/
11
+
12
+ = Disclaimer
13
+
14
+ The companies-house rubygem has been developed independently of Companies House.
15
+ It is in no way authorized or supported by Companies House.
16
+
17
+ = Example usage:
18
+
19
+ Note usage requires you have a registered account with Companies House:
20
+ http://xmlgw.companieshouse.gov.uk/faq.shtml#hdiafaxga
21
+
22
+ require 'rubygems'
23
+ require 'companies-house'
24
+
25
+ CompaniesHouse.sender_id = 'XMLGatewayTestUserID'
26
+ CompaniesHouse.password = 'password'
27
+
28
+ x = CompaniesHouse.name_search 'Canonical'
29
+
30
+ x = CompaniesHouse.number_search '05276648'
31
+
32
+ x = CompaniesHouse.company_details '05276648'
data/Rakefile CHANGED
@@ -1,29 +1,29 @@
1
- require 'rubygems'; require 'spec'; require 'lib/companies_house'
2
-
3
- begin
4
- require 'echoe'
5
-
6
- Echoe.new("companies-house", CompaniesHouse::VERSION) do |m|
7
- m.author = ["Rob McKinnon"]
8
- m.email = ["rob ~@nospam@~ rubyforge.org"]
9
- m.description = File.readlines("README").first
10
- m.rubyforge_name = "companies-house"
11
- m.rdoc_options << '--inline-source'
12
- m.rdoc_pattern = ["README", "CHANGELOG", "LICENSE"]
13
- m.dependencies = ["hpricot >=0.6", "haml >=2.0.9", "activesupport >=2.0.2", "morph >=0.2.4"]
14
- # m.executable_pattern = 'bin/companies_house'
15
- end
16
-
17
- rescue LoadError
18
- puts "You need to install the echoe gem to perform meta operations on this gem"
19
- end
20
-
21
- desc "Open an irb session preloaded with this library"
22
- task :console do
23
- sh "irb -rubygems -r ./lib/companies_house.rb"
24
- end
25
-
26
- desc "Run all examples with RCov"
27
- task :rcov do
28
- sh '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib -S rcov --text-report -o "coverage" -x "Library" spec/lib/**/*'
1
+ require 'rubygems'; require 'spec'; require 'lib/companies_house'
2
+
3
+ begin
4
+ require 'echoe'
5
+
6
+ Echoe.new("companies-house", CompaniesHouse::VERSION) do |m|
7
+ m.author = ["Rob McKinnon"]
8
+ m.email = ["rob ~@nospam@~ rubyforge.org"]
9
+ m.description = File.readlines("README").first
10
+ m.rubyforge_name = "companies-house"
11
+ m.rdoc_options << '--inline-source'
12
+ m.rdoc_pattern = ["README", "CHANGELOG", "LICENSE"]
13
+ m.dependencies = ["hpricot >=0.6", "haml >=2.0.9", "activesupport >=2.0.2", "morph >=0.2.6"]
14
+ # m.executable_pattern = 'bin/companies_house'
15
+ end
16
+
17
+ rescue LoadError
18
+ puts "You need to install the echoe gem to perform meta operations on this gem"
19
+ end
20
+
21
+ desc "Open an irb session preloaded with this library"
22
+ task :console do
23
+ sh "irb -rubygems -r ./lib/companies_house.rb"
24
+ end
25
+
26
+ desc "Run all examples with RCov"
27
+ task :rcov do
28
+ sh '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib -S rcov --text-report -o "coverage" -x "Library" spec/lib/**/*'
29
29
  end
@@ -2,42 +2,42 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{companies-house}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
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{2009-03-16}
10
- s.description = %q{Ruby API to UK Companies House XML Gateway.}
9
+ s.date = %q{2010-09-01}
10
+ s.description = %q{Ruby API to UK Companies House XML Gateway.
11
+ }
11
12
  s.email = ["rob ~@nospam@~ rubyforge.org"]
12
13
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
13
- s.files = ["CHANGELOG", "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", "Rakefile", "README", "companies-house.yml.example", "spec/lib/companies_house/request_spec.rb", "spec/lib/companies_house_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Manifest", "companies-house.gemspec"]
14
- s.has_rdoc = true
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", "spec/spec.opts", "spec/spec_helper.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"]
18
18
  s.rubyforge_project = %q{companies-house}
19
- s.rubygems_version = %q{1.3.1}
19
+ s.rubygems_version = %q{1.3.7}
20
20
  s.summary = %q{Ruby API to UK Companies House XML Gateway.}
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 2
24
+ s.specification_version = 3
25
25
 
26
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
27
  s.add_runtime_dependency(%q<hpricot>, [">= 0.6"])
28
28
  s.add_runtime_dependency(%q<haml>, [">= 2.0.9"])
29
29
  s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
30
- s.add_runtime_dependency(%q<morph>, [">= 0.2.4"])
30
+ s.add_runtime_dependency(%q<morph>, [">= 0.2.6"])
31
31
  else
32
32
  s.add_dependency(%q<hpricot>, [">= 0.6"])
33
33
  s.add_dependency(%q<haml>, [">= 2.0.9"])
34
34
  s.add_dependency(%q<activesupport>, [">= 2.0.2"])
35
- s.add_dependency(%q<morph>, [">= 0.2.4"])
35
+ s.add_dependency(%q<morph>, [">= 0.2.6"])
36
36
  end
37
37
  else
38
38
  s.add_dependency(%q<hpricot>, [">= 0.6"])
39
39
  s.add_dependency(%q<haml>, [">= 2.0.9"])
40
40
  s.add_dependency(%q<activesupport>, [">= 2.0.2"])
41
- s.add_dependency(%q<morph>, [">= 0.2.4"])
41
+ s.add_dependency(%q<morph>, [">= 0.2.6"])
42
42
  end
43
43
  end
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ begin
2
+ require File.join(File.dirname(__FILE__), 'lib', 'companies_house') # From here
3
+ rescue LoadError
4
+ require 'companies-house' # From gem
5
+ end
@@ -9,66 +9,50 @@ require 'hpricot'
9
9
  require 'haml'
10
10
 
11
11
  require File.dirname(__FILE__) + '/companies_house/request'
12
+ require File.dirname(__FILE__) + '/companies_house/exception'
12
13
 
13
14
  module CompaniesHouse
14
- VERSION = "0.0.1" unless defined? CompaniesHouse::VERSION
15
+ VERSION = "0.0.2" unless defined? CompaniesHouse::VERSION
15
16
 
16
17
  class << self
17
- def name_search name
18
- xml = CompaniesHouse::Request.name_search_xml :company_name=>name
19
- post(xml)
20
- end
21
18
 
22
- def number_search number
23
- xml = CompaniesHouse::Request.number_search_xml :company_number=>number
24
- post(xml)
19
+ def name_search name, options={}
20
+ xml = CompaniesHouse::Request.name_search_xml options.merge(:company_name => name)
21
+ get_response(xml)
25
22
  end
26
23
 
27
- def company_details number
28
- xml = CompaniesHouse::Request.company_details_xml :company_number=>number
29
- post(xml)
24
+ def number_search number, options={}
25
+ xml = CompaniesHouse::Request.number_search_xml options.merge(:company_number => number)
26
+ get_response(xml)
30
27
  end
31
28
 
32
- def post(data)
33
- begin
34
- u = "http://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/Gateway"
35
- puts "Checking url #{u}"
36
- url = URI.parse u
37
- http = Net::HTTP.new(url.host, url.port)
38
- res, body = http.post(url.path, data, {'Content-type'=>'text/xml;charset=utf-8'})
39
- case res
40
- when Net::HTTPSuccess, Net::HTTPRedirection
41
- xml = res.body
42
- doc = Hpricot.XML(xml)
43
- xml = doc.at('Body')
44
- xml = xml.children.select(&:elem?).first.to_s
45
- hash = Hash.from_xml(xml)
46
- Morph.from_hash(hash, CompaniesHouse)
47
- else
48
- raise res.inspect
49
- end
50
- rescue URI::InvalidURIError
51
- raise "URI is no good: " + u
52
- end
29
+ def company_details number, options={}
30
+ xml = CompaniesHouse::Request.company_details_xml options.merge(:company_number => number)
31
+ get_response(xml)
53
32
  end
54
33
 
55
34
  def sender_id= id
56
35
  @sender_id = id
57
36
  end
37
+
58
38
  def sender_id
59
39
  config_setup('.') if @sender_id.blank?
60
40
  @sender_id
61
41
  end
42
+
62
43
  def password= pw
63
44
  @password = pw
64
45
  end
46
+
65
47
  def password
66
48
  config_setup('.') if @password.blank?
67
49
  @password
68
50
  end
51
+
69
52
  def email= e
70
53
  @email = e
71
54
  end
55
+
72
56
  def email
73
57
  @email
74
58
  end
@@ -93,5 +77,38 @@ module CompaniesHouse
93
77
  self.email= config['email']
94
78
  end
95
79
  end
80
+
81
+ def objectify response_xml
82
+ doc = Hpricot.XML(response_xml)
83
+ xml = doc.at('Body')
84
+ if xml && xml.children.select(&:elem?).size > 0
85
+ xml = xml.children.select(&:elem?).first.to_s
86
+ hash = Hash.from_xml(xml)
87
+ Morph.from_hash(hash, CompaniesHouse)
88
+ else
89
+ nil
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def get_response(data, root_element='NameSearch')
96
+ begin
97
+ http = Net::HTTP.new("xmlgw.companieshouse.gov.uk", 80)
98
+ res, body = http.post("/v1-0/xmlgw/Gateway", data, {'Content-type'=>'text/xml;charset=utf-8'})
99
+ case res
100
+ when Net::HTTPSuccess, Net::HTTPRedirection
101
+ xml = res.body
102
+ objectify xml
103
+ else
104
+ raise CompaniesHouse::Exception.new(res.inspect.to_s)
105
+ end
106
+ rescue URI::InvalidURIError => e
107
+ raise CompaniesHouse::Exception.new(e.class.name + ' ' + e.to_s)
108
+ rescue SocketError => e
109
+ raise CompaniesHouse::Exception.new(e.class.name + ' ' + e.to_s)
110
+ end
111
+ end
112
+
96
113
  end
97
114
  end
@@ -0,0 +1,4 @@
1
+ %Body
2
+ %CompanyDetailsRequest{ :request_ns=>'' }
3
+ %CompanyNumber= company_number
4
+ %GiveMortTotals 1
@@ -0,0 +1,3 @@
1
+ class CompaniesHouse::Exception < Exception
2
+ end
3
+
@@ -4,21 +4,21 @@ describe CompaniesHouse::Request do
4
4
 
5
5
  describe "when asked for name search request xml" do
6
6
  it 'should create xml correctly' do
7
- request_xml = CompaniesHouse::Request.name_search_xml :company_name=> @company_name
7
+ request_xml = CompaniesHouse::Request.name_search_xml :company_name => @company_name
8
8
  request_xml.strip.should == @name_search_xml.strip
9
9
  end
10
10
  end
11
11
 
12
12
  describe "when asked for number search request xml" do
13
13
  it 'should create xml correctly' do
14
- request_xml = CompaniesHouse::Request.number_search_xml :company_number=> @company_number
14
+ request_xml = CompaniesHouse::Request.number_search_xml :company_number => @company_number
15
15
  request_xml.strip.should == @number_search_xml.strip
16
16
  end
17
17
  end
18
18
 
19
19
  describe "when asked for company details request xml" do
20
20
  it 'should create xml correctly' do
21
- request_xml = CompaniesHouse::Request.company_details_xml :company_number=> @company_number
21
+ request_xml = CompaniesHouse::Request.company_details_xml :company_number => @company_number
22
22
  request_xml.strip.should == @company_details_xml.strip
23
23
  end
24
24
  end
@@ -45,7 +45,7 @@ describe CompaniesHouse do
45
45
  describe "when asked for name search request" do
46
46
  it 'should perform request correctly' do
47
47
  CompaniesHouse::Request.should_receive(:name_search_xml).with(:company_name=> @company_name).and_return @request_xml
48
- CompaniesHouse.should_receive(:post).with(@request_xml).and_return @response_xml
48
+ CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
49
49
  CompaniesHouse.name_search(@company_name).should == @response_xml
50
50
  end
51
51
  end
@@ -53,7 +53,7 @@ describe CompaniesHouse do
53
53
  describe "when asked for number search request" do
54
54
  it 'should perform request correctly' do
55
55
  CompaniesHouse::Request.should_receive(:number_search_xml).with(:company_number=> @company_number).and_return @request_xml
56
- CompaniesHouse.should_receive(:post).with(@request_xml).and_return @response_xml
56
+ CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
57
57
  CompaniesHouse.number_search(@company_number).should == @response_xml
58
58
  end
59
59
  end
@@ -61,7 +61,7 @@ describe CompaniesHouse do
61
61
  describe "when asked for company details request" do
62
62
  it 'should perform request correctly' do
63
63
  CompaniesHouse::Request.should_receive(:company_details_xml).with(:company_number=> @company_number).and_return @request_xml
64
- CompaniesHouse.should_receive(:post).with(@request_xml).and_return @response_xml
64
+ CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
65
65
  CompaniesHouse.company_details(@company_number).should == @response_xml
66
66
  end
67
67
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: companies-house
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Rob McKinnon
@@ -9,50 +15,75 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-03-16 00:00:00 +00:00
18
+ date: 2010-09-01 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: hpricot
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 0
32
+ - 6
23
33
  version: "0.6"
24
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: haml
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 29
45
+ segments:
46
+ - 2
47
+ - 0
48
+ - 9
33
49
  version: 2.0.9
34
- version:
50
+ type: :runtime
51
+ version_requirements: *id002
35
52
  - !ruby/object:Gem::Dependency
36
53
  name: activesupport
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
40
57
  requirements:
41
58
  - - ">="
42
59
  - !ruby/object:Gem::Version
60
+ hash: 11
61
+ segments:
62
+ - 2
63
+ - 0
64
+ - 2
43
65
  version: 2.0.2
44
- version:
66
+ type: :runtime
67
+ version_requirements: *id003
45
68
  - !ruby/object:Gem::Dependency
46
69
  name: morph
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
50
73
  requirements:
51
74
  - - ">="
52
75
  - !ruby/object:Gem::Version
53
- version: 0.2.4
54
- version:
55
- description: Ruby API to UK Companies House XML Gateway.
76
+ hash: 27
77
+ segments:
78
+ - 0
79
+ - 2
80
+ - 6
81
+ version: 0.2.6
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ description: |
85
+ Ruby API to UK Companies House XML Gateway.
86
+
56
87
  email:
57
88
  - rob ~@nospam@~ rubyforge.org
58
89
  executables: []
@@ -65,23 +96,29 @@ extra_rdoc_files:
65
96
  - README
66
97
  files:
67
98
  - CHANGELOG
99
+ - companies-house.yml.example
100
+ - init.rb
101
+ - lib/companies_house/company_details.haml
102
+ - lib/companies_house/exception.rb
68
103
  - lib/companies_house/name_search.haml
69
104
  - lib/companies_house/number_search.haml
70
105
  - lib/companies_house/request.haml
71
106
  - lib/companies_house/request.rb
72
107
  - lib/companies_house.rb
73
108
  - LICENSE
109
+ - Manifest
74
110
  - Rakefile
75
111
  - README
76
- - companies-house.yml.example
112
+ - README.rdoc
77
113
  - spec/lib/companies_house/request_spec.rb
78
114
  - spec/lib/companies_house_spec.rb
79
115
  - spec/spec.opts
80
116
  - spec/spec_helper.rb
81
- - Manifest
82
117
  - companies-house.gemspec
83
118
  has_rdoc: true
84
119
  homepage: ""
120
+ licenses: []
121
+
85
122
  post_install_message:
86
123
  rdoc_options:
87
124
  - --line-numbers
@@ -94,23 +131,30 @@ rdoc_options:
94
131
  require_paths:
95
132
  - lib
96
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
97
135
  requirements:
98
136
  - - ">="
99
137
  - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
100
141
  version: "0"
101
- version:
102
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
103
144
  requirements:
104
145
  - - ">="
105
146
  - !ruby/object:Gem::Version
147
+ hash: 11
148
+ segments:
149
+ - 1
150
+ - 2
106
151
  version: "1.2"
107
- version:
108
152
  requirements: []
109
153
 
110
154
  rubyforge_project: companies-house
111
- rubygems_version: 1.3.1
155
+ rubygems_version: 1.3.7
112
156
  signing_key:
113
- specification_version: 2
157
+ specification_version: 3
114
158
  summary: Ruby API to UK Companies House XML Gateway.
115
159
  test_files: []
116
160