srcei-tools 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18d60074ed01a9bf7122ba5eb8950c6a6450e7c1
4
+ data.tar.gz: 260e5f52613c7eb1f4c2c7cb96662be915b0696c
5
+ SHA512:
6
+ metadata.gz: b8b363eed7255ca3cb8c8362ccf0965031f9b662e1755b51941c039b48fe1d5b48ba34504437fada1a335aaa1f177069f5a6c0b60d0be0e16fe5317c4b8b9e41
7
+ data.tar.gz: 4340533ba6335ed314226a0a894f880db00b3698440df66620851821e55f2f3b006232fee7985e738b3efc4e30d7405b2e236cec8279e6614abf5656f6d5470b
@@ -0,0 +1,31 @@
1
+ # srcei-tools
2
+
3
+ srcei-tools is a Ruby library for validating Serial Number Chilean Document. [You can check in](https://portal.sidiv.registrocivil.cl/usuarios-portal/pages/DocumentRequestStatus.xhtml) on Registro Civil
4
+
5
+ ## INSTALLATION
6
+
7
+ gem install srcei-tools
8
+
9
+ The gem should be compatible with most Ruby versions.
10
+
11
+ ## USAGE
12
+ ```ruby
13
+ require 'srcei-tools'
14
+ # the parameters are RUT, Document Type and Serial Number
15
+ SRCEITools::ValidateDI.valid?("55555555-5", "CEDULA", "103500XXX")
16
+ => true
17
+ ```
18
+
19
+ In Document Type Parameters you can use
20
+
21
+ * CEDULA
22
+ * CEDULA_EXT
23
+ * PASAPORTE_PG
24
+ * PASAPORTE_DIPLOMATICO
25
+ * PASAPORTE_OFICIAL
26
+
27
+ ----------------------------------------
28
+
29
+ ## License
30
+
31
+ This library is distributed under the MIT license. Please see the [LICENSE](https://github.com/xalupeao/srcei-tools/blob/master/LICENSE) file.
@@ -0,0 +1,2 @@
1
+ require 'mechanize'
2
+ require 'srcei-tools/validate_di.rb'
@@ -0,0 +1,60 @@
1
+ require 'mechanize'
2
+
3
+ module SRCEITools
4
+ class ValidateDI
5
+ attr_writer :doc_type
6
+ attr_writer :doc_run
7
+
8
+ def doc_type=(doc_type)
9
+ # Valid options in select document
10
+ valid = ['CEDULA', 'CEDULA_EXT', 'PASAPORTE_PG', 'PASAPORTE_DIPLOMATICO', 'PASAPORTE_OFICIAL']
11
+ # if not valid option set default CEDULA
12
+ @doc_type = (valid).include?(@doc_type) ? @doc_type : 'CEDULA'
13
+ end
14
+
15
+ def initialize(doc_run, doc_type, doc_number)
16
+ self.doc_run = doc_run
17
+ self.doc_type = doc_type
18
+ @doc_number = doc_number
19
+ end
20
+
21
+ def self.valid?(doc_run, doc_type, doc_number)
22
+ new( doc_run, doc_type, doc_number ).check_document
23
+ end
24
+
25
+ def check_document
26
+ # URL SRCEI to validate document
27
+ url = 'https://portal.sidiv.registrocivil.cl/usuarios-portal/pages/DocumentRequestStatus.xhtml'
28
+
29
+ # Set Agent to navigate web
30
+ a = Mechanize.new do |agent|
31
+ agent.user_agent_alias = 'Mac Safari'
32
+ agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
33
+ end
34
+
35
+ begin
36
+ a.get(url) do |page|
37
+
38
+ form = page.form_with(:id => 'form') do |f|
39
+ f['form:run'] = @doc_run
40
+ f['form:selectDocType'] = @doc_type
41
+ f['form:docNumber'] = @doc_number
42
+ end.click_button
43
+
44
+ doc = form.parser
45
+ # Get value (Vigente | No Vigente | Empty)
46
+ status = doc.at('tr [@class="setWidthOfSecondColumn"]').text
47
+
48
+ if( status == 'Vigente' )
49
+ return true
50
+ else
51
+ return false
52
+ end
53
+ end
54
+ rescue Mechanize::ResponseCodeError => e
55
+ return false
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,45 @@
1
+ module SRCEITools
2
+ module Version
3
+ module_function
4
+
5
+ # @return [Integer]
6
+ def major
7
+ 1
8
+ end
9
+
10
+ # @return [Integer]
11
+ def minor
12
+ 0
13
+ end
14
+
15
+ # @return [Integer]
16
+ def patch
17
+ 1
18
+ end
19
+
20
+ # @return [Integer, NilClass]
21
+ def pre
22
+ nil
23
+ end
24
+
25
+ # @return [Hash]
26
+ def to_h
27
+ {
28
+ major: major,
29
+ minor: minor,
30
+ patch: patch,
31
+ pre: pre,
32
+ }
33
+ end
34
+
35
+ # @return [Array]
36
+ def to_a
37
+ [major, minor, patch, pre].compact
38
+ end
39
+
40
+ # @return [String]
41
+ def to_s
42
+ to_a.join('.')
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: srcei-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Rios
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ description: Validar numero de serie de documento nacional RUT Chile
28
+ email: contacto@gonzalorios.cl
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/srcei-tools.rb
35
+ - lib/srcei-tools/validate_di.rb
36
+ - lib/srcei-tools/version.rb
37
+ homepage: https://github.com/xalupeao/srcei-tools
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements:
56
+ - none
57
+ rubyforge_project:
58
+ rubygems_version: 2.6.13
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: SRCEI Tools
62
+ test_files: []