padron 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +167 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/padron.rb +39 -0
- data/lib/padron/auth_data.rb +47 -0
- data/lib/padron/call.rb +89 -0
- data/lib/padron/constants.rb +39 -0
- data/lib/padron/id_persona.rb +58 -0
- data/lib/padron/version.rb +3 -0
- data/lib/padron/wsaa.rb +88 -0
- data/padron.gemspec +35 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 25017fb2680d137d73e166828395657852264574f9e474532754e0ae3319c63b
|
4
|
+
data.tar.gz: 0fd8f3f40f2d1b2f4e43a0878d599129aa72a5c87b4df2c87ca8f0a5fb71e8ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9669e5bbc72ed0642038f94606ec875fce67f868463b93a24ba8c991d3d6224f1c0f348908be0b5722d130697b101821be2ba69b0bddf7746c906fa25d9d560
|
7
|
+
data.tar.gz: d0adfab38cf08030dee6d767641c7b4679df73df2a73b4704a77b3d3b43ae065f62c5b128e3a66c03c1f8090b187f7db7c1e70cf2006ff53130d51755ec03f1b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
padron (0.1.0)
|
5
|
+
httpi
|
6
|
+
nokogiri (>= 1.10.4)
|
7
|
+
savon
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actioncable (6.0.2.1)
|
13
|
+
actionpack (= 6.0.2.1)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (6.0.2.1)
|
17
|
+
actionpack (= 6.0.2.1)
|
18
|
+
activejob (= 6.0.2.1)
|
19
|
+
activerecord (= 6.0.2.1)
|
20
|
+
activestorage (= 6.0.2.1)
|
21
|
+
activesupport (= 6.0.2.1)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
actionmailer (6.0.2.1)
|
24
|
+
actionpack (= 6.0.2.1)
|
25
|
+
actionview (= 6.0.2.1)
|
26
|
+
activejob (= 6.0.2.1)
|
27
|
+
mail (~> 2.5, >= 2.5.4)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
actionpack (6.0.2.1)
|
30
|
+
actionview (= 6.0.2.1)
|
31
|
+
activesupport (= 6.0.2.1)
|
32
|
+
rack (~> 2.0, >= 2.0.8)
|
33
|
+
rack-test (>= 0.6.3)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (6.0.2.1)
|
37
|
+
actionpack (= 6.0.2.1)
|
38
|
+
activerecord (= 6.0.2.1)
|
39
|
+
activestorage (= 6.0.2.1)
|
40
|
+
activesupport (= 6.0.2.1)
|
41
|
+
nokogiri (>= 1.8.5)
|
42
|
+
actionview (6.0.2.1)
|
43
|
+
activesupport (= 6.0.2.1)
|
44
|
+
builder (~> 3.1)
|
45
|
+
erubi (~> 1.4)
|
46
|
+
rails-dom-testing (~> 2.0)
|
47
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
+
activejob (6.0.2.1)
|
49
|
+
activesupport (= 6.0.2.1)
|
50
|
+
globalid (>= 0.3.6)
|
51
|
+
activemodel (6.0.2.1)
|
52
|
+
activesupport (= 6.0.2.1)
|
53
|
+
activerecord (6.0.2.1)
|
54
|
+
activemodel (= 6.0.2.1)
|
55
|
+
activesupport (= 6.0.2.1)
|
56
|
+
activestorage (6.0.2.1)
|
57
|
+
actionpack (= 6.0.2.1)
|
58
|
+
activejob (= 6.0.2.1)
|
59
|
+
activerecord (= 6.0.2.1)
|
60
|
+
marcel (~> 0.3.1)
|
61
|
+
activesupport (6.0.2.1)
|
62
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
63
|
+
i18n (>= 0.7, < 2)
|
64
|
+
minitest (~> 5.1)
|
65
|
+
tzinfo (~> 1.1)
|
66
|
+
zeitwerk (~> 2.2)
|
67
|
+
akami (1.3.1)
|
68
|
+
gyoku (>= 0.4.0)
|
69
|
+
nokogiri
|
70
|
+
builder (3.2.4)
|
71
|
+
concurrent-ruby (1.1.5)
|
72
|
+
crass (1.0.6)
|
73
|
+
erubi (1.9.0)
|
74
|
+
globalid (0.4.2)
|
75
|
+
activesupport (>= 4.2.0)
|
76
|
+
gyoku (1.3.1)
|
77
|
+
builder (>= 2.1.2)
|
78
|
+
httpi (2.4.4)
|
79
|
+
rack
|
80
|
+
socksify
|
81
|
+
i18n (1.8.2)
|
82
|
+
concurrent-ruby (~> 1.0)
|
83
|
+
loofah (2.4.0)
|
84
|
+
crass (~> 1.0.2)
|
85
|
+
nokogiri (>= 1.5.9)
|
86
|
+
mail (2.7.1)
|
87
|
+
mini_mime (>= 0.1.1)
|
88
|
+
marcel (0.3.3)
|
89
|
+
mimemagic (~> 0.3.2)
|
90
|
+
method_source (0.9.2)
|
91
|
+
mimemagic (0.3.3)
|
92
|
+
mini_mime (1.0.2)
|
93
|
+
mini_portile2 (2.4.0)
|
94
|
+
minitest (5.14.0)
|
95
|
+
nio4r (2.5.2)
|
96
|
+
nokogiri (1.10.7)
|
97
|
+
mini_portile2 (~> 2.4.0)
|
98
|
+
nori (2.6.0)
|
99
|
+
rack (2.1.1)
|
100
|
+
rack-test (1.1.0)
|
101
|
+
rack (>= 1.0, < 3)
|
102
|
+
rails (6.0.2.1)
|
103
|
+
actioncable (= 6.0.2.1)
|
104
|
+
actionmailbox (= 6.0.2.1)
|
105
|
+
actionmailer (= 6.0.2.1)
|
106
|
+
actionpack (= 6.0.2.1)
|
107
|
+
actiontext (= 6.0.2.1)
|
108
|
+
actionview (= 6.0.2.1)
|
109
|
+
activejob (= 6.0.2.1)
|
110
|
+
activemodel (= 6.0.2.1)
|
111
|
+
activerecord (= 6.0.2.1)
|
112
|
+
activestorage (= 6.0.2.1)
|
113
|
+
activesupport (= 6.0.2.1)
|
114
|
+
bundler (>= 1.3.0)
|
115
|
+
railties (= 6.0.2.1)
|
116
|
+
sprockets-rails (>= 2.0.0)
|
117
|
+
rails-dom-testing (2.0.3)
|
118
|
+
activesupport (>= 4.2.0)
|
119
|
+
nokogiri (>= 1.6)
|
120
|
+
rails-html-sanitizer (1.3.0)
|
121
|
+
loofah (~> 2.3)
|
122
|
+
railties (6.0.2.1)
|
123
|
+
actionpack (= 6.0.2.1)
|
124
|
+
activesupport (= 6.0.2.1)
|
125
|
+
method_source
|
126
|
+
rake (>= 0.8.7)
|
127
|
+
thor (>= 0.20.3, < 2.0)
|
128
|
+
rake (12.3.3)
|
129
|
+
savon (2.12.0)
|
130
|
+
akami (~> 1.2)
|
131
|
+
builder (>= 2.1.2)
|
132
|
+
gyoku (~> 1.2)
|
133
|
+
httpi (~> 2.3)
|
134
|
+
nokogiri (>= 1.8.1)
|
135
|
+
nori (~> 2.4)
|
136
|
+
wasabi (~> 3.4)
|
137
|
+
socksify (1.7.1)
|
138
|
+
sprockets (4.0.0)
|
139
|
+
concurrent-ruby (~> 1.0)
|
140
|
+
rack (> 1, < 3)
|
141
|
+
sprockets-rails (3.2.1)
|
142
|
+
actionpack (>= 4.0)
|
143
|
+
activesupport (>= 4.0)
|
144
|
+
sprockets (>= 3.0.0)
|
145
|
+
thor (1.0.1)
|
146
|
+
thread_safe (0.3.6)
|
147
|
+
tzinfo (1.2.6)
|
148
|
+
thread_safe (~> 0.1)
|
149
|
+
wasabi (3.5.0)
|
150
|
+
httpi (~> 2.0)
|
151
|
+
nokogiri (>= 1.4.2)
|
152
|
+
websocket-driver (0.7.1)
|
153
|
+
websocket-extensions (>= 0.1.0)
|
154
|
+
websocket-extensions (0.1.4)
|
155
|
+
zeitwerk (2.2.2)
|
156
|
+
|
157
|
+
PLATFORMS
|
158
|
+
ruby
|
159
|
+
|
160
|
+
DEPENDENCIES
|
161
|
+
bundler (~> 2.1)
|
162
|
+
padron!
|
163
|
+
rails
|
164
|
+
rake (~> 12.0)
|
165
|
+
|
166
|
+
BUNDLED WITH
|
167
|
+
2.1.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Facundo Diaz Martinez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Padron
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/padron`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'padron'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install padron
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/padron.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "padron"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/padron.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative "padron/version"
|
2
|
+
require_relative "padron/call"
|
3
|
+
require_relative "padron/auth_data"
|
4
|
+
require_relative "padron/constants"
|
5
|
+
require_relative "padron/wsaa"
|
6
|
+
require_relative "padron/id_persona"
|
7
|
+
require 'rails'
|
8
|
+
require "savon"
|
9
|
+
require 'net/http'
|
10
|
+
require 'net/https'
|
11
|
+
|
12
|
+
|
13
|
+
module Padron
|
14
|
+
class Error < StandardError; end
|
15
|
+
|
16
|
+
mattr_accessor :cuit, :pkey, :cert, :environment, :openssl_bin
|
17
|
+
|
18
|
+
def self.root
|
19
|
+
File.expand_path '../..', __FILE__
|
20
|
+
end
|
21
|
+
|
22
|
+
def deleteToken
|
23
|
+
AuthData.deleteToken
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.auth_hash(service = "ws_sr_padron_a5")
|
27
|
+
{ 'token' => Padron::TOKEN, 'sign' => Padron::SIGN, 'cuitRepresentada' => Padron.cuit }
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.setup(&block)
|
31
|
+
yield self
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Padron
|
2
|
+
|
3
|
+
class AuthData
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
attr_accessor :environment, :todays_data_file_name
|
8
|
+
|
9
|
+
def fetch
|
10
|
+
unless File.exists?(Padron.pkey)
|
11
|
+
raise "Archivo de llave privada no encontrado en #{ Padron.pkey }"
|
12
|
+
end
|
13
|
+
|
14
|
+
unless File.exists?(Padron.cert)
|
15
|
+
raise "Archivo certificado no encontrado en #{ Padron.cert }"
|
16
|
+
end
|
17
|
+
|
18
|
+
unless File.exists?(todays_data_file_name)
|
19
|
+
Padron::Wsaa.login
|
20
|
+
end
|
21
|
+
|
22
|
+
YAML.load_file(todays_data_file_name).each do |k, v|
|
23
|
+
Padron.const_set(k.to_s.upcase, v) #unless Padron.const_defined?(k.to_s.upcase)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def auth_hash
|
28
|
+
fetch unless Padron.constants.include?(:TOKEN) && Padron.constants.include?(:SIGN)
|
29
|
+
{ 'token' => Padron::TOKEN, 'sign' => Padron::SIGN, 'cuitRepresentado' => Padron.cuit }
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def wsaa_url
|
34
|
+
Padron::URLS[Padron.environment][:wsaa]
|
35
|
+
end
|
36
|
+
|
37
|
+
def wsfe_url
|
38
|
+
raise 'Environment not sent to either :test or :production' unless Padron::URLS.keys.include? environment
|
39
|
+
Padron::URLS[Padron.environment][:wsfe]
|
40
|
+
end
|
41
|
+
|
42
|
+
def todays_data_file_name
|
43
|
+
@todays_data_file ||= "/tmp/padron_a5_#{Padron.environment.to_s}_Padron_#{ Padron.cuit }_#{ Time.new.strftime('%Y_%m_%d') }.yml"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/padron/call.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module Padron
|
2
|
+
class Call
|
3
|
+
|
4
|
+
attr_reader :client, :environment, :body, :data, :fault_code
|
5
|
+
|
6
|
+
def initialize(args={})
|
7
|
+
@environment = args[:environment] || :test
|
8
|
+
end
|
9
|
+
|
10
|
+
def dummy
|
11
|
+
set_client
|
12
|
+
pp reponse = client.call(:dummy)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_data(id)
|
16
|
+
@data = get_personas(id)
|
17
|
+
return nil unless fault_code.nil?
|
18
|
+
set_data
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_personas(id)
|
22
|
+
set_client
|
23
|
+
set_body(id)
|
24
|
+
response = client.call(:get_persona_list, message: body)
|
25
|
+
rescue Savon::SOAPFault => error
|
26
|
+
if !error.blank?
|
27
|
+
@fault_code = error.to_hash[:fault][:faultstring]
|
28
|
+
else
|
29
|
+
@fault_code = nil
|
30
|
+
end
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def set_client
|
37
|
+
Padron::AuthData.fetch
|
38
|
+
@client = Savon.client(
|
39
|
+
wsdl: service_url,
|
40
|
+
log_level: :debug,
|
41
|
+
ssl_cert_key_file: Padron.pkey,
|
42
|
+
ssl_cert_file: Padron.cert,
|
43
|
+
ssl_verify_mode: :none,
|
44
|
+
read_timeout: 90,
|
45
|
+
open_timeout: 90,
|
46
|
+
headers: { "Accept-Encoding" => "gzip, deflate", "Connection" => "Keep-Alive" }
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_body id
|
51
|
+
ids = Padron::IdPersona.new(id).return_cuits
|
52
|
+
body = Padron.auth_hash
|
53
|
+
id_personas = []
|
54
|
+
ids.map do |cuit|
|
55
|
+
id_personas << cuit
|
56
|
+
end
|
57
|
+
@body = body.merge({"idPersona" => id_personas})
|
58
|
+
end
|
59
|
+
|
60
|
+
def service_url
|
61
|
+
Padron::URLS[environment][:padron]
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_data
|
65
|
+
pp data.body
|
66
|
+
personas = data.body[:get_persona_list_response][:persona_list_return][:persona]
|
67
|
+
personas.map do |persona|
|
68
|
+
unless persona[:error_constancia] && persona[:error_constancia].try(:[],:apellido).nil?
|
69
|
+
if !persona[:error_constancia].nil?
|
70
|
+
{:name => persona[:error_constancia][:apellido],
|
71
|
+
:cuit => persona[:error_constancia][:id_persona]}
|
72
|
+
else
|
73
|
+
{:name => set_name(persona[:datos_generales]),
|
74
|
+
:cuit => persona[:datos_generales][:id_persona],
|
75
|
+
:cp => persona[:datos_generales].try(:[], :domicilio_fiscal).try(:[], :cod_postal),
|
76
|
+
:address => persona[:datos_generales].try(:[], :domicilio_fiscal).try(:[], :direccion),
|
77
|
+
:city_id => persona[:datos_generales].try(:[], :domicilio_fiscal).try(:[], :id_provincia),
|
78
|
+
:city => Padron::PROVINCIAS[persona[:datos_generales].try(:[],:domicilio_fiscal).try(:[], :id_provincia)],
|
79
|
+
:locality => persona[:datos_generales].try(:[], :domicilio_fiscal).try(:[], :localidad)}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_name(persona)
|
86
|
+
return "#{persona[:nombre]} #{persona[:apellido]}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Padron
|
2
|
+
URLS = {
|
3
|
+
:test => {
|
4
|
+
:wsaa => 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms',
|
5
|
+
:padron => "https://awshomo.afip.gov.ar/sr-padron/webservices/personaServiceA5?WSDL"
|
6
|
+
},
|
7
|
+
:production => {
|
8
|
+
:wsaa => 'https://wsaa.afip.gov.ar/ws/services/LoginCms',
|
9
|
+
:padron => "https://aws.afip.gov.ar/sr-padron/webservices/personaServiceA5?WSDL"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
PROVINCIAS = {
|
14
|
+
"0" => 'CIUDAD AUTONOMA BUENOS AIRES',
|
15
|
+
"1" => 'BUENOS AIRES',
|
16
|
+
"2" => 'CATAMARCA',
|
17
|
+
"3" => 'CORDOBA',
|
18
|
+
"4" => 'CORRIENTES',
|
19
|
+
"5" => 'ENTRE RIOS',
|
20
|
+
"6" => 'JUJUY',
|
21
|
+
"7" => 'MENDOZA',
|
22
|
+
"8" => 'LA RIOJA',
|
23
|
+
"9" => 'SALTA',
|
24
|
+
"10" => 'SAN JUAN',
|
25
|
+
"11" => 'SAN LUIS',
|
26
|
+
"12" => 'SANTA FE',
|
27
|
+
"13" => 'SANTIAGO DEL ESTERO',
|
28
|
+
"14" => 'TUCUMAN',
|
29
|
+
"16" => 'CHACO',
|
30
|
+
"17" => 'CHUBUT',
|
31
|
+
"18" => 'FORMOSA',
|
32
|
+
"19" => 'MISIONES',
|
33
|
+
"20" => 'NEUQUEN',
|
34
|
+
"21" => 'LA PAMPA',
|
35
|
+
"22" => 'RIO NEGRO',
|
36
|
+
"23" => 'SANTA CRUZ',
|
37
|
+
"24" => 'TIERRA DEL FUEGO'
|
38
|
+
}
|
39
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Padron
|
2
|
+
class IdPersona
|
3
|
+
attr_reader :id
|
4
|
+
|
5
|
+
def initialize(id)
|
6
|
+
@id = id
|
7
|
+
end
|
8
|
+
|
9
|
+
def return_cuits
|
10
|
+
return id if id.length == 11
|
11
|
+
return calculate_cuits
|
12
|
+
end
|
13
|
+
|
14
|
+
def calculate_cuits
|
15
|
+
ids = []
|
16
|
+
%w(F M).each do |tipo|
|
17
|
+
ids << calculate_z(tipo)
|
18
|
+
end
|
19
|
+
return ids
|
20
|
+
end
|
21
|
+
|
22
|
+
def calculate_z tipo
|
23
|
+
multiplicador = "2345672345"
|
24
|
+
case tipo
|
25
|
+
when "F"
|
26
|
+
xy = 27
|
27
|
+
xy_dni = "27#{id}"
|
28
|
+
when "M"
|
29
|
+
xy = 20
|
30
|
+
xy_dni = "20#{id}"
|
31
|
+
end
|
32
|
+
verificador = 0
|
33
|
+
(0..9).each do |i|
|
34
|
+
verificador += (xy_dni.reverse[i].to_i * multiplicador[i].to_i)
|
35
|
+
end
|
36
|
+
verificador
|
37
|
+
z = verificador - (verificador / 11 * 11)
|
38
|
+
|
39
|
+
case z
|
40
|
+
when 0
|
41
|
+
z = 0
|
42
|
+
when 1
|
43
|
+
if tipo == "M"
|
44
|
+
z = 9
|
45
|
+
xy = 23
|
46
|
+
elsif tipo == "F"
|
47
|
+
z = 4
|
48
|
+
xy = 23
|
49
|
+
else
|
50
|
+
z = 11 - z
|
51
|
+
end
|
52
|
+
else
|
53
|
+
z = 11 - z
|
54
|
+
end
|
55
|
+
return "#{xy}#{id}#{z}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/padron/wsaa.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module Padron
|
2
|
+
class Wsaa
|
3
|
+
|
4
|
+
def self.login
|
5
|
+
service = 'ws_sr_padron_a5'
|
6
|
+
tra = build_tra(service)
|
7
|
+
cms = build_cms(tra)
|
8
|
+
req = build_request(cms)
|
9
|
+
auth = call_wsaa(req)
|
10
|
+
|
11
|
+
write_yaml(auth)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def self.build_tra service
|
17
|
+
@now = (Time.now) - 120
|
18
|
+
@from = @now.strftime('%FT%T%:z')
|
19
|
+
@to = (@from.to_time.end_of_day).strftime('%FT%T%:z')
|
20
|
+
@id = @now.strftime('%s')
|
21
|
+
tra = <<-EOF
|
22
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
23
|
+
<loginTicketRequest version="1.0">
|
24
|
+
<header>
|
25
|
+
<uniqueId>#{ @id }</uniqueId>
|
26
|
+
<generationTime>#{ @from }</generationTime>
|
27
|
+
<expirationTime>#{ @to }</expirationTime>
|
28
|
+
</header>
|
29
|
+
<service>#{service}</service>
|
30
|
+
</loginTicketRequest>
|
31
|
+
EOF
|
32
|
+
return tra
|
33
|
+
end
|
34
|
+
|
35
|
+
# Builds the CMS
|
36
|
+
# @return [String] cms
|
37
|
+
#
|
38
|
+
def self.build_cms(tra)
|
39
|
+
cms = `echo '#{ tra }' |
|
40
|
+
#{ Padron.openssl_bin } cms -sign -in /dev/stdin -signer #{ Padron.cert } -inkey #{ Padron.pkey } -nodetach \
|
41
|
+
-outform der |
|
42
|
+
#{ Padron.openssl_bin } base64 -e`
|
43
|
+
return cms
|
44
|
+
end
|
45
|
+
|
46
|
+
# Builds the CMS request to log in to the server
|
47
|
+
# @return [String] the cms body
|
48
|
+
#
|
49
|
+
def self.build_request(cms)
|
50
|
+
request = <<-XML
|
51
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
52
|
+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://wsaa.view.sua.dvadac.desein.Padron.gov">
|
53
|
+
<SOAP-ENV:Body>
|
54
|
+
<ns1:loginCms>
|
55
|
+
<ns1:in0>
|
56
|
+
#{ cms }
|
57
|
+
</ns1:in0>
|
58
|
+
</ns1:loginCms>
|
59
|
+
</SOAP-ENV:Body>
|
60
|
+
</SOAP-ENV:Envelope>
|
61
|
+
XML
|
62
|
+
return request
|
63
|
+
end
|
64
|
+
|
65
|
+
# Calls the WSAA with the request built by build_request
|
66
|
+
# @return [Array] with the token and signature
|
67
|
+
#
|
68
|
+
def self.call_wsaa(req)
|
69
|
+
response = `echo '#{ req }' | curl -k -s -H 'Content-Type: application/soap+xml; action=""' -d @- #{ Padron::AuthData.wsaa_url }`
|
70
|
+
pp response
|
71
|
+
response = CGI::unescapeHTML(response)
|
72
|
+
token = response.scan(/\<token\>(.+)\<\/token\>/).first.first
|
73
|
+
sign = response.scan(/\<sign\>(.+)\<\/sign\>/).first.first
|
74
|
+
return [token, sign]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Writes the token and signature to a YAML file in the /tmp directory
|
78
|
+
#
|
79
|
+
def self.write_yaml(certs)
|
80
|
+
yml = <<-YML
|
81
|
+
token: #{certs[0]}
|
82
|
+
sign: #{certs[1]}
|
83
|
+
YML
|
84
|
+
`echo '#{ yml }' > #{Rails.root}/Padron/#{Padron::AuthData.environment.to_s}_Padron_#{ Padron.cuit }_#{ Time.new.strftime('%Y_%m_%d') }.yml`
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/padron.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'lib/padron/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "padron"
|
5
|
+
spec.version = Padron::VERSION
|
6
|
+
spec.authors = ["Facundo Diaz Martinez"]
|
7
|
+
spec.email = ["facundo_diaz_martinez@hotmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "You could get public info from the desired CUIT"
|
10
|
+
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
11
|
+
spec.homepage = "http://www.litecodesas.com"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
#spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
#spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "savon", "~> 2.12"
|
31
|
+
spec.add_dependency "httpi", "2.3"
|
32
|
+
spec.add_dependency "nokogiri", "~> 1.10.4"
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Facundo Diaz Martinez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httpi
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.10.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.10.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- facundo_diaz_martinez@hotmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/padron.rb
|
99
|
+
- lib/padron/auth_data.rb
|
100
|
+
- lib/padron/call.rb
|
101
|
+
- lib/padron/constants.rb
|
102
|
+
- lib/padron/id_persona.rb
|
103
|
+
- lib/padron/version.rb
|
104
|
+
- lib/padron/wsaa.rb
|
105
|
+
- padron.gemspec
|
106
|
+
homepage: http://www.litecodesas.com
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
allowed_push_host: https://rubygems.org
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 2.3.0
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.0.3
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: You could get public info from the desired CUIT
|
130
|
+
test_files: []
|