Class: SRCEITools::ValidateDI

Inherits:
Object
  • Object
show all
Defined in:
lib/srcei-tools/validate_di.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc_run, doc_type, doc_number) ⇒ ValidateDI

Returns a new instance of ValidateDI.



15
16
17
18
19
# 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

Instance Attribute Details

#doc_run=(value) ⇒ Object (writeonly)

Sets the attribute doc_run

Parameters:

  • value

    the value to set the attribute doc_run to.



6
7
8
# File 'lib/srcei-tools/validate_di.rb', line 6

def doc_run=(value)
  @doc_run = value
end

#doc_type=(doc_type) ⇒ Object (writeonly)

Sets the attribute doc_type

Parameters:

  • value

    the value to set the attribute doc_type to.



5
6
7
# File 'lib/srcei-tools/validate_di.rb', line 5

def doc_type=(value)
  @doc_type = value
end

Class Method Details

.valid?(doc_run, doc_type, doc_number) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# 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

Instance Method Details

#check_documentObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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