Sha256: 4a32841190b86a7e79c9273c0383e1b178e9e610019c493d52f92081d18f185b

Contents?: true

Size: 1.26 KB

Versions: 34

Compression:

Stored size: 1.26 KB

Contents

module EgovUtils
  class AddressesController < ApplicationController

    def validate_ruian
      require 'egon_gate/egsb/messages/e37_vyhledej_adresu'

      # TODO: shoud be in some validator - external class
      addr_params = params.require(:address).permit(:city, :postcode, :street, :orientation_number, :house_number)
      address = Address.new(addr_params)
      if (address.city || address.postcode) && (( address.street && address.orientation_number ) || address.house_number)
        message = EgonGate::Egsb::Messages::E37VyhledejAdresu.new
        address.prepare_egon_message(message)
        kobra_reqest = EgonGate::Kobra::Request.new
        response = kobra_reqest.send_message(message)
        if response.error?
          respond_to do |format|
            format.json { render json: { error: response.error_message }, status: 404 }
          end
        else
          egon_address_info = message.parse_response( response.egsb_response )
          address.from_egon_info(egon_address_info)
          respond_to do |format|
            format.json { render json: address }
          end
        end
      else
        respond_to do |format|
          format.json { render json: { error: t(:error_not_found) }, status: 404 }
        end
      end
    end

  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
egov_utils-0.2.9 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.8 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.7 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.6 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.5 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.4 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.3 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.2 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.1 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.2.0 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.37 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.36 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.35 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.33 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.32 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.31 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.30 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.29 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.28 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.1.27 app/controllers/egov_utils/addresses_controller.rb