ruby-ares 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50972475ce973dc631c0dc3ecd6f1dfac01f2e25
4
+ data.tar.gz: fc170ac8e02fc2c9275535636241efca524df9d0
5
+ SHA512:
6
+ metadata.gz: f63f5c44c5e7b5527ca65513a0c0240e2ee7ec8bc753317e7f0cb1f4e22f86f8a87441d6135123beab6419257b267d1371d13114b5c6935217855579e3f3b196
7
+ data.tar.gz: 5adb94c1f6ba5734f22e57120599dd27c8f3e4ce3288a01860c4560e910cec3b22ed2d831c803fc0286cf28471ae337004d76f4f93d7b1c9455578eef40ce505
data/README.md CHANGED
@@ -1,24 +1,46 @@
1
+ # ruby-ares
2
+
3
+ Gem for accesing business information from ARES database.
4
+
5
+ ARES is the Czech business database maintained by Ministry of Finance of the Czech Republic.
6
+ This gem helps to retrieve data provided by this database. Currently ruby-ares supports only retrieval of basic information and addresses for business contacts by IČ (Czech business contact identification number).
7
+
8
+ ## Installation and Requirements
9
+
10
+ Install the gem and require it:
11
+ ```
12
+ $ gem install ruby-ares
13
+ ```
14
+ ```ruby
15
+ require 'ruby-ares'
16
+ ```
17
+
18
+ This will need libxml2 (with header files) installed. On Fedora:
19
+
20
+ ```
21
+ su -c 'yum install libxml2-devel'
22
+ ```
23
+
1
24
  ## Usage
2
25
 
3
- subject = ARES::Subject.get ic
26
+ To get an ARES subjet/party by IČ:
27
+ ```ruby
28
+ subject = RubyARES::Subject.get(74948440)
29
+ ```
30
+ And then:
31
+ ```ruby
32
+ subject => #<RubyARES::Subject:0x007fc691a77470 @ico="74948440", @ic="74948440", @dic=nil, @name="Josef Stříbný", @company=nil, @status="A", @addresses=[#<RubyARES::Address:0x007fc691a776a0 @id="10731009", @street="Nádražní", @postcode="74727", @city="Kobeřice", @city_part="Kobeřice", @house_number="721", @house_number_type="1", @orientational_number=nil>], @updated_at="2009-08-25">
33
+ subject.name => Josef Stříbný
34
+ subject.ic => 74948440
35
+ subject.address => #<RubyARES::Address:0x007fc691a776a0 @id="10731009", @street="Nádražní", @postcode="74727", @city="Kobeřice", @city_part="Kobeřice", @house_number="721", @house_number_type="1", @orientational_number=nil>
36
+ ```
37
+
38
+ ### Exceptions
4
39
 
5
- puts subject
6
- puts subject.name
7
- puts subject.ic
8
- puts subject.address # same as puts subject.addresses[0].to_str
40
+ ruby-ares will raise either `RubyARES::Parser::ARESDatabaseError` or `RubyARES::Parser::ParseError` if the ARES database responds with an error or the XML doesn't contain the information you are looking for.
9
41
 
10
- #require './lib/ares.rb'
11
- require 'xml'
12
- require 'libxml'
13
- require 'net/http'
14
- require './lib/ares/subject.rb'
15
- require './lib/ares/address.rb'
16
- require './lib/ares/parser.rb'
17
- require './lib/ares/http.rb'
42
+ If the connection to the ARES database can't be established ruby-ares raises `RubyARES::HTTP::ConnectionError`.
18
43
 
19
- subject = ARES::Subject.get(74948440)
44
+ ## License
20
45
 
21
- puts subject.name
22
- puts subject.ic
23
- puts subject.dic
24
- puts subject.address
46
+ See LICENSE
data/Rakefile CHANGED
@@ -2,23 +2,28 @@ require 'rubygems/package_task'
2
2
  require 'rake'
3
3
  require 'rake/testtask'
4
4
 
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
6
+ require 'ruby-ares'
7
+
5
8
  gemspec = Gem::Specification.new do |s|
6
- s.name = "ruby-ares"
7
- s.version = "0.0.1"
9
+ s.name = 'ruby-ares'
10
+ s.version = RubyARES::VERSION
8
11
  s.platform = Gem::Platform::RUBY
9
- s.summary = "Gem for accesing business information from ARES database."
12
+ s.summary = 'Gem for accesing business information from ARES database.'
10
13
  s.description = <<-EOF
11
14
  ARES is the Czech business database maintained by Ministry of Finance of the Czech Republic.
12
15
  This gem helps to retrieve data provided by this database.
13
16
  EOF
14
- s.licenses = ["GPLv3"]
15
- s.author = "Josef Strzibny"
16
- s.email = "strzibny@strzibny.name"
17
- s.homepage = "http://github.com/strzibny/ares"
18
- s.required_ruby_version = ">= 1.8.7"
19
- s.required_rubygems_version = ">= 1.8.0"
20
- s.files = FileList["README.md", "Rakefile",
21
- "lib/**/*.rb", "test/**/test*.rb"]
17
+ s.licenses = ['GPLv3']
18
+ s.author = 'Josef Strzibny'
19
+ s.email = 'strzibny@strzibny.name'
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'
22
27
  end
23
28
 
24
29
  Gem::PackageTask.new gemspec do |pkg|
@@ -28,4 +33,4 @@ Rake::TestTask.new('test') do |t|
28
33
  t.libs << 'test'
29
34
  t.pattern = 'test/**/test*.rb'
30
35
  t.verbose = true
31
- end
36
+ end
@@ -5,4 +5,8 @@ require 'libxml'
5
5
  require 'net/http'
6
6
  require 'ruby-ares/subject'
7
7
  require 'ruby-ares/address'
8
- require 'ruby-ares/parser'
8
+ require 'ruby-ares/parser'
9
+
10
+ module RubyARES
11
+ VERSION = '0.0.2'
12
+ end
@@ -10,7 +10,7 @@ module RubyARES
10
10
  :house_number_type, # Typ_cislo_domovni
11
11
  :orientational_number, # Cislo_orientacni
12
12
  :postcode # PSC
13
-
13
+
14
14
  def initialize(id, street, postcode, city, city_part,
15
15
  house_number, house_number_type, orientational_number)
16
16
  @id = id
@@ -22,7 +22,7 @@ module RubyARES
22
22
  @house_number_type = house_number_type
23
23
  @orientational_number = orientational_number
24
24
  end
25
-
25
+
26
26
  def to_str
27
27
  @city_part = '' if @city == @city_part
28
28
  <<EOF
@@ -31,7 +31,7 @@ module RubyARES
31
31
  #{self.city_part}
32
32
  EOF
33
33
  end
34
-
34
+
35
35
  def street_number
36
36
  unless @orientational_number
37
37
  @house_number
@@ -39,13 +39,13 @@ EOF
39
39
  "#{@orientational_number}/#{@house_number}"
40
40
  end
41
41
  end
42
-
42
+
43
43
  def street_line
44
44
  "#{@street} #{street_number}"
45
45
  end
46
-
46
+
47
47
  def city_line
48
48
  "#{@postcode} #{@city}"
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -4,9 +4,9 @@ require 'net/http'
4
4
 
5
5
  module RubyARES
6
6
  class HTTP
7
-
7
+
8
8
  class ConnectionError < StandardError; end
9
-
9
+
10
10
  def self.fetch_subject_xml(ic)
11
11
  # Get a subject info from ARES[http://wwwinfo.mfcr.cz/ares/]
12
12
  uri = URI('http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_rzp.cgi')
@@ -22,4 +22,4 @@ module RubyARES
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -6,18 +6,18 @@ require 'ruby-ares/subject'
6
6
 
7
7
  module RubyARES
8
8
  class Parser
9
-
9
+
10
10
  class ARESDatabaseError < StandardError; end
11
11
  class ParseError < StandardError; end
12
-
12
+
13
13
  def self.get_subject(xml)
14
14
  begin
15
15
  doc = self.parse_document xml
16
-
16
+
17
17
  # Basic info
18
18
  doc.find('//dtt:Zakladni_udaje').each do |node|
19
19
  attrs = node.children()
20
-
20
+
21
21
  # Attributes of the subject
22
22
  @status = node.find('dtt:Stav').to_a[0].content unless node.find('dtt:Stav') == 0
23
23
  @updated_at = node.find('dtt:Datum_zmeny').to_a[0].content unless node.find('dtt:Datum_zmeny').to_a.size == 0
@@ -25,26 +25,26 @@ module RubyARES
25
25
  @dic = node.find('dtt:DIC').to_a[0].content unless node.find('dtt:DIC').to_a.size == 0
26
26
  @name = node.find('dtt:Obchodni_firma').to_a[0].content unless node.find('dtt:Obchodni_firma').to_a.size == 0
27
27
  end
28
-
28
+
29
29
  # Corresponding addresses
30
- @addresses = self.find_addresses doc
30
+ @addresses = self.find_addresses doc
31
31
  rescue
32
32
  raise ParseError, "Can't parse the given document."
33
33
  end
34
-
34
+
35
35
  if doc.find('//dtt:Error').to_a.size > 0
36
36
  raise ARESDatabaseError, 'ARES returned an error.'
37
37
  end
38
-
38
+
39
39
  # Create and return subject
40
40
  return RubyARES::Subject.new(@ic, @dic, @name, @status, @addresses, @updated_at)
41
41
  end
42
-
42
+
43
43
  protected
44
-
44
+
45
45
  def self.find_addresses(doc)
46
46
  @addresses = []
47
-
47
+
48
48
  doc.find('//dtt:Adresa').each do |node|
49
49
  id = node.find('dtt:ID_adresy').to_a[0].content
50
50
  street = node.find('dtt:Nazev_ulice').to_a[0].content unless node.find('dtt:Nazev_ulice').to_a.size == 0
@@ -54,17 +54,17 @@ module RubyARES
54
54
  house_number = node.find('dtt:Cislo_domovni').to_a[0].content unless node.find('dtt:Cislo_domovni').to_a.size == 0
55
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
56
  orientational_number = node.find('dtt:Cislo_orientacni').to_a[0].content unless node.find('dtt:Cislo_orientacni').to_a.size == 0
57
-
57
+
58
58
  @addresses << RubyARES::Address.new(id, street, postcode, city, city_part,
59
59
  house_number, house_number_type, orientational_number)
60
60
  end
61
-
61
+
62
62
  return @addresses
63
63
  end
64
-
64
+
65
65
  def self.parse_document(xml)
66
66
  parser = XML::Parser.string xml
67
67
  parser.parse
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -4,7 +4,7 @@ require 'ruby-ares/parser'
4
4
  require 'ruby-ares/http'
5
5
 
6
6
  module RubyARES
7
- class Subject
7
+ class Subject
8
8
  attr_reader :ico, # ICO
9
9
  :ic, # alias for ic
10
10
  :dic, # DIC
@@ -13,12 +13,12 @@ module RubyARES
13
13
  :status, # Stav
14
14
  :addresses,
15
15
  :updated_at # Datum_zmeny
16
-
16
+
17
17
  def self.get(ic)
18
18
  xml = RubyARES::HTTP.fetch_subject_xml ic
19
19
  RubyARES::Parser.get_subject xml
20
20
  end
21
-
21
+
22
22
  def initialize(ic, dic, name, status, addresses, updated_at)
23
23
  @ic, @ico = ic, ic
24
24
  @dic = dic
@@ -27,9 +27,9 @@ module RubyARES
27
27
  @addresses = addresses
28
28
  @updated_at = updated_at
29
29
  end
30
-
30
+
31
31
  def address
32
32
  @addresses[0]
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -8,28 +8,28 @@ class RubyARESTest < Test::Unit::TestCase
8
8
  def setup
9
9
  @subject = RubyARES::Parser.get_subject RubyARESTestHelper.subject_xml
10
10
  end
11
-
12
- def test_subject_address_house_number
11
+
12
+ def test_subject_address_house_number
13
13
  assert_equal '2178 1', "#{@subject.addresses[0].house_number} #{@subject.addresses[0].house_number_type}"
14
14
  end
15
-
15
+
16
16
  def test_subject_address_street
17
17
  assert_equal 'Podvinný mlýn 6/2178', "#{@subject.addresses[0].street} #{@subject.addresses[0].street_number}"
18
18
  end
19
-
19
+
20
20
  def test_subject_address_city
21
21
  assert_equal 'Praha Libeň', "#{@subject.addresses[0].city} #{@subject.addresses[0].city_part}"
22
- end
23
-
22
+ end
23
+
24
24
  def test_subject_address_postcode
25
25
  assert_equal '19000', @subject.addresses[0].postcode
26
- end
27
-
28
- def test_subject_name
26
+ end
27
+
28
+ def test_subject_name
29
29
  assert_equal 'Asseco Central Europe, a.s.', @subject.name
30
- end
31
-
32
- def test_number_of_subject_addresses
33
- assert_equal 1, @subject.addresses.size
34
- end
35
- end
30
+ end
31
+
32
+ def test_number_of_subject_addresses
33
+ assert_equal 1, @subject.addresses.size
34
+ end
35
+ end
@@ -4,20 +4,20 @@ require 'test/unit'
4
4
  require 'ruby-ares/address'
5
5
 
6
6
  class RubyARESAddressTest < Test::Unit::TestCase
7
-
7
+
8
8
  def setup
9
9
  @address = RubyARES::Address.new(1, 'Kunzova', '10010', 'Brno', 'Královo pole', 1, 1, nil)
10
10
  end
11
-
12
- def test_address_to_string
11
+
12
+ def test_address_to_string
13
13
  assert_equal "Kunzova 1\n10010 Brno\nKrálovo pole\n", @address.to_str
14
14
  end
15
-
15
+
16
16
  def test_address_street_line
17
17
  assert_equal "Kunzova 1", @address.street_line
18
18
  end
19
-
19
+
20
20
  def test_address_city_line
21
21
  assert_equal "10010 Brno", @address.city_line
22
22
  end
23
- end
23
+ end
@@ -5,4 +5,4 @@ require 'ruby-ares/http'
5
5
 
6
6
  class RubyARESHTTPTest < Test::Unit::TestCase
7
7
 
8
- end
8
+ end
@@ -5,10 +5,10 @@ require 'helper'
5
5
  require 'ruby-ares/parser'
6
6
 
7
7
  class RubyARESParserTest < Test::Unit::TestCase
8
-
9
- def test_parser_should_fail
10
- assert_raise(RubyARES::Parser::ARESDatabaseError) {
11
- RubyARES::Parser.get_subject(RubyARESTestHelper.error_responce_xml)
12
- }
13
- end
14
- end
8
+
9
+ def test_parser_should_fail
10
+ assert_raise(RubyARES::Parser::ARESDatabaseError) {
11
+ RubyARES::Parser.get_subject(RubyARESTestHelper.error_responce_xml)
12
+ }
13
+ end
14
+ end
@@ -5,4 +5,4 @@ require 'ruby-ares/subject'
5
5
 
6
6
  class RubyARESSubjectTest < Test::Unit::TestCase
7
7
 
8
- end
8
+ end
metadata CHANGED
@@ -1,19 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Josef Strzibny
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-02 00:00:00.000000000Z
13
- dependencies: []
14
- description: ! " ARES is the Czech business database maintained
15
- by Ministry of Finance of the Czech Republic.\n This gem helps
16
- to retrieve data provided by this database.\n"
11
+ date: 2014-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libxml-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |2
28
+ ARES is the Czech business database maintained by Ministry of Finance of the Czech Republic.
29
+ This gem helps to retrieve data provided by this database.
17
30
  email: strzibny@strzibny.name
18
31
  executables: []
19
32
  extensions: []
@@ -31,29 +44,29 @@ files:
31
44
  - test/test_ares_http.rb
32
45
  - test/test_ares_parser.rb
33
46
  - test/test_ares_subject.rb
34
- homepage: http://github.com/strzibny/ares
47
+ homepage: http://github.com/strzibny/ruby-ares
35
48
  licenses:
36
49
  - GPLv3
50
+ metadata: {}
37
51
  post_install_message:
38
52
  rdoc_options: []
39
53
  require_paths:
40
54
  - lib
41
55
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
56
  requirements:
44
- - - ! '>='
57
+ - - '>='
45
58
  - !ruby/object:Gem::Version
46
59
  version: 1.8.7
47
60
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
61
  requirements:
50
- - - ! '>='
62
+ - - '>='
51
63
  - !ruby/object:Gem::Version
52
64
  version: 1.8.0
53
- requirements: []
65
+ requirements:
66
+ - libxml2
54
67
  rubyforge_project:
55
- rubygems_version: 1.8.6
68
+ rubygems_version: 2.1.11
56
69
  signing_key:
57
- specification_version: 3
70
+ specification_version: 4
58
71
  summary: Gem for accesing business information from ARES database.
59
72
  test_files: []