Sha256: 6dc181368458633f061b6555c19b9aa08408da344493e3faf33cbe0f9b6c7e35

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

module EgovUtils
  module Iszr
    module LegalPeople
      class ProdSearch < ActiveInteraction::Base
        string :ico

        validates :ico, presence: true

        MAPPING_CLASS = EgovUtils::Services::Iszr::LegalPeople

        def execute
          find_person
        end

        private

        def request
          result = EgovUtils::Iszr::LegalPeople::CreateRequest.run(ico:)
          # make some call to API with result
        end

        def find_person
          # Request will contain provided ICO on which the response will be based

          response = File.read(sample_results)

          body = Nokogiri::XML(response)

          person = MAPPING_CLASS.new(
            ico: body.at('//dot:Ico').text,
            name: body.at('//dot:NazevOsoby').text,
            remote_id: body.at('//ros:Aifo').text
          )
          if person.nil?
            errors.add(:base, I18n.t('errors.messages.legal_person.not_found'))
          else
            person
          end
        end

        def sample_results
          'lib/egov_utils/iszr/e20_ico_response.xml'
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
egov_utils-1.5.0.alpha16 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha15 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha14 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha13 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha12 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha11 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha10 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha9 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha8 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha7 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha6 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha5 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha4 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha3 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha2 app/services/egov_utils/iszr/legal_people/prod_search.rb
egov_utils-1.5.0.alpha1 app/services/egov_utils/iszr/legal_people/prod_search.rb