ares.rb 0.3.2 → 0.4.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 +5 -5
- data/.rubocop.yml +23 -0
- data/.travis.yml +35 -4
- data/Gemfile +2 -0
- data/Rakefile +5 -3
- data/ares.gemspec +10 -7
- data/bin/console +7 -0
- data/lib/ares.rb +29 -12
- data/lib/ares/client/base.rb +27 -0
- data/lib/ares/client/basic.rb +24 -0
- data/lib/ares/client/standard.rb +6 -8
- data/lib/ares/errors.rb +5 -3
- data/lib/ares/http.rb +2 -0
- data/lib/ares/logging.rb +3 -1
- data/lib/ares/responses.rb +5 -3
- data/lib/ares/responses/base.rb +64 -0
- data/lib/ares/responses/basic.rb +137 -0
- data/lib/ares/responses/{standard_response.rb → standard.rb} +71 -100
- data/lib/ares/version.rb +3 -1
- metadata +45 -12
- data/lib/ares/client.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f91b5af9bca65eb5d80708b5abf1900fd66565e6132f1936e8a51c348c04d84e
|
4
|
+
data.tar.gz: fd81071e422c3ba4aa53325879774cf4bb36c0fa9a02399f1e1e6d1540f23cee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e066a7e10bba0b844427f77ffc15f1bd20600fced8419971e413b5b95fa2ca5da13f4e3a3edcb63b4bd2e37cc92ad7df26c3f3eef1256594bc22e9980fcbf1be
|
7
|
+
data.tar.gz: a5a8e93814b4384c91c8aaba681db4e9ca24a8613ee39d7ebc59d180949aac589480aebbfe04d2ba241c1933f1ecf3ec9af8e6730b4e753e432439c5d291454e
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'ares.gemspec'
|
4
|
+
- 'spec/**/*'
|
5
|
+
TargetRubyVersion: 2.3
|
6
|
+
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 89
|
12
|
+
|
13
|
+
Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Naming/VariableName:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Naming/UncommunicativeMethodParamName:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/MultilineIfModifier:
|
23
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,7 +1,38 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.3.1
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
- 2.4.5
|
5
|
+
- 2.5.3
|
6
|
+
- 2.6.0
|
7
|
+
|
8
|
+
stages:
|
9
|
+
- code-quality
|
10
|
+
- test
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
include:
|
14
|
+
- rvm: 2.3.1
|
15
|
+
stage: code-quality
|
16
|
+
script: bundle exec rubocop
|
17
|
+
- rvm: 2.3.1
|
18
|
+
stage: test
|
19
|
+
script: bundle exec rspec
|
20
|
+
- rvm: 2.4.5
|
21
|
+
stage: code-quality
|
22
|
+
script: bundle exec rubocop
|
23
|
+
- rvm: 2.4.5
|
24
|
+
stage: test
|
25
|
+
script: bundle exec rspec
|
26
|
+
- rvm: 2.5.3
|
27
|
+
stage: code-quality
|
28
|
+
script: bundle exec rubocop
|
29
|
+
- rvm: 2.5.3
|
30
|
+
stage: test
|
31
|
+
script: bundle exec rspec
|
32
|
+
- rvm: 2.6.0
|
33
|
+
stage: code-quality
|
34
|
+
script: bundle exec rubocop
|
35
|
+
- rvm: 2.6.0
|
36
|
+
stage: test
|
37
|
+
script: bundle exec rspec
|
38
|
+
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/ares.gemspec
CHANGED
@@ -1,30 +1,33 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'ares/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = 'ares.rb'
|
8
9
|
spec.version = Ares::VERSION
|
9
|
-
spec.authors = ['Ondřej Svoboda','Bohuslav Blin']
|
10
|
+
spec.authors = ['Ondřej Svoboda', 'Bohuslav Blin']
|
10
11
|
spec.email = ['blin@uol.cz']
|
11
12
|
|
12
13
|
spec.summary = 'ARES library'
|
13
14
|
spec.description = 'Gem for accesing business information from ARES database.'
|
14
|
-
spec.homepage =
|
15
|
+
spec.homepage = 'http://www.uol.cz'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
18
|
spec.require_paths = ['lib']
|
18
19
|
|
19
20
|
spec.add_dependency 'ico-validator', '~> 0.4'
|
20
21
|
|
21
|
-
spec.add_development_dependency '
|
22
|
+
spec.add_development_dependency 'pry'
|
23
|
+
spec.add_development_dependency 'rails'
|
22
24
|
spec.add_development_dependency 'rake', '~> 11.0'
|
23
25
|
spec.add_development_dependency 'rspec'
|
24
|
-
spec.add_development_dependency '
|
26
|
+
spec.add_development_dependency 'rubocop'
|
25
27
|
spec.add_development_dependency 'vcr'
|
26
|
-
spec.add_development_dependency '
|
28
|
+
spec.add_development_dependency 'webmock'
|
27
29
|
|
28
30
|
spec.add_runtime_dependency 'httparty'
|
29
31
|
spec.add_runtime_dependency 'nokogiri'
|
32
|
+
spec.add_runtime_dependency 'activesupport'
|
30
33
|
end
|
data/bin/console
ADDED
data/lib/ares.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'httparty'
|
2
4
|
require 'nokogiri'
|
5
|
+
require 'active_support/core_ext/hash'
|
6
|
+
|
3
7
|
require 'ares/version'
|
4
8
|
require 'ares/errors'
|
5
9
|
require 'ares/logging'
|
6
|
-
require 'ares/
|
10
|
+
require 'ares/http'
|
11
|
+
|
12
|
+
require 'ares/responses'
|
13
|
+
require 'ares/responses/base'
|
14
|
+
require 'ares/responses/standard'
|
15
|
+
require 'ares/responses/basic'
|
16
|
+
|
17
|
+
require 'ares/client/base'
|
18
|
+
require 'ares/client/standard'
|
19
|
+
require 'ares/client/basic'
|
20
|
+
|
7
21
|
require 'ico-validator'
|
8
22
|
|
9
23
|
module Ares
|
@@ -20,27 +34,30 @@ module Ares
|
|
20
34
|
class << self
|
21
35
|
include Ares::Logging
|
22
36
|
|
23
|
-
# Returns standard client
|
24
|
-
# @returns [Client::Standard]
|
25
|
-
def client
|
26
|
-
@client ||= Client.standard
|
27
|
-
end
|
28
|
-
|
29
37
|
# @see Client::Standard#call
|
30
38
|
# @return [Responses::StandardResponse::Record]
|
31
39
|
def standard(options)
|
32
40
|
validate_ico_format(options[:ico])
|
33
|
-
response =
|
34
|
-
|
41
|
+
response = Client::Standard.call(options)
|
42
|
+
raise ArgumentError, "Arguments #{options} are invalid" if response.error?
|
43
|
+
|
44
|
+
response.record
|
45
|
+
end
|
46
|
+
|
47
|
+
# @see Client::Basic#call
|
48
|
+
# @return [Responses::NoIdeaNow::Record]
|
49
|
+
def basic(options)
|
50
|
+
validate_ico_format(options[:ico])
|
51
|
+
response = Client::Basic.call(options)
|
52
|
+
raise ArgumentError, "Arguments #{options} are invalid" if response.error?
|
53
|
+
|
35
54
|
response.record
|
36
55
|
end
|
37
56
|
|
38
57
|
private
|
39
58
|
|
40
59
|
def validate_ico_format(ico)
|
41
|
-
unless IcoValidation.valid_ico?(ico)
|
42
|
-
fail ArgumentError, "ICO '#{ico}' is invalid"
|
43
|
-
end
|
60
|
+
raise ArgumentError, "ICO '#{ico}' is invalid" unless IcoValidation.valid_ico?(ico)
|
44
61
|
end
|
45
62
|
end
|
46
63
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'ares/responses/standard_response'
|
4
|
+
|
5
|
+
module Ares
|
6
|
+
module Client
|
7
|
+
class Base
|
8
|
+
include Ares::Http
|
9
|
+
|
10
|
+
def self.call(opts)
|
11
|
+
new.call(opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(opts)
|
15
|
+
xml = get(self.class::ENDPOINT, opts)
|
16
|
+
document = Nokogiri::XML(xml)
|
17
|
+
process_response(document)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def process_response(_document)
|
23
|
+
raise NotImplementedError, "#{self.class} must implement process_response}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# From what I can quickly find I can only search by ICO
|
5
|
+
# at least for the time being...
|
6
|
+
#
|
7
|
+
module Ares
|
8
|
+
module Client
|
9
|
+
class Basic < Base
|
10
|
+
ENDPOINT = 'https://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi'
|
11
|
+
|
12
|
+
def call(opts)
|
13
|
+
xml = get(self.class::ENDPOINT, opts.merge!(ver: '1.0.2'))
|
14
|
+
process_response(xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def process_response(document)
|
20
|
+
Ares::Responses::Basic.new(document)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ares/client/standard.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Ares
|
4
4
|
module Client
|
5
|
-
class Standard
|
5
|
+
class Standard < Base
|
6
6
|
ENDPOINT = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi'
|
7
7
|
|
8
|
-
|
8
|
+
private
|
9
9
|
|
10
10
|
# Search for standard entity's identification data
|
11
11
|
#
|
@@ -24,11 +24,9 @@ module Ares
|
|
24
24
|
# @option opts [Integer] :diakritika (1) [0, 1]
|
25
25
|
# @option opts [String] :czk (iso) Encoding [iso, utf]
|
26
26
|
# @returns [Ares::Responses::StandardResponse]
|
27
|
-
def
|
28
|
-
|
29
|
-
document = Nokogiri::XML(xml)
|
30
|
-
Ares::Responses::StandardResponse.new(document)
|
27
|
+
def process_response(document)
|
28
|
+
Ares::Responses::Standard.new(document)
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
34
|
-
end
|
32
|
+
end
|
data/lib/ares/errors.rb
CHANGED
data/lib/ares/http.rb
CHANGED
data/lib/ares/logging.rb
CHANGED
data/lib/ares/responses.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ares
|
2
4
|
module Responses
|
3
5
|
class TextCode
|
@@ -19,9 +21,9 @@ module Ares
|
|
19
21
|
end
|
20
22
|
|
21
23
|
class Error < TextCode
|
22
|
-
def error
|
24
|
+
def error?
|
25
|
+
true
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
26
|
-
|
27
|
-
require 'ares/responses/standard_response'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Ares
|
2
|
+
module Responses
|
3
|
+
class Base
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
# @!attribute [r] xml_document
|
7
|
+
# @return [String] XML Document returned by ares
|
8
|
+
# @!attribute [r] time
|
9
|
+
# @return [String] Created at
|
10
|
+
# @!attribute [r] count
|
11
|
+
# @return [String] Element count
|
12
|
+
# @!attribute [r] type
|
13
|
+
# @return [String] 'Standard'
|
14
|
+
# @!attribute [r] output_format
|
15
|
+
# @return [String] 'XML'
|
16
|
+
# @!attribute [r] xslt
|
17
|
+
# @return [String] 'klient'
|
18
|
+
# @!attribute [r] validation_xslt
|
19
|
+
# @return [String] Path to xsl document
|
20
|
+
# @!attribute [r] id
|
21
|
+
# @return [String] ID
|
22
|
+
attr_reader :xml_document, :time, :count, :type,
|
23
|
+
:output_format, :xslt, :validation_xslt, :id
|
24
|
+
|
25
|
+
# Returns response with found company
|
26
|
+
# or nil if not found.
|
27
|
+
#
|
28
|
+
# @returns [Response, NilClass] response
|
29
|
+
def response
|
30
|
+
@content.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def record
|
34
|
+
response ? response.records.first : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def error?
|
38
|
+
any?(&:error?)
|
39
|
+
end
|
40
|
+
|
41
|
+
def each(&block)
|
42
|
+
@content.each(&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_xml
|
46
|
+
@xml_document.to_xml
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
# rubocop:disable Metrics/AbcSize
|
52
|
+
def assign_base_attributes(attributes)
|
53
|
+
@time = attributes['odpoved_datum_cas'].to_s
|
54
|
+
@count = attributes['odpoved_pocet'].to_s
|
55
|
+
@type = attributes['odpoved_typ'].to_s # musi byt 'Standard'
|
56
|
+
@output_format = (attributes['vystup_format'] || 'XML').to_s
|
57
|
+
@xslt = (attributes['xslt'] || 'klient').to_s
|
58
|
+
@validation_xslt = attributes['validation_XSLT'].to_s
|
59
|
+
@id = attributes['Id'].to_s
|
60
|
+
end
|
61
|
+
# rubocop:enable Metrics/AbcSize
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Ares
|
2
|
+
module Responses
|
3
|
+
class Basic < Base
|
4
|
+
def initialize(xml_document)
|
5
|
+
@response_hash = Hash.from_xml(xml_document)
|
6
|
+
@base_response = @response_hash.values.first
|
7
|
+
|
8
|
+
assign_base_attributes(@base_response)
|
9
|
+
|
10
|
+
@content = @base_response.map { |key, value| parse_elem(key, value) }.compact
|
11
|
+
end
|
12
|
+
|
13
|
+
def error?
|
14
|
+
@content.any? { |e| e.is_a? Ares::Responses::Error }
|
15
|
+
end
|
16
|
+
|
17
|
+
def record
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_elem(key, value)
|
22
|
+
case key
|
23
|
+
when 'Fault'
|
24
|
+
Ares::Responses::Error.new(
|
25
|
+
value,
|
26
|
+
value['faultcode'].to_s,
|
27
|
+
value['faultstring'].to_s
|
28
|
+
)
|
29
|
+
when 'Odpoved'
|
30
|
+
Response.new(value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Base
|
35
|
+
# rubocop:disable Metrics/MethodLength
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
37
|
+
def initialize(value)
|
38
|
+
self.class.class_eval do
|
39
|
+
if const_defined?(:ATTRIBUTES)
|
40
|
+
attr_reader(*const_get(:ATTRIBUTES).map(&:parameterize))
|
41
|
+
end
|
42
|
+
if const_defined?(:COMPOSITE_ATTRIBUTES)
|
43
|
+
attr_reader(*const_get(:COMPOSITE_ATTRIBUTES)
|
44
|
+
.values.map(&:parameterize))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
return unless value
|
49
|
+
|
50
|
+
if self.class.const_defined?(:ATTRIBUTES)
|
51
|
+
self.class::ATTRIBUTES.each do |attribute|
|
52
|
+
instance_variable_set("@#{attribute.parameterize}",
|
53
|
+
value[attribute].presence)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
self.class::COMPOSITE_ATTRIBUTES.each do |class_name, key|
|
57
|
+
full_class = "Ares::Responses::Basic::#{class_name}".constantize
|
58
|
+
instance_variable_set("@#{key.parameterize}",
|
59
|
+
full_class.new(value[key].presence))
|
60
|
+
end if self.class.const_defined?(:COMPOSITE_ATTRIBUTES)
|
61
|
+
end
|
62
|
+
# rubocop:enable Metrics/AbcSize
|
63
|
+
# rubocop:enable Metrics/MethodLength
|
64
|
+
end
|
65
|
+
|
66
|
+
class Response < Base
|
67
|
+
ATTRIBUTES = %w[Pomocne_ID Vysledek_hledani Pocet_zaznamu].freeze
|
68
|
+
|
69
|
+
COMPOSITE_ATTRIBUTES = {
|
70
|
+
Introduction: 'Uvod',
|
71
|
+
Record: 'Vypis_basic'
|
72
|
+
}.freeze
|
73
|
+
end
|
74
|
+
|
75
|
+
class Record < Base
|
76
|
+
ATTRIBUTES = %w[ICO Obchodni_firma Datum_vzniku Adresa_ARES Priznaky_subjektu
|
77
|
+
Kategorie_poctu_pracovniku].freeze
|
78
|
+
|
79
|
+
COMPOSITE_ATTRIBUTES = {
|
80
|
+
LegalForm: 'Pravni_forma',
|
81
|
+
SendingAddress: 'Adresa_dorucovaci',
|
82
|
+
Address: 'Adresa_ARES',
|
83
|
+
CzNace: 'Nace',
|
84
|
+
RegisteredInstitution: 'Registrace_RZP'
|
85
|
+
}.freeze
|
86
|
+
end
|
87
|
+
|
88
|
+
class RegisteredInstitution < Base
|
89
|
+
COMPOSITE_ATTRIBUTES = {
|
90
|
+
BusinessOffice: 'Zivnostensky_urad',
|
91
|
+
FinanceOffice: 'Financni_urad'
|
92
|
+
}.freeze
|
93
|
+
end
|
94
|
+
|
95
|
+
class BusinessOffice < Base
|
96
|
+
ATTRIBUTES = %w[Kod_ZU Nazev_ZU].freeze
|
97
|
+
end
|
98
|
+
|
99
|
+
class FinanceOffice < Base
|
100
|
+
ATTRIBUTES = %w[Kod_FU Nazev_FU].freeze
|
101
|
+
end
|
102
|
+
|
103
|
+
class CzNace < Base
|
104
|
+
ATTRIBUTES = %w[NACE].freeze
|
105
|
+
end
|
106
|
+
|
107
|
+
class SendingAddress < Base
|
108
|
+
ATTRIBUTES = %w[zdroj Ulice_cislo PSC_obec].freeze
|
109
|
+
end
|
110
|
+
|
111
|
+
class Address < Base
|
112
|
+
ATTRIBUTES = %w[zdroj ID_adresy Kod_statu Nazev_statu Nazev_okresu Nazev_obce
|
113
|
+
Nazev_casti_obce Nazev_mestske_casti Nazev_ulice Cislo_domovni
|
114
|
+
Typ_cislo_domovni Cislo_orientacni PSC].freeze
|
115
|
+
|
116
|
+
COMPOSITE_ATTRIBUTES = {
|
117
|
+
AddressUIR: 'Adresa_UIR'
|
118
|
+
}.freeze
|
119
|
+
end
|
120
|
+
|
121
|
+
class AddressUIR < Base
|
122
|
+
ATTRIBUTES = %w[Kod_oblasti Kod_kraje Kod_okresu Kod_obce Kod_pobvod Kod_sobvod
|
123
|
+
Kod_casti_obce Kod_mestske_casti PSC Kod_ulice Cislo_domovni
|
124
|
+
Typ_cislo_domovni Cislo_orientacni Kod_adresy Kod_objektu
|
125
|
+
PCD].freeze
|
126
|
+
end
|
127
|
+
|
128
|
+
class LegalForm < Base
|
129
|
+
ATTRIBUTES = %w[zdroj Kod_PF Nazev_PF].freeze
|
130
|
+
end
|
131
|
+
|
132
|
+
class Introduction < Base
|
133
|
+
ATTRIBUTES = %w[Nadpis Aktualizace_DB Datum_vypisu Cas_vypisu Typ_odkazu].freeze
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -1,77 +1,32 @@
|
|
1
|
+
##
|
2
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
3
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
4
|
+
# rubocop:disable Metrics/MethodLength
|
5
|
+
# rubocop:disable Metrics/AbcSize
|
6
|
+
#
|
1
7
|
module Ares
|
2
8
|
module Responses
|
3
9
|
# Coresponds to <are:Ares_odpovedi> element.
|
4
|
-
class
|
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
|
-
|
10
|
+
class Standard < Base
|
26
11
|
def initialize(xml_document)
|
27
12
|
@xml_document = xml_document
|
28
13
|
|
29
|
-
|
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
|
14
|
+
assign_base_attributes(xml_document.root.attributes)
|
37
15
|
|
38
16
|
@content = xml_document.root.children.map { |elem| parse_elem elem }.compact
|
39
17
|
end
|
40
18
|
|
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
19
|
private
|
66
20
|
|
67
21
|
def parse_elem(elem)
|
68
|
-
|
22
|
+
case elem.name
|
23
|
+
when 'Fault'
|
69
24
|
Ares::Responses::Error.new(
|
70
|
-
|
71
|
-
|
72
|
-
|
25
|
+
elem,
|
26
|
+
elem.at_xpath('./faultcode/text()').to_s,
|
27
|
+
elem.at_xpath('./faultstring/text()').to_s
|
73
28
|
)
|
74
|
-
|
29
|
+
when 'Odpoved'
|
75
30
|
Response.new(elem)
|
76
31
|
end
|
77
32
|
end
|
@@ -86,7 +41,8 @@ module Ares
|
|
86
41
|
# @return [Integer] Responses count
|
87
42
|
# @!attribute [r] search_type
|
88
43
|
# @return [String] type of search:
|
89
|
-
# * FREE - searching by ico, if not found search
|
44
|
+
# * FREE - searching by ico, if not found search
|
45
|
+
# by RC, if not found find by company's name
|
90
46
|
# * ICO, RC, OF - search by type, if not found searching ends.
|
91
47
|
# Searching type is shown in (Kod_shody_*) element.
|
92
48
|
#
|
@@ -112,34 +68,37 @@ module Ares
|
|
112
68
|
private
|
113
69
|
|
114
70
|
# @param child [Nokogiri::XML::Element] Child element
|
71
|
+
# rubocop:disable Lint/EmptyWhen
|
115
72
|
def parse_elem(child)
|
116
73
|
case child.name
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
74
|
+
when 'Pomocne_ID'
|
75
|
+
@id = child.value
|
76
|
+
when 'Pocet_zaznamu'
|
77
|
+
@count = child.content.to_i
|
78
|
+
when 'Typ_vyhledani'
|
79
|
+
@search_type = child.content
|
80
|
+
when 'Error'
|
81
|
+
@records << Ares::Responses::Error.new(
|
82
|
+
child,
|
83
|
+
child.at_xpath('./Error_kod/text()').to_s,
|
84
|
+
child.at_xpath('./Error_text/text()').to_s
|
85
|
+
)
|
86
|
+
when 'Zaznam'
|
87
|
+
@records << Record.new(child)
|
88
|
+
when 'text'
|
89
|
+
# do nothing
|
90
|
+
else
|
91
|
+
Ares.logger.warn("#{self}: Unexpected record #{child.name} at #{child.path}")
|
135
92
|
end
|
136
93
|
end
|
94
|
+
# rubocop:enable Lint/EmptyWhen
|
137
95
|
end
|
138
96
|
|
139
97
|
# <are:Zaznam> element
|
140
98
|
class Record
|
141
99
|
# @!attribute [r] match
|
142
|
-
# @return [Responses::TextCode] <are:Shoda_ICO/RC/OF>
|
100
|
+
# @return [Responses::TextCode] <are:Shoda_ICO/RC/OF>
|
101
|
+
# Code of matching register ('ICO', 'RC', 'OF')
|
143
102
|
# @!attribute [r] search_by
|
144
103
|
# @return [String] <are:Vyhledano_dle> Register where record was found
|
145
104
|
# @!attribute [r] register_type
|
@@ -170,9 +129,10 @@ module Ares
|
|
170
129
|
def initialize(elem)
|
171
130
|
@match = get_match(elem)
|
172
131
|
@search_by = elem.at_xpath('./are:Vyhledano_dle').content
|
173
|
-
@register_type = TextCode
|
174
|
-
|
175
|
-
|
132
|
+
@register_type = TextCode
|
133
|
+
.new('RegisterType',
|
134
|
+
elem.at_xpath('./are:Typ_registru/dtt:Kod').content,
|
135
|
+
elem.at_xpath('./are:Typ_registru/dtt:Text').content)
|
176
136
|
date = elem.at_xpath('./are:Datum_vzniku')
|
177
137
|
@creation_date = date ? Time.parse(date.content) : nil
|
178
138
|
date = elem.at_xpath('./are:Datum_zaniku')
|
@@ -196,6 +156,7 @@ module Ares
|
|
196
156
|
# @returns [AresAddress, NilClass] Address
|
197
157
|
def address
|
198
158
|
return unless identification
|
159
|
+
|
199
160
|
identification.address
|
200
161
|
end
|
201
162
|
|
@@ -203,17 +164,17 @@ module Ares
|
|
203
164
|
|
204
165
|
def get_match(elem)
|
205
166
|
name = code = text = nil
|
206
|
-
if match = elem.at_xpath('./are:Shoda_ICO')
|
167
|
+
if (match = elem.at_xpath('./are:Shoda_ICO'))
|
207
168
|
name = 'Match ICO'
|
208
169
|
code = match.at_xpath('./dtt:Kod').content
|
209
170
|
text = match.at_xpath('./dtt:Text')
|
210
171
|
text = (text ? text.content : nil)
|
211
|
-
elsif match = elem.at_xpath('./are:Shoda_RC')
|
172
|
+
elsif (match = elem.at_xpath('./are:Shoda_RC'))
|
212
173
|
name = 'Match RC'
|
213
174
|
code = match.at_xpath('./dtt:Kod').content
|
214
175
|
text = match.at_xpath('./dtt:Text')
|
215
176
|
text = (text ? text.content : nil)
|
216
|
-
elsif match = elem.at_xpath('./are:Shoda_OF')
|
177
|
+
elsif (match = elem.at_xpath('./are:Shoda_OF'))
|
217
178
|
name = 'Match OF'
|
218
179
|
code = match.at_xpath('./dtt:Kod').content
|
219
180
|
text = match.at_xpath('./dtt:Text')
|
@@ -228,13 +189,13 @@ module Ares
|
|
228
189
|
|
229
190
|
# <Pravni_forma> element
|
230
191
|
class LegalForm
|
231
|
-
# Typ
|
232
|
-
# F-
|
233
|
-
# P-
|
234
|
-
# X-
|
235
|
-
# Z-
|
236
|
-
# O-
|
237
|
-
# C-
|
192
|
+
# Typ ekonomickeho subjektu:
|
193
|
+
# F-fyzicka osoba tuzemska,
|
194
|
+
# P-pravnicka osoba tuzemska,
|
195
|
+
# X-zahranicni pravnicka osoba,
|
196
|
+
# Z-zahranicni fyzicka osoba,
|
197
|
+
# O-fyzicka osoba s organizacni slozkou
|
198
|
+
# C-civilni osoba nepodnikajici (v CEU)
|
238
199
|
attr_reader :code, :name, :person, :text, :person_type
|
239
200
|
|
240
201
|
def initialize(elem)
|
@@ -280,8 +241,8 @@ module Ares
|
|
280
241
|
|
281
242
|
# <Osoba> element
|
282
243
|
class Person
|
283
|
-
attr_reader :title_before, :name, :last_name, :title_after,
|
284
|
-
:text, :address
|
244
|
+
attr_reader :title_before, :name, :last_name, :title_after,
|
245
|
+
:birthdate, :personal_id_number, :text, :address
|
285
246
|
|
286
247
|
def initialize(elem)
|
287
248
|
@title_before = elem.at_xpath('./dtt:Titul_pred')
|
@@ -299,7 +260,7 @@ module Ares
|
|
299
260
|
# Ares address definition
|
300
261
|
# ares_datatypes_v_1.0.4.xsd:788
|
301
262
|
class AresAddress
|
302
|
-
#
|
263
|
+
# Nazvy:
|
303
264
|
# uol ico: 27074358
|
304
265
|
# en: http://wwwinfo.mfcr.cz/cgi-bin/ares/ares_sad.cgi?zdroj=0&adr=204437556&jazyk=en
|
305
266
|
# cs: http://wwwinfo.mfcr.cz/cgi-bin/ares/ares_sad.cgi?zdroj=0&adr=204437556
|
@@ -334,11 +295,12 @@ module Ares
|
|
334
295
|
# @return [Integer] postcode (PSC)
|
335
296
|
# @!attribute [r] foreign_postcode
|
336
297
|
# @return [Integer] Foreign postcode (Zahr_PSC)
|
337
|
-
attr_reader :id, :state_code, :state, :territory, :region, :district,
|
338
|
-
:
|
298
|
+
attr_reader :id, :state_code, :state, :territory, :region, :district,
|
299
|
+
:town, :residential_area, :town_district, :street,
|
300
|
+
:building_number, :sequence_number, :land_registry_number,
|
339
301
|
:postcode, :foreign_postcode
|
340
302
|
|
341
|
-
# TODO:
|
303
|
+
# TODO: localize
|
342
304
|
|
343
305
|
# @!attribute [r] pobvod
|
344
306
|
# @return [Integer] (Nazev_pobvodu)
|
@@ -370,6 +332,8 @@ module Ares
|
|
370
332
|
|
371
333
|
# TODO: localize
|
372
334
|
# @param lang [String] ('cz') Language
|
335
|
+
#
|
336
|
+
# rubocop:disable Metrics/BlockNesting
|
373
337
|
def to_s(lang = 'cz')
|
374
338
|
s = ''
|
375
339
|
if street
|
@@ -383,7 +347,7 @@ module Ares
|
|
383
347
|
end
|
384
348
|
s << ", #{postcode} #{town}"
|
385
349
|
if residential_area
|
386
|
-
(town =~ /-/
|
350
|
+
s << (town =~ /-/ ? ',' : '-') if town
|
387
351
|
s << residential_area
|
388
352
|
end
|
389
353
|
else
|
@@ -409,6 +373,7 @@ module Ares
|
|
409
373
|
end
|
410
374
|
s
|
411
375
|
end
|
376
|
+
# rubocop:enable Metrics/BlockNesting
|
412
377
|
|
413
378
|
private
|
414
379
|
|
@@ -439,4 +404,10 @@ module Ares
|
|
439
404
|
end
|
440
405
|
end
|
441
406
|
end
|
442
|
-
end
|
407
|
+
end
|
408
|
+
#
|
409
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
410
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
411
|
+
# rubocop:enable Metrics/MethodLength
|
412
|
+
# rubocop:enable Metrics/AbcSize
|
413
|
+
##
|
data/lib/ares/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ares.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Svoboda
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ico-validator
|
@@ -26,19 +26,33 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0.4'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: pry
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rails
|
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
|
+
- - ">="
|
40
54
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: rake
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,7 +82,7 @@ dependencies:
|
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '0'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
85
|
+
name: rubocop
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
73
87
|
requirements:
|
74
88
|
- - ">="
|
@@ -96,7 +110,7 @@ dependencies:
|
|
96
110
|
- !ruby/object:Gem::Version
|
97
111
|
version: '0'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
113
|
+
name: webmock
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
116
|
- - ">="
|
@@ -137,6 +151,20 @@ dependencies:
|
|
137
151
|
- - ">="
|
138
152
|
- !ruby/object:Gem::Version
|
139
153
|
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: activesupport
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
type: :runtime
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
140
168
|
description: Gem for accesing business information from ARES database.
|
141
169
|
email:
|
142
170
|
- blin@uol.cz
|
@@ -147,6 +175,7 @@ files:
|
|
147
175
|
- ".gitignore"
|
148
176
|
- ".hound.yml"
|
149
177
|
- ".rspec"
|
178
|
+
- ".rubocop.yml"
|
150
179
|
- ".ruby-gemset"
|
151
180
|
- ".ruby-version"
|
152
181
|
- ".travis.yml"
|
@@ -156,14 +185,18 @@ files:
|
|
156
185
|
- Rakefile
|
157
186
|
- TODO.md
|
158
187
|
- ares.gemspec
|
188
|
+
- bin/console
|
159
189
|
- lib/ares.rb
|
160
|
-
- lib/ares/client.rb
|
190
|
+
- lib/ares/client/base.rb
|
191
|
+
- lib/ares/client/basic.rb
|
161
192
|
- lib/ares/client/standard.rb
|
162
193
|
- lib/ares/errors.rb
|
163
194
|
- lib/ares/http.rb
|
164
195
|
- lib/ares/logging.rb
|
165
196
|
- lib/ares/responses.rb
|
166
|
-
- lib/ares/responses/
|
197
|
+
- lib/ares/responses/base.rb
|
198
|
+
- lib/ares/responses/basic.rb
|
199
|
+
- lib/ares/responses/standard.rb
|
167
200
|
- lib/ares/version.rb
|
168
201
|
homepage: http://www.uol.cz
|
169
202
|
licenses: []
|
@@ -184,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
217
|
version: '0'
|
185
218
|
requirements: []
|
186
219
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
220
|
+
rubygems_version: 2.7.8
|
188
221
|
signing_key:
|
189
222
|
specification_version: 4
|
190
223
|
summary: ARES library
|