ares_rest 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 +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/lib/ares_rest/version.rb +6 -0
- data/lib/ares_rest.rb +147 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1157c4e6280ca0a075b900c9c6d3966d9ff6bc55c07edf3d1fcb862fac6581e0
|
|
4
|
+
data.tar.gz: a8f87d8e82b7e8cd6fcd5e244c68fa62a342eab0be2ead87977f35bebe82bb7c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a95bf05d02767b4036a2180237f1085e05dad83cac417657da6488f29ddafeeb7a548f40e477b195a5ef9d348a7b9a4f4fe6299b4340d01450405a0d73f47404
|
|
7
|
+
data.tar.gz: 9ccd38d547fb8b8597580dfb457a177b13f57971c4a78153ac97ca5ba9a99460c2e59aaf40f94f0f506ee68fc80d749ac99b3a5e95cefd0c829301cb1318d42e
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-10-08
|
|
4
|
+
|
|
5
|
+
- Initial release
|
|
6
|
+
- Add `AresRest.find` to look up a company by IČO
|
|
7
|
+
- Add `AresRest::Subject` with name, DIČ, registered address and the raw response via `data`
|
|
8
|
+
- Add `NotFoundError` and `InvalidIcoError`; network and parsing failures raise `AresRest::Error`
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"ares_rest" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["tomaslepicg@gmail.com"](mailto:"tomaslepicg@gmail.com").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lepi1
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# AresRest
|
|
2
|
+
|
|
3
|
+
Simple Ruby client for the Czech [ARES](https://ares.gov.cz/) registry. Finds a company by IČO.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "ares_rest", github: "lepi1/ares_rest"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
company = AresRest.find("12345678")
|
|
15
|
+
company.name # => "Example s.r.o."
|
|
16
|
+
company.street # => "Hlavní 123/4"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Returns an `AresRest::Subject`. Other attributes: `ico`, `dic`, `city`, `postal_code`, `address`. There is also `to_h`.
|
|
20
|
+
|
|
21
|
+
For fields not mapped yet, use the raw ARES response:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
company.data["datumVzniku"] # => "2020-01-01"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Raises `AresRest::NotFoundError` when the IČO doesn't exist, `AresRest::InvalidIcoError` for a malformed IČO and `AresRest::Error` for anything else (network errors, timeouts). All of them inherit from `AresRest::Error`.
|
|
28
|
+
|
|
29
|
+
## Development
|
|
30
|
+
|
|
31
|
+
Run `bin/setup` to install dependencies, then `bundle exec rake` to run tests and RuboCop. `bin/console` gives you an interactive prompt.
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lepi1/ares_rest. Contributors are expected to follow the [code of conduct](https://github.com/lepi1/ares_rest/blob/master/CODE_OF_CONDUCT.md).
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
[MIT](https://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/lib/ares_rest.rb
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "uri"
|
|
7
|
+
require_relative "ares_rest/version"
|
|
8
|
+
|
|
9
|
+
# Module for calling Ares API
|
|
10
|
+
# https://ares.gov.cz/swagger-ui/#/
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# subject = AresRest.find("12345678")
|
|
14
|
+
# subject.name # => "Example s.r.o."
|
|
15
|
+
# subject.street # => "Hlavní 123/4"
|
|
16
|
+
module AresRest
|
|
17
|
+
# Base class for all errors raised by this gem.
|
|
18
|
+
class Error < StandardError; end
|
|
19
|
+
|
|
20
|
+
# Raised when ARES has no subject with the given IČO.
|
|
21
|
+
class NotFoundError < Error; end
|
|
22
|
+
|
|
23
|
+
# Raised when the IČO is malformed or ARES rejects it.
|
|
24
|
+
class InvalidIcoError < Error; end
|
|
25
|
+
|
|
26
|
+
BASE_URL = "https://ares.gov.cz/ekonomicke-subjekty-v-be/rest"
|
|
27
|
+
BY_ICO_ENDPOINT = "#{BASE_URL}/ekonomicke-subjekty/%s".freeze
|
|
28
|
+
OPEN_TIMEOUT = 5
|
|
29
|
+
READ_TIMEOUT = 10
|
|
30
|
+
NETWORK_ERRORS = [
|
|
31
|
+
SocketError, Timeout::Error, IOError, SystemCallError, OpenSSL::SSL::SSLError
|
|
32
|
+
].freeze
|
|
33
|
+
private_constant :BASE_URL, :BY_ICO_ENDPOINT, :OPEN_TIMEOUT, :READ_TIMEOUT, :NETWORK_ERRORS
|
|
34
|
+
|
|
35
|
+
# Economic subject (company, sole trader, association, ...) returned by ARES.
|
|
36
|
+
# The full parsed response is available via {#data}.
|
|
37
|
+
class Subject
|
|
38
|
+
# @return [String, nil] IČO, 8 digits
|
|
39
|
+
attr_reader :ico
|
|
40
|
+
|
|
41
|
+
# @return [String, nil] business name (obchodní jméno)
|
|
42
|
+
attr_reader :name
|
|
43
|
+
|
|
44
|
+
# @return [String, nil] VAT number (DIČ), e.g. "CZ12345678"
|
|
45
|
+
attr_reader :dic
|
|
46
|
+
|
|
47
|
+
# @return [String, nil] street with house number, e.g. "Hlavní 123/4a"
|
|
48
|
+
attr_reader :street
|
|
49
|
+
|
|
50
|
+
# @return [String, nil] municipality (název obce), without district,
|
|
51
|
+
# e.g. "Praha" even for an address in Praha 4
|
|
52
|
+
attr_reader :city
|
|
53
|
+
|
|
54
|
+
# @return [String, nil] postal code (PSČ) without spaces, e.g. "11000"
|
|
55
|
+
attr_reader :postal_code
|
|
56
|
+
|
|
57
|
+
# @return [String, nil] full one-line address as formatted by ARES
|
|
58
|
+
attr_reader :address
|
|
59
|
+
|
|
60
|
+
# Raw parsed ARES response, for fields without their own accessor.
|
|
61
|
+
#
|
|
62
|
+
# @example
|
|
63
|
+
# subject.data["datumVzniku"] # => "2020-01-01"
|
|
64
|
+
# @return [Hash{String => Object}]
|
|
65
|
+
attr_reader :data
|
|
66
|
+
|
|
67
|
+
# @api private
|
|
68
|
+
# @param data [Hash{String => Object}] parsed ARES response
|
|
69
|
+
def initialize(data)
|
|
70
|
+
@data = data
|
|
71
|
+
@ico = data["ico"]
|
|
72
|
+
@name = data["obchodniJmeno"]
|
|
73
|
+
@dic = data["dic"]
|
|
74
|
+
assign_address(data["sidlo"]) if data["sidlo"]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @return [Hash{Symbol => String, nil}] mapped attributes, without {#data}
|
|
78
|
+
def to_h
|
|
79
|
+
{ ico: ico, name: name, dic: dic, street: street, city: city, postal_code: postal_code, address: address }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Short representation without the raw {#data}.
|
|
83
|
+
#
|
|
84
|
+
# @example
|
|
85
|
+
# subject.inspect # => '#<AresRest::Subject ico="12345678" name="Example s.r.o.">'
|
|
86
|
+
# @return [String]
|
|
87
|
+
def inspect
|
|
88
|
+
"#<#{self.class} ico=#{ico.inspect} name=#{name.inspect}>"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def assign_address(location)
|
|
94
|
+
street = location["nazevUlice"] || location["nazevCastiObce"] || location["nazevObce"]
|
|
95
|
+
|
|
96
|
+
@street = "#{street} #{build_street_number_from(location)}".strip
|
|
97
|
+
@city = location["nazevObce"]
|
|
98
|
+
@postal_code = location["psc"]&.to_s&.gsub(/\s+/, "")
|
|
99
|
+
@address = location["textovaAdresa"]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def build_street_number_from(location)
|
|
103
|
+
orientacni = "#{location["cisloOrientacni"]}#{location["cisloOrientacniPismeno"]}"
|
|
104
|
+
[location["cisloDomovni"], orientacni].map(&:to_s).reject(&:empty?).join("/")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Looks up an economic subject by IČO.
|
|
109
|
+
#
|
|
110
|
+
# @param ico [String, Integer] 1-8 digits; whitespace is stripped and
|
|
111
|
+
# shorter numbers are padded with leading zeros
|
|
112
|
+
# @return [Subject]
|
|
113
|
+
# @raise [InvalidIcoError] if the IČO is malformed
|
|
114
|
+
# @raise [NotFoundError] if no subject has this IČO
|
|
115
|
+
# @raise [Error] on network failure, timeout or an unexpected response
|
|
116
|
+
# @example
|
|
117
|
+
# AresRest.find("12345678").name # => "Example s.r.o."
|
|
118
|
+
def self.find(ico)
|
|
119
|
+
response = get(URI(format(BY_ICO_ENDPOINT, normalize_ico(ico))))
|
|
120
|
+
|
|
121
|
+
case response.code
|
|
122
|
+
when "200" then Subject.new(JSON.parse(response.body))
|
|
123
|
+
when "404" then raise NotFoundError, "Cannot find subject with ICO #{ico}"
|
|
124
|
+
when "400" then raise InvalidIcoError, "ARES rejected ICO #{ico}"
|
|
125
|
+
else raise Error, "Unexpected ARES response: HTTP #{response.code}"
|
|
126
|
+
end
|
|
127
|
+
rescue JSON::ParserError => e
|
|
128
|
+
raise Error, "Invalid ARES response: #{e.message}"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def self.normalize_ico(ico)
|
|
132
|
+
normalized = ico.to_s.gsub(/\s+/, "")
|
|
133
|
+
raise InvalidIcoError, "ICO must be 1-8 digits, got #{ico.inspect}" unless normalized.match?(/\A\d{1,8}\z/)
|
|
134
|
+
|
|
135
|
+
normalized.rjust(8, "0")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.get(uri)
|
|
139
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT) do |http|
|
|
140
|
+
http.request(Net::HTTP::Get.new(uri, "Accept" => "application/json"))
|
|
141
|
+
end
|
|
142
|
+
rescue *NETWORK_ERRORS => e
|
|
143
|
+
raise Error, "Communication error: #{e.message}"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
private_class_method :normalize_ico, :get
|
|
147
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ares_rest
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- lepi1
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Look up Czech companies by ICO (IČO) using the official ARES REST API.
|
|
13
|
+
email:
|
|
14
|
+
- public@tomaslepic.cz
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- ".yardopts"
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- CODE_OF_CONDUCT.md
|
|
22
|
+
- LICENSE.txt
|
|
23
|
+
- README.md
|
|
24
|
+
- Rakefile
|
|
25
|
+
- lib/ares_rest.rb
|
|
26
|
+
- lib/ares_rest/version.rb
|
|
27
|
+
homepage: https://github.com/lepi1/ares_rest
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
allowed_push_host: https://rubygems.org
|
|
32
|
+
homepage_uri: https://github.com/lepi1/ares_rest
|
|
33
|
+
source_code_uri: https://github.com/lepi1/ares_rest
|
|
34
|
+
changelog_uri: https://github.com/lepi1/ares_rest/blob/master/CHANGELOG.md
|
|
35
|
+
rubygems_mfa_required: 'true'
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 3.2.0
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 4.0.10
|
|
51
|
+
specification_version: 4
|
|
52
|
+
summary: Ruby client for the Czech ARES business registry API
|
|
53
|
+
test_files: []
|