companies-house 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/companies-house.gemspec +2 -2
- data/lib/companies_house.rb +3 -4
- data/lib/companies_house/request.rb +1 -1
- data/spec/lib/companies_house/request_spec.rb +20 -0
- data/spec/lib/companies_house_spec.rb +8 -1
- metadata +4 -4
data/CHANGELOG
CHANGED
data/companies-house.gemspec
CHANGED
@@ -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
|
5
|
+
s.version = "0.1.0"
|
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{2011-
|
9
|
+
s.date = %q{2011-04-11}
|
10
10
|
s.description = %q{Ruby API to UK Companies House XML Gateway.
|
11
11
|
}
|
12
12
|
s.email = ["rob ~@nospam@~ rubyforge.org"]
|
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.1.0" unless defined? CompaniesHouse::VERSION
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
@@ -63,10 +63,9 @@ module CompaniesHouse
|
|
63
63
|
'CHMD5'
|
64
64
|
end
|
65
65
|
|
66
|
-
def create_transaction_id_and_digest
|
67
|
-
# transaction_id = (Time.now + 2.minutes - 17.seconds).to_i
|
66
|
+
def create_transaction_id_and_digest(options={})
|
68
67
|
transaction_id = (Time.now.to_f * 100).to_i
|
69
|
-
digest = Digest::MD5.hexdigest("#{sender_id}#{password}#{transaction_id}")
|
68
|
+
digest = Digest::MD5.hexdigest("#{options[:sender_id] || sender_id}#{options[:password] || password}#{transaction_id}")
|
70
69
|
return transaction_id, digest
|
71
70
|
end
|
72
71
|
|
@@ -27,7 +27,7 @@ module CompaniesHouse
|
|
27
27
|
|
28
28
|
def create options={}
|
29
29
|
template = options.delete(:template)
|
30
|
-
transaction_id, digest = CompaniesHouse.create_transaction_id_and_digest
|
30
|
+
transaction_id, digest = CompaniesHouse.create_transaction_id_and_digest(options)
|
31
31
|
params = {:digest => digest,
|
32
32
|
:digest_method => CompaniesHouse.digest_method,
|
33
33
|
:sender_id => CompaniesHouse.sender_id,
|
@@ -64,6 +64,12 @@ describe CompaniesHouse::Request do
|
|
64
64
|
request_xml.strip.should == @name_search_xml.gsub(' <SearchRows>20</SearchRows>'," <SearchRows>20</SearchRows>\n <RegressionKey>4321</RegressionKey>").strip
|
65
65
|
end
|
66
66
|
end
|
67
|
+
describe "and sender_id and password given in options" do
|
68
|
+
it "should use given sender_id and password when creating transaction_id and digest" do
|
69
|
+
CompaniesHouse.should_receive(:create_transaction_id_and_digest).with(hash_including(:sender_id => 'foo123', :password => 'bar456'))
|
70
|
+
CompaniesHouse::Request.name_search_xml(:company_name => @company_name, :sender_id => 'foo123', :password => 'bar456')
|
71
|
+
end
|
72
|
+
end
|
67
73
|
end
|
68
74
|
|
69
75
|
describe "when asked for number search request xml" do
|
@@ -71,6 +77,13 @@ describe CompaniesHouse::Request do
|
|
71
77
|
request_xml = CompaniesHouse::Request.number_search_xml :company_number => @company_number
|
72
78
|
request_xml.strip.should == @number_search_xml.strip
|
73
79
|
end
|
80
|
+
|
81
|
+
describe "and sender_id and password given in options" do
|
82
|
+
it "should use given sender_id and password when creating transaction_id and digest" do
|
83
|
+
CompaniesHouse.should_receive(:create_transaction_id_and_digest).with(hash_including(:sender_id => 'foo123', :password => 'bar456'))
|
84
|
+
CompaniesHouse::Request.number_search_xml(:company_number => @company_number, :sender_id => 'foo123', :password => 'bar456')
|
85
|
+
end
|
86
|
+
end
|
74
87
|
end
|
75
88
|
|
76
89
|
describe "when asked for company details request xml" do
|
@@ -80,6 +93,13 @@ describe CompaniesHouse::Request do
|
|
80
93
|
request_xml = CompaniesHouse::Request.company_details_xml :company_number => @company_number
|
81
94
|
request_xml.strip.should == @company_details_xml.strip
|
82
95
|
end
|
96
|
+
|
97
|
+
describe "and sender_id and password given in options" do
|
98
|
+
it "should use given sender_id and password when creating transaction_id and digest" do
|
99
|
+
CompaniesHouse.should_receive(:create_transaction_id_and_digest).with(hash_including(:sender_id => 'foo123', :password => 'bar456'))
|
100
|
+
CompaniesHouse::Request.company_details_xml(:company_number => @company_number, :sender_id => 'foo123', :password => 'bar456')
|
101
|
+
end
|
102
|
+
end
|
83
103
|
end
|
84
104
|
|
85
105
|
def expected_xml request_type, body
|
@@ -137,8 +137,15 @@ describe CompaniesHouse do
|
|
137
137
|
transaction_id.should == @transaction_id
|
138
138
|
digest.should == @digest
|
139
139
|
end
|
140
|
+
|
141
|
+
describe "and password and sender_id passed as options" do
|
142
|
+
it "should use in preference to class ones" do
|
143
|
+
Digest::MD5.should_receive(:hexdigest).with("foo1234bar4567#{@transaction_id}")# @digest
|
144
|
+
CompaniesHouse.create_transaction_id_and_digest(:sender_id => 'foo1234', :password => 'bar4567')
|
145
|
+
end
|
146
|
+
end
|
140
147
|
end
|
141
|
-
|
148
|
+
|
142
149
|
describe "when asked for name search request" do
|
143
150
|
it 'should perform request correctly' do
|
144
151
|
CompaniesHouse::Request.should_receive(:name_search_xml).with(:company_name=> @company_name).and_return @request_xml
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.9
|
10
|
+
version: 0.1.0
|
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: 2011-
|
18
|
+
date: 2011-04-11 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|