sii_chile 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96e8fd8d31bbf30279abaaae8401ede569b03723
4
- data.tar.gz: 5db499e5e15fc11a0ca3f6facb8ee78393763a2d
3
+ metadata.gz: 9f526c5f522c2cb71f7f367df7449af50239abf9
4
+ data.tar.gz: 1e0f09e39921b4f5a02250b0c8ee4a071a7093b9
5
5
  SHA512:
6
- metadata.gz: a2ae2bd43b609cc5fb658978667de32798f752e8a26164a19c92879d6eabac5f2e9e3bcc9ef6cc0b610a621b6e2c7383ca97d9bcbdedd3ef3f50bbe3ccb4d353
7
- data.tar.gz: 386d54d2ec609e3b6eb675bf9686b99c739ed5d0058fc9ec79203ba74b37e53825847d079669b0e39e7b1cf9d6d5bc2928f758949e2082b0ea7085723e5a61e0
6
+ metadata.gz: 0430abf164c28dc7d73932a3bd277bd471a80eb020c27370024048614067b0ed35ca6addf21ec6c992661c39731ebb08f2ba462e6777844c4889493ca618437a
7
+ data.tar.gz: 73b3bbc3d52307702bc8f337695eabda1e969f4db1449289375ff96100c9ab641dd6bd4c4b2e0088899d5f7c58278b7a8d608625d67266438281b261382f3ac6
@@ -1,3 +1,6 @@
1
+ require 'json'
2
+ require 'base64'
3
+
1
4
  module SIIChile
2
5
  class Consulta
3
6
  attr_reader :rut
@@ -17,11 +20,14 @@ module SIIChile
17
20
  def fetch!
18
21
  raise 'Rut invalido' unless @rut.valid?
19
22
 
20
- response = Faraday.get('https://zeus.sii.cl/cvc_cgi/stc/getstc', {
23
+ captcha = fetch_captcha!
24
+ response = Faraday.post('https://zeus.sii.cl/cvc_cgi/stc/getstc', {
21
25
  'RUT' => @rut.number,
22
26
  'DV' => @rut.code,
23
27
  'PRG' => 'STC',
24
- 'ACEPTAR' => 'Efectuar%20Consulta'
28
+ 'OPC' => 'NOR',
29
+ 'txt_code' => captcha[:code],
30
+ 'txt_captcha' => captcha[:captcha]
25
31
  })
26
32
 
27
33
  data = Nokogiri::HTML(response.body)
@@ -46,5 +52,18 @@ module SIIChile
46
52
  :error => e.message
47
53
  }
48
54
  end
55
+
56
+ def fetch_captcha!
57
+ response = Faraday.post('https://zeus.sii.cl/cvc_cgi/stc/CViewCaptcha.cgi', {
58
+ oper: 0
59
+ });
60
+
61
+ data = JSON.parse(response.body)
62
+
63
+ {
64
+ code: Base64.decode64(data["txtCaptcha"])[36..39],
65
+ captcha: data["txtCaptcha"]
66
+ }
67
+ end
49
68
  end
50
69
  end
@@ -1,3 +1,3 @@
1
1
  module SIIChile
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sii_chile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seba Gamboa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday