registeruz 1.0.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: 5de231d07357ce7f59e5d4afdc99fa8097d39796
4
+ data.tar.gz: 75bd98df4a5a39a961c45b91956c36084f067d5a
5
+ SHA512:
6
+ metadata.gz: c5032fb0c30ec32cd2d2c9781d0a4b8471751797a9600bbafeee3414824ba762506db8cfe4421fdd8e97cc227061579150cce69b52c72174afb0a6833db7d89a
7
+ data.tar.gz: e6f8a9fd0f435a16002810292a383ecd09248b8d7a6ef10e8379ab5ee9085690a0f574b343d05ac6d1f18e1af469b349c15e57a3d8089a6b2d3d4b1e403e2bba
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'registeruz.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
+ Style/VariableName:
17
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ registeruz
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.3
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ - 2.4.3
6
+ before_install: gem install bundler
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andrej@antas.cz. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gem_template.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ registeruz (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ ast (2.3.0)
12
+ childprocess (0.7.1)
13
+ ffi (~> 1.0, >= 1.0.11)
14
+ coderay (1.1.2)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.3)
18
+ docile (1.1.5)
19
+ ffi (1.9.18)
20
+ hashdiff (0.3.7)
21
+ iniparse (1.4.4)
22
+ json (2.1.0)
23
+ method_source (0.9.0)
24
+ overcommit (0.41.0)
25
+ childprocess (~> 0.6, >= 0.6.3)
26
+ iniparse (~> 1.4)
27
+ parallel (1.12.1)
28
+ parser (2.4.0.2)
29
+ ast (~> 2.3)
30
+ powerpack (0.1.1)
31
+ pry (0.11.3)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.9.0)
34
+ public_suffix (3.0.1)
35
+ rainbow (3.0.0)
36
+ rake (10.5.0)
37
+ rspec (3.7.0)
38
+ rspec-core (~> 3.7.0)
39
+ rspec-expectations (~> 3.7.0)
40
+ rspec-mocks (~> 3.7.0)
41
+ rspec-core (3.7.0)
42
+ rspec-support (~> 3.7.0)
43
+ rspec-expectations (3.7.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.7.0)
46
+ rspec-mocks (3.7.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-support (3.7.0)
50
+ rubocop (0.52.0)
51
+ parallel (~> 1.10)
52
+ parser (>= 2.4.0.2, < 3.0)
53
+ powerpack (~> 0.1)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (~> 1.0, >= 1.0.1)
57
+ ruby-progressbar (1.9.0)
58
+ safe_yaml (1.0.4)
59
+ simplecov (0.15.0)
60
+ docile (~> 1.1.0)
61
+ json (>= 1.8, < 3)
62
+ simplecov-html (~> 0.10.0)
63
+ simplecov-html (0.10.2)
64
+ unicode-display_width (1.3.0)
65
+ vcr (3.0.3)
66
+ webmock (3.1.1)
67
+ addressable (>= 2.3.6)
68
+ crack (>= 0.3.2)
69
+ hashdiff
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 1.16)
76
+ overcommit (~> 0.40)
77
+ pry (~> 0.10)
78
+ rake (~> 10.0)
79
+ registeruz!
80
+ rspec (~> 3.0)
81
+ rubocop (~> 0.49)
82
+ simplecov (~> 0.14)
83
+ vcr (~> 3.0)
84
+ webmock (~> 3.0)
85
+
86
+ BUNDLED WITH
87
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrej Antas
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,178 @@
1
+ # Registeruz
2
+
3
+ [![Build Status](https://travis-ci.org/redrick/registeruz.svg?branch=master)](https://travis-ci.org/redrick/registeruz)
4
+
5
+ Gem build as SVK alternation of [CZK Ares gem](https://github.com/ucetnictvi-on-line/ares.rb)
6
+
7
+ Allows you to get company/person information based on their ICO (we purely use
8
+ it this way, but could be bent to use it otherwise :) )
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'gem_template'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install gem_template
25
+
26
+ ## Usage
27
+
28
+ This gem has no setup, all data it accesses is free online, just enjoy them :)
29
+
30
+ Purely based on documentation found [here on
31
+ http://www.registeruz.sk/](http://www.registeruz.sk/cruz-public/home/api)
32
+
33
+ You can find many many details there, I will present you with use case I did
34
+ this for, if you are missing something, do not hesitate to contact me, will try
35
+ to have a look shortly...
36
+
37
+ You are provided with class `Registeruz::Subject` which allows you to search
38
+ through companies by attributes listed in official docs, I will go through ICO
39
+ lookup only here:
40
+
41
+ You can choose if you are searching and expect more items returned to use `where` (similar to rails activerecord method):
42
+
43
+ ```ruby
44
+ Registeruz::Subject.where(ico: 50826042)
45
+
46
+ [#<Registeruz::Models::Subject:0x00007fdc7a1a57a8
47
+ @city="Bratislava - mestská časť Rača",
48
+ @consolidated=false,
49
+ @data_origin="SUSR",
50
+ @dic=nil,
51
+ @district="Bratislava III",
52
+ @founded_at=2017-04-12 00:00:00 +0200,
53
+ @ico="50826042",
54
+ @id=1689373,
55
+ @legal_form="Spol. s r. o.",
56
+ @name="UOL SK s.r.o.",
57
+ @organization_size="nezistený",
58
+ @ownership_type="Zahraničné",
59
+ @postal_code="83106",
60
+ @region="Bratislavský kraj",
61
+ @residence="Bratislava-Rača",
62
+ @sk_nace_code="Účtovnícke činnosti",
63
+ @street="Karpatské námestie 10A",
64
+ @updated_at=2017-11-03 00:00:00 +0100>]
65
+ ```
66
+
67
+ if you get whole array of results, you can perform array operations on it...
68
+ that's a plus...
69
+
70
+ Otherwise searching by ICO seems to make more sense with usage of `find_by`
71
+ where object of `Registeruz::Subject` is being returned like this:
72
+
73
+ ```ruby
74
+ Registeruz::Subject.find_by(ico: 50826042)
75
+
76
+ #<Registeruz::Models::Subject:0x00007fdc7aa124b8
77
+ @city="Bratislava - mestská časť Rača",
78
+ @consolidated=false,
79
+ @data_origin="SUSR",
80
+ @dic=nil,
81
+ @district="Bratislava III",
82
+ @founded_at=2017-04-12 00:00:00 +0200,
83
+ @ico="50826042",
84
+ @id=1689373,
85
+ @legal_form="Spol. s r. o.",
86
+ @name="UOL SK s.r.o.",
87
+ @organization_size="nezistený",
88
+ @ownership_type="Zahraničné",
89
+ @postal_code="83106",
90
+ @region="Bratislavský kraj",
91
+ @residence="Bratislava-Rača",
92
+ @sk_nace_code="Účtovnícke činnosti",
93
+ @street="Karpatské námestie 10A",
94
+ @updated_at=2017-11-03 00:00:00 +0100>
95
+ ```
96
+
97
+ The `Registeruz::Subject` that is returned has method with english names, but
98
+ here you have SVK equivalents from official docs:
99
+
100
+ - `id` - identifikátor účtovnej jednotky, maximálne desaťciferné celé číslo
101
+ - `ico` - IČO účtovnej jednotky, osemznakový textový reťazec
102
+ - `dic` - DIČ účtovnej jednotky, desaťznakový textový reťazec
103
+ - `name` - názov účtovnej jednotky, textový reťazec s maximálnou dĺžkou 500 znakov
104
+ - `city` - adresa účtovnej jednotky, mesto, textový reťazec s maximálnou dĺžkou 200 znakov
105
+ - `street` - adresa účtovnej jednotky, ulica s číslom, textový reťazec s maximálnou dĺžkou 200 znakov
106
+ - `postal_code` - adresa účtovnej jednotky, PSČ, textový reťazec s maximálnou dĺžkou 10 znakov
107
+ - `founded_at` - dátum založenia účtovnej jednotky, formát RRRR-MM-DD
108
+ - `closed_at` - dátum zrušenia účtovnej jednotky, formát RRRR-MM-DD
109
+ - `legal_form` - kód právnej formy (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
110
+ - `sk_nace_code` - kód SK NACE klasifikácie (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
111
+ - `organization_size` - kód kategórie veľkosti organizácie (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
112
+ - `ownership_type` - kód druhu vlastníctva (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
113
+ - `region` - sídlo účtovnej jednotky, kód kraja (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
114
+ - `district` - sídlo účtovnej jednotky, kód okresu (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
115
+ - `residence` - sídlo účtovnej jednotky, kód obce alebo mesta (viď Číselníky), textový reťazec s maximálnou dĺžkou 100 znakov
116
+ - `consolidated` - boolean príznak - true, ak jednotka obsahuje aspoň jednu konsolidovanú účtovnú závierku
117
+ - `data_origin` - kód zdroja, z ktorého pochádzajú dáta (viď Zdroje dát), textový reťazec s maximálnou dĺžkou 30 znakov
118
+ - `updated_at` - dátum poslednej úpravy, formát RRRR-MM-DD
119
+
120
+ When there is `Číselník` mentioned it means you will not get ID representation
121
+ of the data but gem looks it up and gives you slovak word equivalent of the
122
+ ID....
123
+
124
+ Otherwise you can search yourself through codebooks like this:
125
+
126
+ ```ruby
127
+ Registeruz::Api::Codebook.find('sidla', '510262')
128
+
129
+ => "Liptovský Mikuláš"
130
+ ```
131
+
132
+ First param is name of the codebook, you can use one of these:
133
+
134
+ - `pravne-formy`
135
+ - `sk-nace`
136
+ - `druhy-vlastnictva`
137
+ - `velkosti-organizacie`
138
+ - `kraje`
139
+ - `okresy`
140
+ - `sidla`
141
+
142
+ if you do not pass second param, it will return the whole collection hash and
143
+ you can search for whatever you were looking for this way:
144
+
145
+ ```ruby
146
+ Registeruz::Api::Codebook.find('druhy-vlastnictva')
147
+
148
+ => [{"nazov"=>{"sk"=>"Zatiaľ nezistené", "en"=>"Not ascertained yet"},"kod"=>"0"},
149
+ {"nazov"=>{"sk"=>"Medzinárodné - verejné", "en"=>"Internatonial-public"},"kod"=>"1"},
150
+ {"nazov"=>{"sk"=>"Súkromné tuzemské", "en"=>"Private inland"}, "kod"=>"2"},
151
+ {"nazov"=>{"sk"=>"Družstevné", "en"=>"Cooperative-owned"}, "kod"=>"3"},
152
+ {"nazov"=>{"sk"=>"Štátne", "en"=>"State-owned"}, "kod"=>"4"},
153
+ {"nazov"=>{"sk"=>"Vlast.územnej samosprávy", "en"=>"Municipality-owned"},"kod"=>"5"},
154
+ {"nazov"=>{"sk"=>"Združ.,p.strany,cirkvi", "en"=>"Ownership of associat."}, "kod"=>"6"},
155
+ {"nazov"=>{"sk"=>"Zahraničné", "en"=>"Foreign"}, "kod"=>"7"},
156
+ {"nazov"=>{"sk"=>"Medzinárodné - súkromné", "en"=>"International-private"}, "kod"=>"8"},
157
+ {"nazov"=>{"sk"=>"Zmiešané", "en"=>"Mixed"}, "kod"=>"9"}]
158
+ ```
159
+
160
+ Enjoy!
161
+
162
+ ## Development
163
+
164
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
165
+
166
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
167
+
168
+ ## Contributing
169
+
170
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gem_template. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
171
+
172
+ ## License
173
+
174
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
175
+
176
+ ## Code of Conduct
177
+
178
+ Everyone interacting in the GemTemplate project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gem_template/blob/master/CODE_OF_CONDUCT.md).
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/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-architect
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'registeruz'
5
+
6
+ require 'pry'
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ module Registeruz
2
+ module Api
3
+ class Codebook
4
+ def initialize(codebook_name, code)
5
+ @codebook_name = codebook_name
6
+ @code = code
7
+ end
8
+
9
+ def self.find(codebook_name, code = nil)
10
+ new(codebook_name, code).find
11
+ end
12
+
13
+ # rubocop:disable Metrics/AbcSize
14
+ def find
15
+ response = Request.get(@codebook_name)
16
+ body = JSON.parse(response.body)
17
+ if @code
18
+ body[body.keys.first].select do |item|
19
+ item['kod'] == @code
20
+ end.first['nazov']['sk']
21
+ else
22
+ body[body.keys.first]
23
+ end
24
+ end
25
+ # rubocop:enable Metrics/AbcSize
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module Registeruz
2
+ module Api
3
+ class Find
4
+ def initialize(id)
5
+ @id = id
6
+ end
7
+
8
+ def self.find(id)
9
+ new(id).find
10
+ end
11
+
12
+ def find
13
+ response = Request.get('uctovna-jednotka', id: @id)
14
+ body = JSON.parse(response.body)
15
+ ::Registeruz::Models::Subject.new(body)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ module Registeruz
2
+ module Api
3
+ class Request
4
+ def initialize(endpoint, params)
5
+ @endpoint = endpoint
6
+ @params = params
7
+ end
8
+
9
+ def self.get(endpoint, params = {})
10
+ new(endpoint, params).get
11
+ end
12
+
13
+ def get
14
+ net_http_get
15
+ end
16
+
17
+ protected
18
+
19
+ def net_http_get
20
+ uri = URI("#{Registeruz.base_url}#{@endpoint}")
21
+ uri.query = URI.encode_www_form(@params)
22
+
23
+ request = Net::HTTP::Get.new(uri)
24
+ headers.each { |k, v| request[k] = v }
25
+
26
+ Net::HTTP.start(uri.hostname, uri.port,
27
+ use_ssl: (uri.scheme == 'https')) do |http|
28
+ http.request(request)
29
+ end
30
+ end
31
+
32
+ def headers
33
+ {
34
+ 'Accept-Encoding' => 'application/json',
35
+ 'Content-Type' => 'application/json'
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ module Registeruz
2
+ module Api
3
+ class Where
4
+ def initialize(params)
5
+ @params = params.merge('zmenene-od': '1993-01-01')
6
+ end
7
+
8
+ def self.where(params)
9
+ new(params).where
10
+ end
11
+
12
+ def where
13
+ response = Request.get('uctovne-jednotky', @params)
14
+ body = JSON.parse(response.body)
15
+ ::Registeruz::Models::Collection.new(body)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module Registeruz
2
+ class Error < StandardError; end
3
+
4
+ class NotFound < Error
5
+ def initialize
6
+ msg = 'Could not find what you are looking for'
7
+ super(msg)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ module Registeruz
2
+ module Models
3
+ class Collection
4
+ attr_accessor :items
5
+
6
+ def initialize(body)
7
+ raise NotFound unless body['id']&.any?
8
+ @ids = body['id']
9
+ load_all_subjects
10
+ end
11
+
12
+ private
13
+
14
+ def load_all_subjects
15
+ @items = @ids.map do |id|
16
+ ::Registeruz::Api::Find.find(id)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ module Registeruz
2
+ module Models
3
+ class Subject
4
+ attr_accessor :id, :name, :city, :street, :postal_code, :founded_at,
5
+ :closed_at, :legal_form, :organization_size, :ownership_type,
6
+ :region, :district, :residence, :data_origin, :updated_at,
7
+ :ico, :dic, :sk_nace_code, :consolidated
8
+
9
+ # rubocop:disable Metrics/AbcSize
10
+ # rubocop:disable Metrics/MethodLength
11
+ def initialize(body)
12
+ @id = body['id']
13
+ @name = body['nazovUJ']
14
+ @city = body['mesto']
15
+ @street = body['ulica']
16
+ @postal_code = body['psc']
17
+ @founded_at = Time.parse body['datumZalozenia']
18
+ @closed_at = Time.parse body['datumZrusenia'] if body['datumZrusenia']
19
+ @legal_form = ::Registeruz::Api::Codebook
20
+ .find('pravne-formy', body['pravnaForma'])
21
+ @organization_size = ::Registeruz::Api::Codebook
22
+ .find('velkosti-organizacie', body['velkostOrganizacie'])
23
+ @ownership_type = ::Registeruz::Api::Codebook
24
+ .find('druhy-vlastnictva', body['druhVlastnictva'])
25
+ @region = ::Registeruz::Api::Codebook.find('kraje', body['kraj'])
26
+ @district = ::Registeruz::Api::Codebook.find('okresy', body['okres'])
27
+ @residence = ::Registeruz::Api::Codebook.find('sidla', body['sidlo'])
28
+ @data_origin = body['zdrojDat']
29
+ @updated_at = Time.parse body['datumPoslednejUpravy']
30
+ @ico = body['ico']
31
+ @dic = body['dic']
32
+ @sk_nace_code = ::Registeruz::Api::Codebook.find('sk-nace', body['skNace'])
33
+ @consolidated = body['konsolidovana']
34
+ end
35
+ # rubocop:enable Metrics/MethodLength
36
+ # rubocop:enable Metrics/AbcSize
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ module Registeruz
2
+ class Subject
3
+ class << self
4
+ def where(options)
5
+ ::Registeruz::Api::Where.where(options).items
6
+ end
7
+
8
+ def find_by(options)
9
+ where(options).first
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Registeruz
2
+ VERSION = '1.0.0'.freeze
3
+ end
data/lib/registeruz.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'time'
4
+
5
+ require 'registeruz/version'
6
+ require 'registeruz/subject'
7
+ require 'registeruz/errors'
8
+
9
+ require 'registeruz/api/request'
10
+ require 'registeruz/api/where'
11
+ require 'registeruz/api/find'
12
+ require 'registeruz/api/codebook'
13
+
14
+ require 'registeruz/models/collection'
15
+ require 'registeruz/models/subject'
16
+
17
+ module Registeruz
18
+ class << self
19
+ def base_url
20
+ 'http://www.registeruz.sk/cruz-public/api/'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'registeruz/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'registeruz'
7
+ spec.version = Registeruz::VERSION
8
+ spec.authors = ['Andrej Antas']
9
+ spec.email = ['andrej@antas.cz']
10
+
11
+ spec.summary = 'Ruby wrapper pre verejne API registeruz.sk'
12
+ spec.description = 'Prehladavanie Slopvenskych subjektov podla ICO a vratenie subjektu s adresou atd.'
13
+ spec.homepage = 'https://github.com/redrick/registeruz'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
33
+ spec.add_development_dependency 'overcommit', '~> 0.40'
34
+ spec.add_development_dependency 'pry', '~> 0.10'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rubocop', '~> 0.49'
38
+ spec.add_development_dependency 'simplecov', '~> 0.14'
39
+ spec.add_development_dependency 'vcr', '~> 3.0'
40
+ spec.add_development_dependency 'webmock', '~> 3.0'
41
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: registeruz
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrej Antas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: overcommit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.40'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.40'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.49'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.49'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description: Prehladavanie Slopvenskych subjektov podla ICO a vratenie subjektu s
140
+ adresou atd.
141
+ email:
142
+ - andrej@antas.cz
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".ruby-gemset"
151
+ - ".ruby-version"
152
+ - ".travis.yml"
153
+ - CODE_OF_CONDUCT.md
154
+ - Gemfile
155
+ - Gemfile.lock
156
+ - LICENSE.txt
157
+ - README.md
158
+ - Rakefile
159
+ - _config.yml
160
+ - bin/console
161
+ - bin/setup
162
+ - lib/registeruz.rb
163
+ - lib/registeruz/api/codebook.rb
164
+ - lib/registeruz/api/find.rb
165
+ - lib/registeruz/api/request.rb
166
+ - lib/registeruz/api/where.rb
167
+ - lib/registeruz/errors.rb
168
+ - lib/registeruz/models/collection.rb
169
+ - lib/registeruz/models/subject.rb
170
+ - lib/registeruz/subject.rb
171
+ - lib/registeruz/version.rb
172
+ - registeruz.gemspec
173
+ homepage: https://github.com/redrick/registeruz
174
+ licenses:
175
+ - MIT
176
+ metadata:
177
+ allowed_push_host: https://rubygems.org/
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.14
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Ruby wrapper pre verejne API registeruz.sk
198
+ test_files: []