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-0.6.5 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.6.4 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.6.3 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.6.2 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.6.1 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.6.0 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.5.2 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.5.1 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.5.0 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.18 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.17 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.16 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.15 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.14 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.13 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.10 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.9 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.7 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.6 app/controllers/egov_utils/addresses_controller.rb
egov_utils-0.4.5 app/controllers/egov_utils/addresses_controller.rb