Skip to content

Commit b01769d

Browse files
author
Jindrich Skupa
committed
change ARES to DARV BAS for VAT number, status, legal form and added some tests
1 parent a1017ce commit b01769d

File tree

8 files changed

+304
-300
lines changed

8 files changed

+304
-300
lines changed

Rakefile

+1-20
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,7 @@ require 'rake/testtask'
55
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
66
require 'ruby-ares'
77

8-
gemspec = Gem::Specification.new do |s|
9-
s.name = 'ruby-ares'
10-
s.version = RubyARES::VERSION
11-
s.platform = Gem::Platform::RUBY
12-
s.summary = 'Gem for accesing business information from ARES database.'
13-
s.description = <<-EOF
14-
ARES is the Czech business database maintained by Ministry of Finance of the Czech Republic.
15-
This gem helps to retrieve data provided by this database.
16-
EOF
17-
s.licenses = ['GPLv3']
18-
s.author = 'Josef Strzibny'
19-
s.email = '[email protected]'
20-
s.homepage = 'http://github.com/strzibny/ruby-ares'
21-
s.required_ruby_version = '>= 1.8.7'
22-
s.required_rubygems_version = '>= 1.8.0'
23-
s.files = FileList['README.md', 'Rakefile',
24-
'lib/**/*.rb', 'test/**/test*.rb']
25-
s.add_runtime_dependency 'libxml-ruby'
26-
s.requirements << 'libxml2'
27-
end
8+
gemspec = eval(File.open(File.join(File.dirname(__FILE__),'ruby-ares.gemspec')).read)
289

2910
Gem::PackageTask.new gemspec do |pkg|
3011
end

lib/ruby-ares/address.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ def initialize(id, street, postcode, city, city_part,
2424
end
2525

2626
def to_str
27-
@city_part = '' if @city == @city_part
2827
<<EOF
29-
#{self.street} #{self.street_number}
28+
#{self.street.nil? ? self.city_part : self.street} #{self.street_number}
3029
#{self.postcode} #{self.city}
31-
#{self.city_part}
30+
#{self.city_part == self.city ? "" : self.city_part}
3231
EOF
3332
end
3433

lib/ruby-ares/http.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class ConnectionError < StandardError; end
99

1010
def self.fetch_subject_xml(ic)
1111
# Get a subject info from ARES[http://wwwinfo.mfcr.cz/ares/]
12-
uri = URI('http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_rzp.cgi')
13-
params = { :ico => ic, :ver => '1.0.4' }
12+
uri = URI('http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi')
13+
params = { :ico => ic, :version => '1.0.3' }
1414
uri.query = URI.encode_www_form(params)
1515

1616
begin

lib/ruby-ares/parser.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def self.get_subject(xml)
1515
doc = self.parse_document xml
1616

1717
# Basic info
18-
doc.find('//dtt:Zakladni_udaje').each do |node|
18+
doc.find('//D:VBAS').each do |node|
1919
attrs = node.children()
2020

2121
# Attributes of the subject
22-
@status = node.find('dtt:Stav').to_a[0].content unless node.find('dtt:Stav') == 0
23-
@updated_at = node.find('dtt:Datum_zmeny').to_a[0].content unless node.find('dtt:Datum_zmeny').to_a.size == 0
24-
@ic = node.find('dtt:ICO').to_a[0].content
25-
@dic = node.find('dtt:DIC').to_a[0].content unless node.find('dtt:DIC').to_a.size == 0
26-
@name = node.find('dtt:Obchodni_firma').to_a[0].content unless node.find('dtt:Obchodni_firma').to_a.size == 0
22+
@status = node.find("D:ROR/D:SOR/D:SSU").to_a[0].content unless node.find('D:ROR/D:SOR/D:SSU').to_a.size == 0
23+
@ic = node.find('D:ICO').to_a[0].content unless node.find('D:ICO').to_a.size == 0
24+
@dic = node.find('D:DIC').to_a[0].content unless node.find('D:DIC').to_a.size == 0
25+
@name = node.find('D:OF').to_a[0].content unless node.find('D:OF').to_a.size == 0
26+
@legal_form = node.find('D:PF/D:NPF').to_a[0].content unless node.find('D:PF/D:NPF').to_a.size == 0
2727
end
2828

2929
# Corresponding addresses
@@ -32,28 +32,28 @@ def self.get_subject(xml)
3232
raise ParseError, "Can't parse the given document."
3333
end
3434

35-
if doc.find('//dtt:Error').to_a.size > 0
35+
if doc.find('//D:E').to_a.size > 0
3636
raise ARESDatabaseError, 'ARES returned an error.'
3737
end
3838

3939
# Create and return subject
40-
return RubyARES::Subject.new(@ic, @dic, @name, @status, @addresses, @updated_at)
40+
return RubyARES::Subject.new(@ic, @dic, @name, @status, @addresses, @updated_at, @legal_form)
4141
end
4242

4343
protected
4444

4545
def self.find_addresses(doc)
4646
@addresses = []
4747

48-
doc.find('//dtt:Adresa').each do |node|
49-
id = node.find('dtt:ID_adresy').to_a[0].content
50-
street = node.find('dtt:Nazev_ulice').to_a[0].content unless node.find('dtt:Nazev_ulice').to_a.size == 0
51-
postcode = node.find('dtt:PSC').to_a[0].content unless node.find('dtt:PSC').to_a.size == 0
52-
city = node.find('dtt:Nazev_obce').to_a[0].content unless node.find('dtt:Nazev_obce').to_a.size == 0
53-
city_part = node.find('dtt:Nazev_casti_obce').to_a[0].content unless node.find('dtt:Nazev_casti_obce').to_a.size == 0
54-
house_number = node.find('dtt:Cislo_domovni').to_a[0].content unless node.find('dtt:Cislo_domovni').to_a.size == 0
55-
house_number_type = node.find('dtt:Typ_cislo_domovni').to_a[0].content unless node.find('dtt:Typ_cislo_domovni').to_a.size == 0
56-
orientational_number = node.find('dtt:Cislo_orientacni').to_a[0].content unless node.find('dtt:Cislo_orientacni').to_a.size == 0
48+
doc.find('//D:AA').each do |node|
49+
id = node.find('D:IDA').to_a[0].content
50+
street = node.find('D:NU').to_a[0].content unless node.find('D:NU').to_a.size == 0
51+
postcode = node.find('D:PSC').to_a[0].content unless node.find('D:PSC').to_a.size == 0
52+
city = node.find('D:N').to_a[0].content unless node.find('D:N').to_a.size == 0
53+
city_part = node.find('D:NCO').to_a[0].content unless node.find('D:NCO').to_a.size == 0
54+
house_number = node.find('D:CD').to_a[0].content unless node.find('D:CD').to_a.size == 0
55+
house_number_type = node.find('D:TCD').to_a[0].content unless node.find('D:TCD').to_a.size == 0
56+
orientational_number = node.find('D:CO').to_a[0].content unless node.find('D:CO').to_a.size == 0
5757

5858
@addresses << RubyARES::Address.new(id, street, postcode, city, city_part,
5959
house_number, house_number_type, orientational_number)

lib/ruby-ares/subject.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Subject
1010
:dic, # DIC
1111
:name, # Obchodni_firma
1212
:company, # alias for name
13+
:legal_form,# Pravni forma
1314
:status, # Stav
1415
:addresses,
1516
:updated_at # Datum_zmeny
@@ -19,13 +20,14 @@ def self.get(ic)
1920
RubyARES::Parser.get_subject xml
2021
end
2122

22-
def initialize(ic, dic, name, status, addresses, updated_at)
23+
def initialize(ic, dic, name, status, addresses, updated_at, legal_form)
2324
@ic, @ico = ic, ic
2425
@dic = dic
2526
@name, @company = name
2627
@status = status
2728
@addresses = addresses
2829
@updated_at = updated_at
30+
@legal_form = legal_form
2931
end
3032

3133
def address

ruby-ares.gemspec

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'rubygems/package_task'
2+
require 'rake'
3+
require 'rake/testtask'
4+
5+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
6+
require 'ruby-ares'
7+
8+
gemspec = Gem::Specification.new do |s|
9+
s.name = 'ruby-ares'
10+
s.version = RubyARES::VERSION
11+
s.platform = Gem::Platform::RUBY
12+
s.summary = 'Gem for accesing business information from ARES database.'
13+
s.description = <<-EOF
14+
ARES is the Czech business database maintained by Ministry of Finance of the Czech Republic.
15+
This gem helps to retrieve data provided by this database.
16+
EOF
17+
s.licenses = ['GPLv3']
18+
s.author = 'Josef Strzibny'
19+
s.email = '[email protected]'
20+
s.homepage = 'http://github.com/strzibny/ruby-ares'
21+
s.required_ruby_version = '>= 1.8.7'
22+
s.required_rubygems_version = '>= 1.8.0'
23+
s.files = FileList['README.md', 'Rakefile',
24+
'lib/**/*.rb', 'test/**/test*.rb']
25+
s.add_runtime_dependency 'libxml-ruby'
26+
s.requirements << 'libxml2'
27+
end

0 commit comments

Comments
 (0)