Sha256: c967be32c77fa477cbcae463e0787087e3f431b641011c14d8d50c8737be1534

Contents?: true

Size: 1.28 KB

Versions: 80

Compression:

Stored size: 1.28 KB

Contents

module EgovUtils
  class AddressesController < ApplicationController

    def validate_ruian
      require 'egon_gate'
      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

80 entries across 80 versions & 1 rubygems

Version Path
egov_utils-1.5.0.alpha16 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha15 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha14 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha13 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha12 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha11 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha10 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha9 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha8 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha7 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha6 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha5 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha4 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.4.5 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.4.4 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha3 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha2 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.5.0.alpha1 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.4.3 app/controllers/egov_utils/addresses_controller.rb
egov_utils-1.4.2 app/controllers/egov_utils/addresses_controller.rb