class SRCEITools::ValidateDI

Attributes

doc_run[W]
doc_type[W]

Public Class Methods

new(doc_run, doc_type, doc_number) click to toggle source
# File lib/srcei-tools/validate_di.rb, line 15
def initialize(doc_run, doc_type, doc_number)
  self.doc_run = doc_run
  self.doc_type = doc_type
  @doc_number = doc_number
end
valid?(doc_run, doc_type, doc_number) click to toggle source
# File lib/srcei-tools/validate_di.rb, line 21
def self.valid?(doc_run, doc_type, doc_number)
  new( doc_run, doc_type, doc_number ).check_document
end

Public Instance Methods

check_document() click to toggle source
# File lib/srcei-tools/validate_di.rb, line 25
def check_document
  # URL SRCEI to validate document
  url = 'https://portal.sidiv.registrocivil.cl/usuarios-portal/pages/DocumentRequestStatus.xhtml'

  # Set Agent to navigate web
  a = Mechanize.new do |agent|
    agent.user_agent_alias = 'Mac Safari'
    agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  begin
    a.get(url) do |page|

      form = page.form_with(:id => 'form') do |f|
        f['form:run'] = @doc_run
        f['form:selectDocType'] = @doc_type
        f['form:docNumber'] = @doc_number
      end.click_button

      doc = form.parser
      # Get value (Vigente | No Vigente | Empty)
      status = doc.at('tr [@class="setWidthOfSecondColumn"]').text

      if( status == 'Vigente' )
        return true
      else
        return false
      end
    end
  rescue Mechanize::ResponseCodeError => e
    return false
  end
end