companies-house 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.0.3. can now set same_as, continuation_key, regression_key on name search request
2
+
1
3
  v0.0.2. better responses when errors occur
2
4
 
3
5
  v0.0.1. initial release
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  m.rubyforge_name = "companies-house"
11
11
  m.rdoc_options << '--inline-source'
12
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"]
13
+ m.dependencies = ["hpricot >=0.6", "haml >=2.0.9", "activesupport >=2.0.2", "morph >=0.2.6", "unicode >=0.4.0"]
14
14
  # m.executable_pattern = 'bin/companies_house'
15
15
  end
16
16
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{companies-house}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
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-09-01}
9
+ s.date = %q{2010-10-20}
10
10
  s.description = %q{Ruby API to UK Companies House XML Gateway.
11
11
  }
12
12
  s.email = ["rob ~@nospam@~ rubyforge.org"]
@@ -28,16 +28,19 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency(%q<haml>, [">= 2.0.9"])
29
29
  s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
30
30
  s.add_runtime_dependency(%q<morph>, [">= 0.2.6"])
31
+ s.add_runtime_dependency(%q<unicode>, [">= 0.4.0"])
31
32
  else
32
33
  s.add_dependency(%q<hpricot>, [">= 0.6"])
33
34
  s.add_dependency(%q<haml>, [">= 2.0.9"])
34
35
  s.add_dependency(%q<activesupport>, [">= 2.0.2"])
35
36
  s.add_dependency(%q<morph>, [">= 0.2.6"])
37
+ s.add_dependency(%q<unicode>, [">= 0.4.0"])
36
38
  end
37
39
  else
38
40
  s.add_dependency(%q<hpricot>, [">= 0.6"])
39
41
  s.add_dependency(%q<haml>, [">= 2.0.9"])
40
42
  s.add_dependency(%q<activesupport>, [">= 2.0.2"])
41
43
  s.add_dependency(%q<morph>, [">= 0.2.6"])
44
+ s.add_dependency(%q<unicode>, [">= 0.4.0"])
42
45
  end
43
46
  end
@@ -11,8 +11,10 @@ require 'haml'
11
11
  require File.dirname(__FILE__) + '/companies_house/request'
12
12
  require File.dirname(__FILE__) + '/companies_house/exception'
13
13
 
14
+ $KCODE = 'UTF8' unless RUBY_VERSION >= "1.9"
15
+
14
16
  module CompaniesHouse
15
- VERSION = "0.0.2" unless defined? CompaniesHouse::VERSION
17
+ VERSION = "0.0.3" unless defined? CompaniesHouse::VERSION
16
18
 
17
19
  class << self
18
20
 
@@ -62,6 +64,7 @@ module CompaniesHouse
62
64
  end
63
65
 
64
66
  def create_transaction_id_and_digest
67
+ # transaction_id = (Time.now + 2.minutes - 17.seconds).to_i
65
68
  transaction_id = Time.now.to_i
66
69
  digest = Digest::MD5.hexdigest("#{sender_id}#{password}#{transaction_id}")
67
70
  return transaction_id, digest
@@ -107,6 +110,8 @@ module CompaniesHouse
107
110
  raise CompaniesHouse::Exception.new(e.class.name + ' ' + e.to_s)
108
111
  rescue SocketError => e
109
112
  raise CompaniesHouse::Exception.new(e.class.name + ' ' + e.to_s)
113
+ rescue Timeout::Error => e
114
+ raise CompaniesHouse::Exception.new(e.class.name + ' ' + e.to_s)
110
115
  end
111
116
  end
112
117
 
@@ -2,4 +2,10 @@
2
2
  %NameSearchRequest{ :request_ns=>'' }
3
3
  %CompanyName= company_name
4
4
  %DataSet= data_set
5
+ - if same_as && same_as[/true/i]
6
+ %SameAs< true
5
7
  %SearchRows= search_rows
8
+ - if continuation_key
9
+ %ContinuationKey= continuation_key
10
+ - if regression_key
11
+ %RegressionKey= regression_key
@@ -19,6 +19,9 @@ module CompaniesHouse
19
19
  def default options
20
20
  options[:search_rows] = 20 unless options.has_key?(:search_rows)
21
21
  options[:data_set] = 'LIVE' unless options.has_key?(:data_set)
22
+ options[:same_as] = nil unless options.has_key?(:same_as)
23
+ options[:continuation_key] = nil unless options.has_key?(:continuation_key)
24
+ options[:regression_key] = nil unless options.has_key?(:regression_key)
22
25
  options
23
26
  end
24
27
 
@@ -29,7 +32,7 @@ module CompaniesHouse
29
32
  :digest_method => CompaniesHouse.digest_method,
30
33
  :sender_id => CompaniesHouse.sender_id,
31
34
  :password => CompaniesHouse.password,
32
- :email => CompaniesHouse.email,
35
+ :email => '',
33
36
  :transaction_id => transaction_id }.merge(options)
34
37
 
35
38
  render_request options[:request_type], template, params
@@ -2,11 +2,68 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  describe CompaniesHouse::Request do
4
4
 
5
+ before do
6
+ @transaction_id = 123
7
+ @digest = '????'
8
+ @sender_id = 'XMLGatewayTestUserID'
9
+ @email = 'x@y'
10
+ CompaniesHouse.sender_id = @sender_id
11
+ CompaniesHouse.email = @email
12
+ CompaniesHouse.stub!(:create_transaction_id_and_digest).and_return [@transaction_id, @digest]
13
+
14
+ @name_search_type = 'NameSearch'
15
+ @company_name = 'millennium stadium plc'
16
+ @name_search_xml = expected_xml @name_search_type, %Q|<NameSearchRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/NameSearch.xsd">
17
+ <CompanyName>millennium stadium plc</CompanyName>
18
+ <DataSet>LIVE</DataSet>
19
+ <SearchRows>20</SearchRows>
20
+ </NameSearchRequest>|
21
+
22
+ @number_search_type = 'NumberSearch'
23
+ @company_number = '03176906'
24
+ @number_search_xml = expected_xml @number_search_type, %Q|<NumberSearchRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/NumberSearch.xsd">
25
+ <PartialCompanyNumber>#{@company_number}</PartialCompanyNumber>
26
+ <DataSet>LIVE</DataSet>
27
+ <SearchRows>20</SearchRows>
28
+ </NumberSearchRequest>|
29
+
30
+ @company_details_type = 'CompanyDetails'
31
+ @company_details_xml = expected_xml @company_details_type, %Q|<CompanyDetailsRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/CompanyDetails.xsd">
32
+ <CompanyNumber>#{@company_number}</CompanyNumber>
33
+ <GiveMortTotals>1</GiveMortTotals>
34
+ </CompanyDetailsRequest>|
35
+ end
36
+
5
37
  describe "when asked for name search request xml" do
6
38
  it 'should create xml correctly' do
7
39
  request_xml = CompaniesHouse::Request.name_search_xml :company_name => @company_name
8
40
  request_xml.strip.should == @name_search_xml.strip
9
41
  end
42
+
43
+ describe "and same_as flag is set to true" do
44
+ it 'should create xml correctly' do
45
+ request_xml = CompaniesHouse::Request.name_search_xml :company_name => @company_name, :same_as => 'true'
46
+ request_xml.strip.should == @name_search_xml.gsub(' <DataSet>LIVE</DataSet>'," <DataSet>LIVE</DataSet>\n <SameAs>true</SameAs>").strip
47
+ end
48
+ end
49
+ describe "and same_as flag is set to false" do
50
+ it 'should create xml correctly' do
51
+ request_xml = CompaniesHouse::Request.name_search_xml :company_name => @company_name, :same_as => 'false'
52
+ request_xml.strip.should == @name_search_xml.strip
53
+ end
54
+ end
55
+ describe "and continuation_key is set" do
56
+ it 'should create xml correctly' do
57
+ request_xml = CompaniesHouse::Request.name_search_xml :company_name => @company_name, :continuation_key => '1234'
58
+ request_xml.strip.should == @name_search_xml.gsub(' <SearchRows>20</SearchRows>'," <SearchRows>20</SearchRows>\n <ContinuationKey>1234</ContinuationKey>").strip
59
+ end
60
+ end
61
+ describe "and regression_key is set" do
62
+ it 'should create xml correctly' do
63
+ request_xml = CompaniesHouse::Request.name_search_xml :company_name => @company_name, :regression_key => '4321'
64
+ request_xml.strip.should == @name_search_xml.gsub(' <SearchRows>20</SearchRows>'," <SearchRows>20</SearchRows>\n <RegressionKey>4321</RegressionKey>").strip
65
+ end
66
+ end
10
67
  end
11
68
 
12
69
  describe "when asked for number search request xml" do
@@ -18,6 +75,8 @@ describe CompaniesHouse::Request do
18
75
 
19
76
  describe "when asked for company details request xml" do
20
77
  it 'should create xml correctly' do
78
+ CompaniesHouse.email = ''
79
+ CompaniesHouse.email.should == ''
21
80
  request_xml = CompaniesHouse::Request.company_details_xml :company_number => @company_number
22
81
  request_xml.strip.should == @company_details_xml.strip
23
82
  end
@@ -41,7 +100,7 @@ describe CompaniesHouse::Request do
41
100
  <Value>#{@digest}</Value>
42
101
  </Authentication>
43
102
  </IDAuthentication>
44
- <EmailAddress>#{@email}</EmailAddress>
103
+ <EmailAddress>#{}</EmailAddress>
45
104
  </SenderDetails>
46
105
  </Header>
47
106
  <GovTalkDetails>
@@ -53,36 +112,4 @@ describe CompaniesHouse::Request do
53
112
  </GovTalkMessage>|
54
113
  end
55
114
 
56
- before do
57
- @transaction_id = 123
58
- @digest = '????'
59
- @sender_id = 'XMLGatewayTestUserID'
60
- @email = 'x@y'
61
- CompaniesHouse.sender_id = @sender_id
62
- CompaniesHouse.email = @email
63
- CompaniesHouse.stub!(:create_transaction_id_and_digest).and_return [@transaction_id, @digest]
64
-
65
- @name_search_type = 'NameSearch'
66
- @company_name = 'millennium stadium plc'
67
- @name_search_xml = expected_xml @name_search_type, %Q|<NameSearchRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/NameSearch.xsd">
68
- <CompanyName>millennium stadium plc</CompanyName>
69
- <DataSet>LIVE</DataSet>
70
- <SearchRows>20</SearchRows>
71
- </NameSearchRequest>|
72
-
73
- @number_search_type = 'NumberSearch'
74
- @company_number = '03176906'
75
- @number_search_xml = expected_xml @number_search_type, %Q|<NumberSearchRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/NumberSearch.xsd">
76
- <PartialCompanyNumber>#{@company_number}</PartialCompanyNumber>
77
- <DataSet>LIVE</DataSet>
78
- <SearchRows>20</SearchRows>
79
- </NumberSearchRequest>|
80
-
81
- @company_details_type = 'CompanyDetails'
82
- @company_details_xml = expected_xml @company_details_type, %Q|<CompanyDetailsRequest xmlns="http://xmlgw.companieshouse.gov.uk/v1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/CompanyDetails.xsd">
83
- <CompanyNumber>#{@company_number}</CompanyNumber>
84
- <GiveMortTotals>1</GiveMortTotals>
85
- </CompanyDetailsRequest>|
86
- end
87
-
88
115
  end
@@ -2,67 +2,79 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
3
  describe CompaniesHouse do
4
4
 
5
- before do
6
- @sender_id = 'user'
7
- @password = '???'
8
- @email = 'email'
5
+ describe 'when objectifying xml' do
6
+ describe 'and xml contains expanded unicode' do
7
+ it 'should convert to utf8' do
8
+ xml = '<Body><company_details><company_name>£IBRA FINANCIAL SERVICES LIMITED</company_name></company_details></Body>'
9
+ object = CompaniesHouse.objectify xml
10
+ object.company_name.should == "£IBRA FINANCIAL SERVICES LIMITED"
11
+ end
12
+ end
13
+ end
9
14
 
10
- CompaniesHouse.sender_id = @sender_id
11
- CompaniesHouse.password = @password
12
- CompaniesHouse.email = @email
15
+ describe 'when calling public methods' do
16
+ before do
17
+ @sender_id = 'user'
18
+ @password = '???'
19
+ @email = 'email'
13
20
 
14
- @company_name = 'millennium stadium plc'
15
- @company_number = '03176906'
16
- @request_xml = '<request/>'
17
- @response_xml = '<response/>'
21
+ CompaniesHouse.sender_id = @sender_id
22
+ CompaniesHouse.password = @password
23
+ CompaniesHouse.email = @email
18
24
 
19
- @transaction_id = 123
20
- Time.stub!(:now).and_return(mock('time', :to_i => @transaction_id))
21
- @digest = 'digest'
22
- end
25
+ @company_name = 'millennium stadium plc'
26
+ @company_number = '03176906'
27
+ @request_xml = '<request/>'
28
+ @response_xml = '<response/>'
23
29
 
24
- describe "when asked for credientials" do
25
- it 'should return sender_id correctly' do
26
- CompaniesHouse.sender_id.should == @sender_id
30
+ @transaction_id = 123
31
+ Time.stub!(:now).and_return(mock('time', :to_i => @transaction_id))
32
+ @digest = 'digest'
27
33
  end
28
- it 'should return password correctly' do
29
- CompaniesHouse.password.should == @password
30
- end
31
- it 'should return email correctly' do
32
- CompaniesHouse.email.should == @email
34
+
35
+ describe "when asked for credientials" do
36
+ it 'should return sender_id correctly' do
37
+ CompaniesHouse.sender_id.should == @sender_id
38
+ end
39
+ it 'should return password correctly' do
40
+ CompaniesHouse.password.should == @password
41
+ end
42
+ it 'should return email correctly' do
43
+ CompaniesHouse.email.should == @email
44
+ end
33
45
  end
34
- end
35
46
 
36
- describe 'when asked for a transaction id and digest' do
37
- it 'should create transaction id and digest correctly' do
38
- Digest::MD5.should_receive(:hexdigest).with("#{@sender_id}#{@password}#{@transaction_id}").and_return @digest
39
- transaction_id, digest = CompaniesHouse.create_transaction_id_and_digest
40
- transaction_id.should == @transaction_id
41
- digest.should == @digest
47
+ describe 'when asked for a transaction id and digest' do
48
+ it 'should create transaction id and digest correctly' do
49
+ Digest::MD5.should_receive(:hexdigest).with("#{@sender_id}#{@password}#{@transaction_id}").and_return @digest
50
+ transaction_id, digest = CompaniesHouse.create_transaction_id_and_digest
51
+ transaction_id.should == @transaction_id
52
+ digest.should == @digest
53
+ end
42
54
  end
43
- end
44
55
 
45
- describe "when asked for name search request" do
46
- it 'should perform request correctly' do
47
- CompaniesHouse::Request.should_receive(:name_search_xml).with(:company_name=> @company_name).and_return @request_xml
48
- CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
49
- CompaniesHouse.name_search(@company_name).should == @response_xml
56
+ describe "when asked for name search request" do
57
+ it 'should perform request correctly' do
58
+ CompaniesHouse::Request.should_receive(:name_search_xml).with(:company_name=> @company_name).and_return @request_xml
59
+ CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
60
+ CompaniesHouse.name_search(@company_name).should == @response_xml
61
+ end
50
62
  end
51
- end
52
63
 
53
- describe "when asked for number search request" do
54
- it 'should perform request correctly' do
55
- CompaniesHouse::Request.should_receive(:number_search_xml).with(:company_number=> @company_number).and_return @request_xml
56
- CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
57
- CompaniesHouse.number_search(@company_number).should == @response_xml
64
+ describe "when asked for number search request" do
65
+ it 'should perform request correctly' do
66
+ CompaniesHouse::Request.should_receive(:number_search_xml).with(:company_number=> @company_number).and_return @request_xml
67
+ CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
68
+ CompaniesHouse.number_search(@company_number).should == @response_xml
69
+ end
58
70
  end
59
- end
60
71
 
61
- describe "when asked for company details request" do
62
- it 'should perform request correctly' do
63
- CompaniesHouse::Request.should_receive(:company_details_xml).with(:company_number=> @company_number).and_return @request_xml
64
- CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
65
- CompaniesHouse.company_details(@company_number).should == @response_xml
72
+ describe "when asked for company details request" do
73
+ it 'should perform request correctly' do
74
+ CompaniesHouse::Request.should_receive(:company_details_xml).with(:company_number=> @company_number).and_return @request_xml
75
+ CompaniesHouse.should_receive(:get_response).with(@request_xml).and_return @response_xml
76
+ CompaniesHouse.company_details(@company_number).should == @response_xml
77
+ end
66
78
  end
67
79
  end
68
80
  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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
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-09-01 00:00:00 +01:00
18
+ date: 2010-10-20 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,22 @@ dependencies:
81
81
  version: 0.2.6
82
82
  type: :runtime
83
83
  version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: unicode
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 15
93
+ segments:
94
+ - 0
95
+ - 4
96
+ - 0
97
+ version: 0.4.0
98
+ type: :runtime
99
+ version_requirements: *id005
84
100
  description: |
85
101
  Ruby API to UK Companies House XML Gateway.
86
102