diff --git a/.gitignore b/.gitignore index 4ea5798..ce1433e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /spec/reports/ /tmp/ Gemfile.lock +.DS_Store diff --git a/bin/console b/bin/console old mode 100644 new mode 100755 diff --git a/bin/setup b/bin/setup old mode 100644 new mode 100755 diff --git a/company_register.gemspec b/company_register.gemspec index 57b5255..19205d8 100644 --- a/company_register.gemspec +++ b/company_register.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |spec| spec.name = 'company_register' spec.version = CompanyRegister::VERSION spec.authors = ['Artur Beljajev', 'Maciej Szlosarczyk'] - spec.email = ['artur.beljajev@internet.ee', 'maciej.szlosarczyk@eestiinternet.ee'] + spec.email = ['artur.beljajev@internet.ee', 'maciej.szlosarczyk@eestiinternet.ee', 'oleg.hasjanov@eestiinternet.ee'] spec.summary = 'A Ruby interface to the Estonian company register (Äriregister) API' spec.homepage = 'https://github.com/internetee/company_register' spec.license = 'MIT' diff --git a/lib/company_register.rb b/lib/company_register.rb index 34982ba..4c723c2 100644 --- a/lib/company_register.rb +++ b/lib/company_register.rb @@ -6,6 +6,9 @@ require 'company_register/configuration' require 'company_register/request' require 'company_register/request/representation_rights' +require 'company_register/request/simple_data' +require 'company_register/request/company_details' +require 'company_register/request/entries_and_rulings' module CompanyRegister class Error < StandardError; end diff --git a/lib/company_register/client.rb b/lib/company_register/client.rb index a844992..50f86fb 100644 --- a/lib/company_register/client.rb +++ b/lib/company_register/client.rb @@ -1,5 +1,12 @@ module CompanyRegister - Company = Struct.new(:registration_number, :company_name) + Company = Struct.new(:registration_number, :company_name, :status) + + CompanyDetails = Struct.new( + :registration_number, + :company_name, + :status, + :kandeliik, + ) class Client # API returns request params back with the response. They are stripped out to avoid caching @@ -18,24 +25,73 @@ def representation_rights(citizen_personal_code:, citizen_country_code:) keel: 'eng' } request = Request::RepresentationRightsRequest.new(search_params) - response_body = cache_store.fetch(request, - expires_in: CompanyRegister.configuration.cache_period) do + response_body = cache_store.fetch(request, expires_in: CompanyRegister.configuration.cache_period) do response = request.perform - filter_response_body(response.body) + filter_response_body(response.body, :esindus_v1_response) end parse_representation_rights_response_body(response_body) end + def simple_data(registration_number:) + search_params = { ariregistri_kood: registration_number, keel: 'eng' } + + request = Request::SimpleDataRequest.new(search_params) + response = request.perform + response_body = filter_response_body(response.body, :lihtandmed_v2_response) + + parse_simple_data_response_body(response_body) + end + + # yandmed - If General Data is requested + # iandmed - If Personnel Data is requested + # kandmed - If Commercial Pledga data is requested + # dandmed - If data of applications in proceeding is requested + # maarused - If rulings are required + def company_details(registration_number:, is_general_data: 1, is_personnel_data: 1, is_commercial_pledga: 0, is_data_proceed: 0, is_ruling: 0) + search_params = { + ariregistri_kood: registration_number, + yandmed: is_general_data, + iandmed: is_personnel_data, + kandmed: is_commercial_pledga, + dandmed: is_data_proceed, + maarused: is_ruling + } + + request = Request::CompanyDetailsRequest.new(search_params) + response = request.perform + response_body = filter_response_body(response.body, :detailandmed_v2_response) + + parse_company_details_response_body(response_body) + end + + # liik: K – request for entries; M – request for rulings. + # algus_kpv: The input already takes into account summer and winter time. The maximum search period is one day. The date must not be less than 01.01.2013 + # lopp_kpv: The input already takes into account summer and winter time. The maximum search period is one day. The date must not be less than the start date. + def entries_and_rulings(request_type: 'M', start_at: '2019-01-18T11:57:00', ends_at: '2019-01-19T11:57:00', lang: 'eng') + search_params = { + keel: lang, + liik: request_type, + algus_kpv: start_at, + lopp_kpv: ends_at + } + + request = Request::EntriesAndRulingsRequest.new(search_params) + response = request.perform + response_body = filter_response_body(response.body, :kanded_maarused_v1_response) + + parse_entries_and_rulings_response_body(response_body) + end + private attr_reader :cache_store - def filter_response_body(body) + def filter_response_body(body, response_type) # Avoid parameter mutation body = Marshal.load(Marshal.dump(body)) - body[:esindus_v1_response][:paring].delete_if do |key, _value| + body[response_type][:paring].delete_if do |key, _value| RESPONSE_FILTERED_PARAMS.include?(key) end @@ -51,5 +107,89 @@ def parse_representation_rights_response_body(body) Company.new(item[:ariregistri_kood], item[:arinimi]) end end + + def parse_simple_data_response_body(body) + return [] unless body[:lihtandmed_v2_response][:keha][:ettevotjad] + + items = body[:lihtandmed_v2_response][:keha][:ettevotjad][:item] + items = [items] unless items.kind_of?(Array) + items.map do |item| + Company.new(item[:ariregistri_kood], item[:evnimi], item[:staatus]) + end + end + + def parse_company_details_response_body(body) + return [] unless body[:detailandmed_v2_response][:keha][:ettevotjad] + + items = body[:detailandmed_v2_response][:keha][:ettevotjad][:item] + items = [items] unless items.kind_of?(Array) + items.map do |item| + kandeliik = nil + + kandeliik = if item[:registrikaardid][:item].kind_of?(Array) + return_list_of_registry_cards(item) + else + return_list_of_kanded_items(item) + end + + CompanyDetails.new( + item[:ariregistri_kood], item[:nimi], item[:yldandmed][:staatus], kandeliik + ) + end + end + + def return_list_of_registry_cards(item) + item[:registrikaardid][:item].map do |i| + i[:kanded][:item].map do |entry| + Struct.new(:kandeliik, :kandeliik_tekstina, :kande_kpv) + .new(entry[:kandeliik], entry[:kandeliik_tekstina], entry[:kande_kpv]) + end + end + end + + def return_list_of_kanded_items(item) + if item[:registrikaardid][:item][:kanded][:item].kind_of?(Array) + + item[:registrikaardid][:item][:kanded].map do |reg_pair| + reg_pair[1].map do |reg| + + Struct.new(:kandeliik, :kandeliik_tekstina, :kande_kpv) + .new(reg[:kandeliik], reg[:kandeliik_tekstina], reg[:kande_kpv]) + end + end + + else + Struct.new(:kandeliik, :kandeliik_tekstina, :kande_kpv) + .new( + item[:registrikaardid][:item][:kanded][:item][:kandeliik], + item[:registrikaardid][:item][:kanded][:item][:kandeliik_tekstina], + item[:registrikaardid][:item][:kanded][:item][:kande_kpv] + ) + end + end + + def parse_entries_and_rulings_response_body(body) + return [] unless body[:kanded_maarused_v1_response][:keha][:ettevotjad] + + items = body[:kanded_maarused_v1_response][:keha][:ettevotjad][:item] + items = [items] unless items.kind_of?(Array) + items.map do |item| + maarused = unless item[:maarused][:item][0].nil? + Struct.new(:kandeliik, :kandeliik_tekstina, :maaruse_liik, :maaruse_liik_tekstina) + .new( + item[:maarused][:item][0][:kandeliik], + item[:maarused][:item][0][:kandeliik_tekstina], + item[:maarused][:item][0][:maaruse_liik], + item[:maarused][:item][0][:maaruse_liik_tekstina] + ) + else + [] + end + + CompanyDetails.new( + item[:ariregistri_kood], item[:evnimi], item[:staatus], maarused + ) + end + end end -end \ No newline at end of file +end diff --git a/lib/company_register/request/company_details.rb b/lib/company_register/request/company_details.rb new file mode 100644 index 0000000..3946cc0 --- /dev/null +++ b/lib/company_register/request/company_details.rb @@ -0,0 +1,11 @@ +module CompanyRegister + class Request + class CompanyDetailsRequest < Request + private + + def soap_operation + :detailandmed_v2 + end + end + end +end \ No newline at end of file diff --git a/lib/company_register/request/entries_and_rulings.rb b/lib/company_register/request/entries_and_rulings.rb new file mode 100644 index 0000000..695ecb1 --- /dev/null +++ b/lib/company_register/request/entries_and_rulings.rb @@ -0,0 +1,11 @@ +module CompanyRegister + class Request + class EntriesAndRulingsRequest < Request + private + + def soap_operation + :kanded_maarused_v1 + end + end + end +end \ No newline at end of file diff --git a/lib/company_register/request/simple_data.rb b/lib/company_register/request/simple_data.rb new file mode 100644 index 0000000..03dd17f --- /dev/null +++ b/lib/company_register/request/simple_data.rb @@ -0,0 +1,11 @@ +module CompanyRegister + class Request + class SimpleDataRequest < Request + private + + def soap_operation + :lihtandmed_v2 + end + end + end +end \ No newline at end of file diff --git a/test/client_test.rb b/test/client_test.rb index eb84614..94f5a52 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -131,6 +131,15 @@ def stub_request_with_payload headers: { 'Soapaction' => '"esindus_v1"' }).to_return(status: 200, body: response_body) end + # TODO: + # def stub_request_with_payload_of_company_details + # response_body = File.read('test/fixtures/deleted_company.xml') + # stub_request(:post, 'https://ariregxmlv6.rik.ee/'). + # with( + # body: "johnpwd1234USAeng", + # headers: { 'Soapaction' => '"esindus_v1"' }).to_return(status: 200, body: response_body) + # end + def stub_request_without_payload response_body = File.read('test/fixtures/representation_rights_response_without_payload.xml') stub_request(:post, 'https://ariregxmlv6.rik.ee/').to_return(status: 200, diff --git a/test/fixtures/deleted_company.xml b/test/fixtures/deleted_company.xml new file mode 100644 index 0000000..1ded5c4 --- /dev/null +++ b/test/fixtures/deleted_company.xml @@ -0,0 +1,899 @@ + + + + + + timovohmar + eritivingeparool + 12226399 + true + true + false + false + false + + + + + 12226399 + 3000042387 + OÜ Biohaldjas + + 2012-01-26Z + 2024-01-10Z + K + Kustutatud + 5 + Tartu + Tartu Maakohtu registriosakond + + + false + + 5 + Osaühing + + + + 1 + 1 + R + 1 + R + Registrisse kantud + 2012-01-26Z + 2024-01-10Z + + + 5 + 2 + R + 7 + K + Kustutatud + 2024-01-10Z + + + + + 4469344 + 1 + 2 + R + 1 + Blaufont OÜ + 2012-05-03Z + 2012-05-08Z + + + 4473768 + 1 + 2 + R + 2 + OÜ Biohaldjas + 2012-05-08Z + 2024-01-10Z + + + 4370423 + 1 + 1 + R + 1 + Blaufont UÜ + 2012-01-26Z + 2012-05-03Z + + + + + + 4370425 + 1 + 1 + R + 1 + 0784 + Tallinna linn, Harju maakond + Rännaku pst 12 + 10917 + 2012-01-26Z + 2012-05-03Z + + + 4469347 + 1 + 2 + R + 1 + 0784 + Tallinna linn, Harju maakond + Rännaku pst 12 + 10917 + 2012-05-03Z + 2012-05-08Z + + + 4473769 + 1 + 2 + R + 2 + 3039 + Kiili alev, Kiili vald, Harju maakond + Allika 12 + 75401 + 2012-05-08Z + 2017-12-02Z + + + 7233539 + 5 + 2 + R + 3 + 3039 + Kiili alev, Kiili vald, Harju maakond + Allika tn 12 + EE01838469 + 3466685 + Harju maakond, Kiili vald, Kiili alev, Allika tn 12 + 10274348 + 37305303900000L7900006IWB00000000 + 75401 + 2017-12-02Z + 2024-01-10Z + + + + + + + + + 4370424 + 1 + 1 + R + 1 + + 4 + Usaldusühing + 2012-01-26Z + 2012-05-03Z + + + 4469345 + 1 + 2 + R + 1 + + 5 + Osaühing + 2012-05-03Z + 2024-01-10Z + + + + + + 4469346 + 1 + 2 + R + 1 + 2508.0 + EUR + euro + 2012-05-03Z + 2024-01-10Z + + + + + + 4469350 + 1 + 2 + R + 1 + YMB + Ümberkujundamine tekstina + Blaufont UÜ on 26.01.2012. otsuse alusel ümber kujundatud osaühinguks ärinimega Blaufont OÜ. + 2012-05-03Z + 2024-01-10Z + + + + + 12234751 + 5 + 2 + R + 7 + KUST + Registrist kustutamine tekstina + Osaühing on kustutatud ÄRS § 61 lg 2 alusel. + 2024-01-10Z + + + + + 4469348 + 1 + 2 + R + 1 + 01.01 + 31.12 + 2012-05-03Z + 2024-01-10Z + + + 4370426 + 1 + 1 + R + 1 + 01.01 + 31.12 + 2012-01-26Z + 2012-05-03Z + + + + + 4469349 + 1 + 2 + R + 1 + 2012-01-26Z + false + 2012-05-03Z + 2012-05-08Z + + + 4473770 + 1 + 2 + R + 2 + 2012-05-07Z + false + 2012-05-08Z + 2024-01-10Z + + + + + + + + + + 4469359 + 1 + 1 + R + 2 + 6 + MARK + Märkus + Usaldusühing ümberkujundatud ja registrikaart suletud 03.05.2012 + 2012-05-03Z + 2012-05-03Z + + + 10904268 + 5 + 2 + R + 5 + 6 + MARK + Märkus + Kanne on tehtud äriregistri seaduse § 70 lõike 1 alusel. + 2023-09-01Z + 2024-01-10Z + + + + + + + 3000237943 + WWW + Interneti WWW aadress + www.wasp.ee + 2012-05-07Z + + + 3000237942 + EMAIL + Elektronposti aadress + info@wasp.ee + 2012-05-07Z + + + 7720673 + EMAIL + Elektronposti aadress + priit.mannamae@gmail.com + 2024-01-10Z + 5 + 2 + R + 4 + + + 9000175303 + MOB + Mobiiltelefon + +372 58530664 + 2024-01-10Z + + + 3000258732 + MOB + Mobiiltelefon + +372 56239718 + 2014-01-18Z + + + 3000258733 + EMAIL + Elektronposti aadress + priit.mannamae@gmail.com + 2018-01-17Z + + + + + 9000726164 + 4791 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + true + 2023-10-27Z + 2024-01-10Z + + + 9000095183 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + true + 2014-01-18Z + 2023-10-27Z + + + 3000164225 + 82991 + Muud mujal liigitamata äritegevust abistavad tegevused + 2 + EMTAK 2008 + 82.99 + true + 2012-01-26Z + 2014-01-18Z + + + + + 3005744 + 2021-01-01Z + 2021-12-31Z + 0 + Allika tn 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 4791 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 2487343 + 2020-01-01Z + 2020-12-31Z + 0 + Allika tn 12, Kiili alev, Kiili vald, Harju maakond, 75401 + + + 2487337 + 2019-01-01Z + 2019-12-31Z + 0 + Allika tn 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 2486957 + 2018-01-01Z + 2018-12-31Z + 0 + Allika tn 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 2270014 + 2017-01-01Z + 2017-12-31Z + 0 + Allika tn 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 1666675 + 2016-01-01Z + 2016-12-31Z + 0 + Allika 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 1373098 + 2015-01-01Z + 2015-12-31Z + 0 + Allika 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 1373095 + 2014-01-01Z + 2014-12-31Z + 0 + Allika 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 1373084 + 2013-01-01Z + 2013-12-31Z + 0 + Allika 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + 1080815 + 2012-01-26Z + 2012-12-31Z + 0 + Allika 12, Kiili alev, Kiili vald, Harju maakond, 75401 + 47911 + Jaemüük posti või Interneti teel + 2 + EMTAK 2008 + 47.91 + + + false + + + + + 4473772 + 1 + 2 + R + 2 + F + JUHL + Juhatuse liige + EEVA + MÄNNAMÄE + 47806110281 + + 2012-05-08Z + 2023-10-27Z + + + 12110539 + 5 + 2 + R + 6 + F + JUHL + Juhatuse liige + Eeva + Pahkla + 47806110281 + + 2023-10-27Z + 2024-01-10Z + + + 4469351 + 1 + 2 + R + 1 + F + JUHL + Juhatuse liige + Hannes + Rosin + 37902090356 + + 2012-05-03Z + 2012-05-08Z + + + 4469352 + 1 + 2 + R + 1 + F + JUHL + Juhatuse liige + Ott + Männiste + 37905050234 + + 2012-05-03Z + 2012-05-08Z + + + 4473771 + 1 + 2 + R + 2 + F + JUHL + Juhatuse liige + PRIIT + MÄNNAMÄE + 37601200226 + + 2012-05-08Z + 2024-01-10Z + + + 4370428 + 1 + 1 + R + 1 + J + TOSAN + Täisosanik + Osaühing Since 2009 + 11587126 + + 2012-01-26Z + 2012-05-03Z + + + 4370427 + 1 + 1 + R + 1 + J + UOSAN + Usaldusosanik + Wasp Consult OÜ + 12067392 + 2508.000000 + EUR + euro + + 2012-01-26Z + 2012-05-03Z + + + + + + + 47998 + K + F + 37601200226 + Männamäe + Priit + 2508.000000 + Täiteasi 022/2018/6510, Harju tööpiirkonna kohtutäitur +Elin Vilippus + 2018-10-29Z + 2019-04-18Z + + + + 52094 + K + F + 37601200226 + Männamäe + Priit + 2508.000000 + Täiteasi 022/2019/27 ja Täiteasi 022/2019/6263, Harju tööpiirkonna kohtutäitur +Elin Vilippus + 2019-09-30Z + 2023-09-01Z + + + + 56325 + K + F + 47806110281 + Männamäe + Eeva + 2508.000000 + Täiteasi 022/2020/6386. Tallinna kohtutäitur Elin Vilippus + 2020-08-12Z + 2020-10-30Z + + + + 10904267 + KM + OSAN + 47806110281 + Pahkla + Eeva + 2508.000000 + Täiteasi 022/2019/27 ja Täiteasi 022/2019/6263, Harju tööpiirkonna kohtutäitur +Elin Vilippus + 2023-09-01Z + 2024-01-10Z + + + + + + 10904265 + F + OSAN + Osanik + Eeva + Männamäe + 47806110281 + + 100.000000 + 2508.000000 + EUR + euro + Y + Ühisomand + 2023-09-01Z + 2023-10-27Z + 35304 + + + 10904266 + F + OSAN + Osanik + Priit + Männamäe + 37601200226 + + 100.000000 + 2508.000000 + EUR + euro + Y + Ühisomand + 2023-09-01Z + 2024-01-10Z + 35304 + + + 12110554 + F + OSAN + Osanik + Eeva + Pahkla + 47806110281 + + 100.000000 + 2508.000000 + EUR + euro + Y + Ühisomand + 2023-10-27Z + 2024-01-10Z + 35304 + + + 3000254586 + J + O + Osanik + Wasp Consult OÜ + 12067392 + + 100.000000 + 2508.000000 + EUR + euro + L + Ainuomand + R + Registripäevik + 2012-05-03Z + 2012-05-03Z + 2012-05-07Z + + + 3000255573 + F + O + Osanik + Eeva + Männamäe + 47806110281 + EST + Eesti + + 100060 + Harju maakond, Kiili vald + 373040000000000000000000000000000 + 100.000000 + 2508.000000 + EUR + euro + Y + Ühisomand + R + Registripäevik + 2012-05-08Z + 2012-05-07Z + 2023-09-01Z + 2 + + + 3000255574 + F + O + Osanik + Priit + Männamäe + 37601200226 + EST + Eesti + + 100060 + Harju maakond, Kiili vald + 373040000000000000000000000000000 + 100.000000 + 2508.000000 + EUR + euro + Y + Ühisomand + R + Registripäevik + 2012-05-08Z + 2012-05-07Z + 2023-09-01Z + 2 + + + + + + + 5 + 1 + R + + + 1 + 2012-01-26Z + 2 + Esmakanne + + + 2 + 2012-05-03Z + 45 + Ümberkujundatud äriühingu senise registrikaardi sulgemise märkus + + + + + 5 + 2 + R + + + 1 + 2012-05-03Z + 34 + Ümberkujundamiskanne + + + 2 + 2012-05-08Z + 12 + Muutmiskanne + + + 3 + 2017-12-02Z + 12 + Muutmiskanne + + + 4 + 2018-01-17Z + 12 + Muutmiskanne + + + 5 + 2023-09-01Z + 12 + Muutmiskanne + + + 6 + 2023-10-27Z + 12 + Muutmiskanne + + + 7 + 2024-01-10Z + 19 + Kustutamiskanne dokumentide hoidjata + + + + + + + 1 + + + +