ares.rb 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc12e73b00e926a9fe1aca8470f37035d7b0bad9
4
+ data.tar.gz: 57a22b7e8d142fe1cbc7bdd5491b67a168760c58
5
+ SHA512:
6
+ metadata.gz: 62ae8f22d35b9df1de3fbe5832f62980760d184fc00101ce1fcb54742c7512405aa7b5127bf85d00b1dc4e034bea5819d05a7d3af3d3c1023b1db653bee45e1b
7
+ data.tar.gz: 5ff88e73f91c694e86dbe63eee9267c3d5aaa5ce48e472dc3e036324d0e9fb98b47611fe96f3501155a8f134c22486dbe40102fb61994a049dee19e3fa942997
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ares
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ - 2.0.0
5
+ - 1.9.3
6
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ares.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Ares
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cnb.png)](http://badge.fury.io/rb/cnb)
4
+ [![Build Status](https://travis-ci.org/ucetnictvi-on-line/ares.rb.png?branch=master)](https://travis-ci.org/ucetnictvi-on-line/ares.rb)
5
+ [![Code Climate](https://codeclimate.com/github/ucetnictvi-on-line/ares.rb/badges/gpa.svg)](https://codeclimate.com/github/ucetnictvi-on-line/ares.rb)
6
+ [![Test Coverage](https://codeclimate.com/github/ucetnictvi-on-line/ares.rb/badges/coverage.svg)](https://codeclimate.com/github/ucetnictvi-on-line/ares.rb/coverage)
7
+
8
+ Load information about employers from Czech ARES service.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ares'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ares
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ record = Ares.standard(ico: '27169278')
30
+ record.business_name # => "Účetnictví on-line, s.r.o."
31
+ record.address.to_s # => "Pekařská 14/628, 15500 Praha-Jinonice, okres: Hlavní město Praha"
32
+ record.address.street # => "Pekařská"
33
+ record.address.sequence_number # => "14"
34
+ record.address.building_number # => "628"
35
+ record.address.postcode # => "15500"
36
+ record.address.town # => "Praha"
37
+ record.address.residential_area # => "Jinonice"
38
+ record.address.district # => "Hlavní město Praha"
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/ares/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,16 @@
1
+ # Validation
2
+
3
+ * Parameter validation (correct ico)
4
+
5
+ # Batch query
6
+
7
+ * Query multiple entities in one call
8
+ * Use post method: [http://wwwinfo.mfcr.cz/ares/ares_xml.html.cz]
9
+
10
+ # Changes
11
+
12
+ * [http://wwwinfo.mfcr.cz/ares/ares_xml_zm.html.cz]
13
+
14
+ # Basic
15
+
16
+ * [http://wwwinfo.mfcr.cz/ares/ares_xml_basic.html.cz]
data/ares.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ares/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ares.rb'
8
+ spec.version = Ares::VERSION
9
+ spec.authors = ['Ondřej Svoboda','Bohuslav Blin']
10
+ spec.email = ['blin@uol.cz']
11
+
12
+ spec.summary = 'ARES library'
13
+ spec.description = 'Gem for accesing business information from ARES database.'
14
+ spec.homepage = "http://www.uol.cz"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.7'
20
+ spec.add_development_dependency 'rake', '~> 10.0'
21
+ spec.add_development_dependency 'rspec'
22
+ spec.add_development_dependency 'webmock'
23
+ spec.add_development_dependency 'vcr'
24
+
25
+ spec.add_runtime_dependency 'httparty'
26
+ spec.add_runtime_dependency 'nokogiri'
27
+ end
data/lib/ares.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+ require 'ares/version'
4
+ require 'ares/errors'
5
+ require 'ares/logging'
6
+ require 'ares/client'
7
+
8
+ module Ares
9
+ class << self
10
+ include Ares::Logging
11
+
12
+ # Returns standard client
13
+ # @returns [Client::Standard]
14
+ def client
15
+ @client ||= Client.standard
16
+ end
17
+
18
+ # @see Client::Standard#call
19
+ # @return [Responses::StandardResponse::Record]
20
+ def standard(options)
21
+ response = client.call(options)
22
+ fail ArgumentError, "Arguments #{options} are invalid" if response.error?
23
+ response.record
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require 'ares/http'
2
+ require 'ares/responses'
3
+
4
+ module Ares
5
+ module Client
6
+ autoload :Standard, 'ares/client/standard'
7
+
8
+ class << self
9
+ def standard
10
+ Standard.new
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ require 'ares/responses/standard_response'
2
+
3
+ module Ares
4
+ module Client
5
+ class Standard
6
+ ENDPOINT = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi'
7
+
8
+ include Ares::Http
9
+
10
+ # Search for standard entity's identification data
11
+ #
12
+ # @param [Hash] opts Options for searching as specified in http://wwwinfo.mfcr.cz/ares/ares_xml_standard.html.en
13
+ # @option opts [String] :ico
14
+ # @option opts [String] :obchodni_firma
15
+ # @option opts [String] :nazev_obce
16
+ # @option opts [String] :kod_pf
17
+ # @option opts [String] :typ_registru
18
+ # @option opts [Integer] :xml (0) Type of xml output.
19
+ # @option opts [String] :jazyk ('cz') Text of html pages [cz, en]
20
+ # @option opts [Integer] :max_pocet (10)
21
+ # @option opts [Integer] :aktivni (0) [0, 1]
22
+ # @option opts [Integer] :adr_puv [0, 1]
23
+ # @option opts [String] :typ_vyhledani ('free') Selection priority [free, ico, of]
24
+ # @option opts [Integer] :diakritika (1) [0, 1]
25
+ # @option opts [String] :czk (iso) Encoding [iso, utf]
26
+ # @returns [Ares::Responses::StandardResponse]
27
+ def call(opts)
28
+ xml = get(ENDPOINT, opts)
29
+ document = Nokogiri::XML(xml)
30
+ Ares::Responses::StandardResponse.new(document)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ module Ares
2
+ class AresError < RuntimeError;
3
+ end
4
+ class RecordNotFound < AresError;
5
+ end
6
+ end
data/lib/ares/http.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Ares
2
+ module Http
3
+ def get(url, params = {})
4
+ response = HTTParty.get(url, query: params)
5
+ response.body
6
+ end
7
+
8
+ def post(url, params = {})
9
+ response = HTTParty.post(url, query: params)
10
+ response.body
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'logger'
2
+
3
+ module Ares
4
+ module Logging
5
+ def logger
6
+ @logger ||= Logger.new(STDOUT)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module Ares
2
+ module Responses
3
+ class TextCode
4
+ attr_reader :elem, :code, :text
5
+
6
+ def initialize(elem, code, text)
7
+ @elem = elem
8
+ @code = code
9
+ @text = text
10
+ end
11
+
12
+ def to_s
13
+ "#{@code}: #{text}"
14
+ end
15
+
16
+ def inspect
17
+ "#<TextCode(#{elem}) code=#{code} text=#{text}>"
18
+ end
19
+ end
20
+
21
+ class Error < TextCode
22
+ def error?; true end
23
+ end
24
+ end
25
+ end
26
+
27
+ require 'ares/responses/standard_response'
@@ -0,0 +1,438 @@
1
+ module Ares
2
+ module Responses
3
+ # Coresponds to <are:Ares_odpovedi> element.
4
+ class StandardResponse
5
+ include Enumerable
6
+
7
+ # @!attribute [r] xml_document
8
+ # @return [String] XML Document returned by ares
9
+ # @!attribute [r] time
10
+ # @return [String] Created at
11
+ # @!attribute [r] count
12
+ # @return [String] Element count
13
+ # @!attribute [r] type
14
+ # @return [String] 'Standard'
15
+ # @!attribute [r] output_format
16
+ # @return [String] 'XML'
17
+ # @!attribute [r] xslt
18
+ # @return [String] 'klient'
19
+ # @!attribute [r] validation_xslt
20
+ # @return [String] Path to xsl document
21
+ # @!attribute [r] id
22
+ # @return [String] ID
23
+ attr_reader :xml_document, :time, :count, :type,
24
+ :output_format, :xslt, :validation_xslt, :id
25
+
26
+ def initialize(xml_document)
27
+ @xml_document = xml_document
28
+
29
+ attributes = xml_document.root.attributes
30
+ @time = attributes['odpoved_datum_cas'].to_s
31
+ @count = attributes['odpoved_pocet'].to_s
32
+ @type = attributes['odpoved_typ'].to_s # musí být 'Standard'
33
+ @output_format = (attributes['vystup_format'] || 'XML').to_s
34
+ @xslt = (attributes['xslt'] || 'klient').to_s
35
+ @validation_xslt = attributes['validation_XSLT'].to_s
36
+ @id = attributes['Id'].to_s
37
+
38
+ @content = xml_document.root.children.map { |elem| parse_elem elem }.compact
39
+ end
40
+
41
+ # Returns response with found company
42
+ # or nil if not found.
43
+ #
44
+ # @returns [Response, NilClass] response
45
+ def response
46
+ @content.first
47
+ end
48
+
49
+ def record
50
+ response ? response.records.first : nil
51
+ end
52
+
53
+ def error?
54
+ any? { |c| c.error? }
55
+ end
56
+
57
+ def each(&block)
58
+ @content.each(&block)
59
+ end
60
+
61
+ def to_xml
62
+ @xml_document.to_xml
63
+ end
64
+
65
+ private
66
+
67
+ def parse_elem(elem)
68
+ if elem.name == 'Fault'
69
+ Ares::Responses::Error.new(
70
+ elem,
71
+ elem.at_xpath('./faultcode/text()').to_s,
72
+ elem.at_xpath('./faultstring/text()').to_s
73
+ )
74
+ elsif elem.name == 'Odpoved'
75
+ Response.new(elem)
76
+ end
77
+ end
78
+
79
+ # <are:Odpoved> element
80
+ class Response
81
+ include Enumerable
82
+
83
+ # @!attribute [r] id
84
+ # @return [Integer] id
85
+ # @!attribute [r] count
86
+ # @return [Integer] Responses count
87
+ # @!attribute [r] search_type
88
+ # @return [String] type of search:
89
+ # * FREE - searching by ico, if not found search by RC, if not found find by company's name
90
+ # * ICO, RC, OF - search by type, if not found searching ends.
91
+ # Searching type is shown in (Kod_shody_*) element.
92
+ #
93
+ # @!attribute [r] records
94
+ # @return [Record, Error] Found records
95
+ attr_reader :id, :count, :search_type, :records
96
+
97
+ # @param elem [Nokogiri::XML::Element]
98
+ def initialize(elem)
99
+ @id = @count = @search_type = nil
100
+ @records = []
101
+ elem.children.each { |child| parse_elem(child) }
102
+ end
103
+
104
+ def each(&block)
105
+ @records.each(&block)
106
+ end
107
+
108
+ def error?
109
+ @records.any? { |e| e.is_a? Responses::Error }
110
+ end
111
+
112
+ private
113
+
114
+ # @param child [Nokogiri::XML::Element] Child element
115
+ def parse_elem(child)
116
+ case child.name
117
+ when 'Pomocne_ID'
118
+ @id = child.value
119
+ when 'Pocet_zaznamu'
120
+ @count = child.content.to_i
121
+ when 'Typ_vyhledani'
122
+ @search_type = child.content
123
+ when 'Error'
124
+ @records << Ares::Responses::Error.new(
125
+ child,
126
+ child.at_xpath('./Error_kod/text()').to_s,
127
+ child.at_xpath('./Error_text/text()').to_s
128
+ )
129
+ when 'Zaznam'
130
+ @records << Record.new(child)
131
+ when 'text'
132
+ # do nothing
133
+ else
134
+ Ares.logger.warn("#{self}: Unexpected record #{child.name} at #{child.path}")
135
+ end
136
+ end
137
+ end
138
+
139
+ # <are:Zaznam> element
140
+ class Record
141
+ # @!attribute [r] match
142
+ # @return [Responses::TextCode] <are:Shoda_ICO/RC/OF> Code of matching register ('ICO', 'RC', 'OF')
143
+ # @!attribute [r] search_by
144
+ # @return [String] <are:Vyhledano_dle> Register where record was found
145
+ # @!attribute [r] register_type
146
+ # @return [String] <are:Typ_registru> Register code
147
+ # @!attribute [r] creation_date
148
+ # @return [String] <are:Datum_vzniku> Date of creation
149
+ # @!attribute [r] termination_date
150
+ # @return [String] <are:Datum_zaniku> Date of termination
151
+ # @!attribute [r] validity_date
152
+ # @return [String] <are:Datum_platnosti>
153
+ # @!attribute [r] legal_form
154
+ # @return [LegalForm] <are:Pravni_forma>
155
+ # @!attribute [r] bussiness_name
156
+ # @return [String] <are:Obchodni_firma>
157
+ # @!attribute [r] ico
158
+ # @return [String] <are:ICO>
159
+ # @!attribute [r] identification
160
+ # @return [Identification] <are:Identifikace>
161
+ # @!attribute [r] tax_office_code
162
+ # @return [String] <are:Kod_FU>
163
+ # @!attribute [r] status_flags
164
+ # @return [Flags] <are:Priznaky_subjektu>
165
+ attr_reader :match, :search_by, :register_type,
166
+ :creation_date, :termination_date, :validity_date,
167
+ :legal_form, :business_name, :ico, :identification,
168
+ :tax_office_code, :status_flags
169
+
170
+ def initialize(elem)
171
+ @match = get_match(elem)
172
+ @search_by = elem.at_xpath('./are:Vyhledano_dle').content
173
+ @register_type = TextCode.new('RegisterType',
174
+ elem.at_xpath('./are:Typ_registru/dtt:Kod').content,
175
+ elem.at_xpath('./are:Typ_registru/dtt:Text').content)
176
+ date = elem.at_xpath('./are:Datum_vzniku')
177
+ @creation_date = date ? Time.parse(date.content) : nil
178
+ date = elem.at_xpath('./are:Datum_zaniku')
179
+ @termination_date = date ? Time.parse(date.content) : nil
180
+ date = elem.at_xpath('./are:Datum_platnosti')
181
+ @validity_date = date ? Time.parse(date.content) : nil
182
+
183
+ @legal_form = LegalForm.new(elem.at_xpath('./are:Pravni_forma'))
184
+ @business_name = elem.at_xpath('./are:Obchodni_firma').content
185
+ @ico = elem.at_xpath('./are:ICO').content
186
+ id_elem = elem.at_xpath('./are:Identifikace')
187
+ @identification = id_elem ? Identification.new(id_elem) : nil
188
+ fu_code = elem.at_xpath('./are:Kod_FU')
189
+ @tax_office_code = fu_code ? fu_code.content.to_i : nil
190
+ flags = elem.at_xpath('./are:Priznaky_subjektu')
191
+ @status_flags = flags ? StatusFlags.new(flags) : nil
192
+ end
193
+
194
+ # Returns company's address or nil if not specified
195
+ #
196
+ # @returns [AresAddress, NilClass] Address
197
+ def address
198
+ return unless identification
199
+ identification.address
200
+ end
201
+
202
+ private
203
+
204
+ def get_match(elem)
205
+ name = code = text = nil
206
+ if match = elem.at_xpath('./are:Shoda_ICO')
207
+ name = 'Match ICO'
208
+ code = match.at_xpath('./dtt:Kod').content
209
+ text = match.at_xpath('./dtt:Text')
210
+ text = (text ? text.content : nil)
211
+ elsif match = elem.at_xpath('./are:Shoda_RC')
212
+ name = 'Match RC'
213
+ code = match.at_xpath('./dtt:Kod').content
214
+ text = match.at_xpath('./dtt:Text')
215
+ text = (text ? text.content : nil)
216
+ elsif match = elem.at_xpath('./are:Shoda_OF')
217
+ name = 'Match OF'
218
+ code = match.at_xpath('./dtt:Kod').content
219
+ text = match.at_xpath('./dtt:Text')
220
+ text = (text ? text.content : nil)
221
+ else
222
+ return nil
223
+ end
224
+
225
+ TextCode.new(name, code, text)
226
+ end
227
+ end
228
+
229
+ # <Pravni_forma> element
230
+ class LegalForm
231
+ # Typ ekonomického subjektu:
232
+ # F-fyzická osoba tuzemská,
233
+ # P-právnická osoba tuzemská,
234
+ # X-zahraniční právnická osoba,
235
+ # Z-zahraniční fyzická osoba,
236
+ # O-fyzická osoba s organizační složkou
237
+ # C-civilní osoba nepodnikající (v CEU)
238
+ attr_reader :code, :name, :person, :text, :person_type
239
+
240
+ def initialize(elem)
241
+ code = elem.at_xpath('./dtt:Kod_PF')
242
+ @code = code ? code.content.to_i : nil
243
+ name = elem.at_xpath('./dtt:Nazev_PF')
244
+ @name = name ? name.content : nil
245
+ person = elem.at_xpath('./dtt:PF_osoba')
246
+ @person = person ? person.content : nil
247
+ @text = elem.xpath('./dtt:Text').map(&:content).join("\n")
248
+ person_type = elem.at_xpath('./dtt:TZU_osoba')
249
+ @person_type = person_type ? person_type.content : nil
250
+ end
251
+ end
252
+
253
+ # <Identification> element
254
+ class Identification
255
+ # WTF: addr_puv? ares_answer_v_1.0.1.xsd:56 Adr_puv = dtt:adresa_ARES
256
+
257
+ # @!attribute [r] person
258
+ # @return [Person] <are:Osoba>
259
+ # @!attribute [r] address
260
+ # @return [AresAddress] <are:Adresa_ARES>
261
+ # @!attribute [r] addr_puv
262
+ # @return [AresAddress] <are:Adr_puv>
263
+ attr_reader :person, :address, :addr_puv
264
+
265
+ def initialize(elem)
266
+ person = elem.at_xpath('./are:Osoba')
267
+ @person = person ? Person.new(person) : nil
268
+
269
+ address = elem.at_xpath('./are:Adresa_ARES')
270
+ @address = address ? AresAddress.new(address) : nil
271
+
272
+ address = elem.at_xpath('./are:Adr_puv')
273
+ @addr_puv = address ? AresAddress.new(address) : nil
274
+ end
275
+ end
276
+
277
+ # <Osoba> element
278
+ class Person
279
+ attr_reader :title_before, :name, :last_name, :title_after, :birthdate, :personal_id_number,
280
+ :text, :address
281
+
282
+ def initialize(elem)
283
+ @title_before = text(elem, 'dtt:Titul_pred')
284
+ @name = text(elem, 'dtt:Jmeno')
285
+ @last_name = text(elem, 'dtt:Prijmeni')
286
+ @title_after = text(elem, 'dtt:Titul_za')
287
+ @birthdate = text(elem, 'dtt:Datum_narozeni')
288
+ @personal_id_number = text(elem, 'dtt:Rodne_cislo')
289
+ @text = text(elem, 'dtt:Osoba_textem')
290
+ address = elem.at_xpath('./dtt:Bydliste')
291
+ @address = address ? AresAddress.new(address) : nil
292
+ end
293
+ end
294
+
295
+ # Ares address definition
296
+ # ares_datatypes_v_1.0.4.xsd:788
297
+ class AresAddress
298
+ # Názvy:
299
+ # uol ico: 27074358
300
+ # en: http://wwwinfo.mfcr.cz/cgi-bin/ares/ares_sad.cgi?zdroj=0&adr=204437556&jazyk=en
301
+ # cs: http://wwwinfo.mfcr.cz/cgi-bin/ares/ares_sad.cgi?zdroj=0&adr=204437556
302
+
303
+ # @!attribute [r] id
304
+ # @return [Integer] Address ID (ID_adresy)
305
+ # @!attribute [r] state_code
306
+ # @return [Integer] State code (Kod_statu)
307
+ # @!attribute [r] state
308
+ # @return [Integer] State name (Nazev_statu)
309
+ # @!attribute [r] territory
310
+ # @return [Integer] Territory (Nazev_oblasti)
311
+ # @!attribute [r] region
312
+ # @return [Integer] Region (Nazev_kraje)
313
+ # @!attribute [r] district
314
+ # @return [Integer] District (Nazev_okresu)
315
+ # @!attribute [r] town
316
+ # @return [Integer] Town (Nazev_obce)
317
+ # @!attribute [r] residential_area
318
+ # @return [Integer] Residential area (Nazev_casti_obce)
319
+ # @!attribute [r] town_district
320
+ # @return [Integer] Town district (Nazev_mestske_casti)
321
+ # @!attribute [r] street
322
+ # @return [Integer] Street (Nazev_ulice)
323
+ # @!attribute [r] building_number
324
+ # @return [Integer] Building number (Cislo_domovni)
325
+ # @!attribute [r] sequence_number
326
+ # @return [Integer] Sequence number (Cislo_orientacni)
327
+ # @!attribute [r] land_registry_number
328
+ # @return [Integer] Land-registry number (Cislo_do_adresy)
329
+ # @!attribute [r] postcode
330
+ # @return [Integer] postcode (PSC)
331
+ # @!attribute [r] foreign_postcode
332
+ # @return [Integer] Foreign postcode (Zahr_PSC)
333
+ attr_reader :id, :state_code, :state, :territory, :region, :district, :town, :residential_area,
334
+ :town_district, :street, :building_number, :sequence_number, :land_registry_number,
335
+ :postcode, :foreign_postcode
336
+
337
+ # TODO: Dopřeložit
338
+
339
+ # @!attribute [r] pobvod
340
+ # @return [Integer] (Nazev_pobvodu)
341
+ attr_reader :pobvod
342
+
343
+ def initialize(elem)
344
+ @id = find(elem, 'dtt:ID_adresy')
345
+ @state_code = find(elem, 'dtt:Kod_statu')
346
+ @state = find(elem, 'dtt:Nazev_statu')
347
+ @territory = find(elem, 'dtt:Nazev_oblasti')
348
+ @region = find(elem, 'dtt:Nazev_kraje')
349
+ @district = find(elem, 'dtt:Nazev_okresu')
350
+ @town = find(elem, 'dtt:Nazev_obce')
351
+ @pobvod = find(elem, 'dtt:Nazev_pobvodu')
352
+ @residential_area = find(elem, 'dtt:Nazev_casti_obce')
353
+ @town_district = find(elem, 'dtt:Nazev_mestske_casti')
354
+ @street = find(elem, 'dtt:Nazev_ulice')
355
+ @building_number = find(elem, 'dtt:Cislo_domovni')
356
+ @sequence_number = find(elem, 'dtt:Cislo_orientacni')
357
+ @land_registry_number = find(elem, 'dtt:Cislo_do_adresy')
358
+ @postcode = find(elem, 'dtt:PSC')
359
+ @foreign_postcode = find(elem, 'dtt:Zahr_PSC')
360
+ @text = find(elem, 'dtt:Adresa_textem')
361
+ end
362
+
363
+ def inspect
364
+ "#<AresAddress \"#{@id || @text}\""
365
+ end
366
+
367
+ # TODO: localize
368
+ # @param lang [String] ('cz') Language
369
+ def to_s(lang = 'cz')
370
+ s = ''
371
+ if street
372
+ s << street
373
+ s << " #{land_registry_number}" if land_registry_number
374
+ if sequence_number || building_number
375
+ s << ' '
376
+ s << sequence_number if sequence_number
377
+ s << '/' if building_number && sequence_number
378
+ s << building_number if building_number
379
+ end
380
+ s << ", #{postcode} #{town}"
381
+ if residential_area
382
+ (town =~ /-/) ? s << ',' : s << '-' if town
383
+ s << residential_area
384
+ end
385
+ else
386
+ s << "#{postcode} #{town}"
387
+ if residential_area
388
+ s << '-' if town
389
+ s << residential_area
390
+ end
391
+ s << " #{land_registry_number}" if land_registry_number
392
+ if land_registry_number && building_number
393
+ s << ' '
394
+ s << sequence_number if sequence_number
395
+ s << '/' if building_number && sequence_number
396
+ s << building_number if building_number
397
+ end
398
+ end
399
+ if lang == 'en'
400
+ s << ", District: #{district}" if district
401
+ s << ", State: #{state}" if state
402
+ else
403
+ s << ", okres: #{district}" if district
404
+ s << ", stát: #{state}" if state
405
+ end
406
+ s
407
+ end
408
+
409
+ private
410
+
411
+ def find(elem, path)
412
+ res = elem.at_xpath("./#{path}")
413
+ res.nil? ? nil : res.content
414
+ end
415
+ end
416
+
417
+ # <Priznaky_subjektu>
418
+ #
419
+ # http://wwwinfo.mfcr.cz/ares/ares_xml_standard.html.en
420
+ class StatusFlags
421
+ attr_reader :flags
422
+
423
+ def initialize(elem)
424
+ flags = elem.at_xpath('./are:Priznaky_subjektu')
425
+ @flags = flags ? flags.value : nil
426
+ end
427
+
428
+ def [](index)
429
+ @flags[index]
430
+ end
431
+
432
+ def inspect
433
+ "#<StatusFlags #{@flags}>"
434
+ end
435
+ end
436
+ end
437
+ end
438
+ end
@@ -0,0 +1,3 @@
1
+ module Ares
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ares.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ondřej Svoboda
8
+ - Bohuslav Blin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: webmock
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: vcr
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: httparty
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: nokogiri
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: Gem for accesing business information from ARES database.
113
+ email:
114
+ - blin@uol.cz
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".ruby-gemset"
122
+ - ".ruby-version"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - README.md
126
+ - Rakefile
127
+ - TODO.md
128
+ - ares.gemspec
129
+ - lib/ares.rb
130
+ - lib/ares/client.rb
131
+ - lib/ares/client/standard.rb
132
+ - lib/ares/errors.rb
133
+ - lib/ares/http.rb
134
+ - lib/ares/logging.rb
135
+ - lib/ares/responses.rb
136
+ - lib/ares/responses/standard_response.rb
137
+ - lib/ares/version.rb
138
+ homepage: http://www.uol.cz
139
+ licenses: []
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: ARES library
161
+ test_files: []