inovadora_xml 0.0.3 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- metadata +24 -60
- data/.gitignore +0 -8
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.md +0 -43
- data/Rakefile +0 -2
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/inovadora_xml-0.0.2.gem +0 -0
- data/inovadora_xml.gemspec +0 -30
- data/lib/inovadora_xml.rb +0 -97
- data/lib/inovadora_xml/assinador.rb +0 -122
- data/lib/inovadora_xml/custom_exceptions.rb +0 -6
- data/lib/inovadora_xml/custom_exceptions/server_error.rb +0 -11
- data/lib/inovadora_xml/modules.rb +0 -8
- data/lib/inovadora_xml/modules/dados_nfse_service.rb +0 -143
- data/lib/inovadora_xml/modules/formatador_nfse.rb +0 -36
- data/lib/inovadora_xml/modules/gerador_xml.rb +0 -44
- data/lib/inovadora_xml/servidor_wsdl.rb +0 -47
- data/lib/inovadora_xml/version.rb +0 -3
- data/lib/inovadora_xml/xml.rb +0 -76
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d085759f5ffcfeabf39f9d77bf68e3e65e927c99802cb1b517ad96ee2f6a01a8
|
4
|
+
data.tar.gz: 4432bb36fd14c314becaf64dab92c1dbc4568278444e92cde823fca3d2dcbeaf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0902f045d8a90b477b72c7c92e22b8772270dceeddbaab191c6c725ba80473d9df804e1b3d6328e2a6a8542779ef27945ff479087af889feb72ae4c792da2b39'
|
7
|
+
data.tar.gz: 8c47daa7d44244c15d34cfe6b5ffde1175d24fafb434e9b412f59a125f30b3d7f0138791f7f70834bc532c10ba8a383894889a7796a9ccb64ba1e2e6e4d62363
|
metadata
CHANGED
@@ -1,52 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inovadora_xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.8
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Junior Libardoni
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-06-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.17'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.17'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '10.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '10.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: signer
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - '='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - '='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,102 +55,73 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: nokogiri
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
61
|
+
version: '1.10'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.
|
68
|
+
version: '1.10'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: savon
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
75
|
+
version: '2.12'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
82
|
+
version: '2.12'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: wasabi
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - "~>"
|
100
88
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
89
|
+
version: '3.6'
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - "~>"
|
108
95
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
96
|
+
version: '3.6'
|
110
97
|
description:
|
111
98
|
email:
|
112
99
|
- evanor.libardoni@gmail.com
|
113
100
|
executables: []
|
114
101
|
extensions: []
|
115
102
|
extra_rdoc_files: []
|
116
|
-
files:
|
117
|
-
- .gitignore
|
118
|
-
- CODE_OF_CONDUCT.md
|
119
|
-
- Gemfile
|
120
|
-
- LICENSE.txt
|
121
|
-
- README.md
|
122
|
-
- Rakefile
|
123
|
-
- bin/console
|
124
|
-
- bin/setup
|
125
|
-
- inovadora_xml-0.0.2.gem
|
126
|
-
- inovadora_xml.gemspec
|
127
|
-
- lib/inovadora_xml.rb
|
128
|
-
- lib/inovadora_xml/assinador.rb
|
129
|
-
- lib/inovadora_xml/custom_exceptions.rb
|
130
|
-
- lib/inovadora_xml/custom_exceptions/server_error.rb
|
131
|
-
- lib/inovadora_xml/modules.rb
|
132
|
-
- lib/inovadora_xml/modules/dados_nfse_service.rb
|
133
|
-
- lib/inovadora_xml/modules/formatador_nfse.rb
|
134
|
-
- lib/inovadora_xml/modules/gerador_xml.rb
|
135
|
-
- lib/inovadora_xml/servidor_wsdl.rb
|
136
|
-
- lib/inovadora_xml/version.rb
|
137
|
-
- lib/inovadora_xml/xml.rb
|
103
|
+
files: []
|
138
104
|
homepage:
|
139
105
|
licenses:
|
140
106
|
- MIT
|
107
|
+
metadata: {}
|
141
108
|
post_install_message:
|
142
109
|
rdoc_options: []
|
143
110
|
require_paths:
|
144
111
|
- lib
|
145
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
113
|
requirements:
|
148
|
-
- -
|
114
|
+
- - ">="
|
149
115
|
- !ruby/object:Gem::Version
|
150
116
|
version: '0'
|
151
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
-
none: false
|
153
118
|
requirements:
|
154
|
-
- -
|
119
|
+
- - ">="
|
155
120
|
- !ruby/object:Gem::Version
|
156
121
|
version: '0'
|
157
122
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 1.8.23.2
|
123
|
+
rubygems_version: 3.1.2
|
160
124
|
signing_key:
|
161
|
-
specification_version:
|
125
|
+
specification_version: 4
|
162
126
|
summary: Gem utilizada para geração de XML e envio.
|
163
127
|
test_files: []
|
data/.gitignore
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at junior@inovadora.com.br. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2019 Junior Libardoni
|
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
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# InovadoraXml
|
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/inovadora_xml`. 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 'inovadora_xml'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install inovadora_xml
|
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]/inovadora_xml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the InovadoraXml project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/inovadora_xml/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "inovadora_xml"
|
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
DELETED
data/inovadora_xml-0.0.2.gem
DELETED
Binary file
|
data/inovadora_xml.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "inovadora_xml/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "inovadora_xml"
|
8
|
-
spec.version = InovadoraXml::VERSION
|
9
|
-
spec.authors = ["Junior Libardoni"]
|
10
|
-
spec.email = ["evanor.libardoni@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Gem utilizada para geração de XML e envio.}
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
16
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
|
18
|
-
end
|
19
|
-
spec.bindir = "exe"
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.17"
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_development_dependency "signer", "1.4.2"
|
27
|
-
spec.add_dependency "nokogiri", ">= 1.4.0"
|
28
|
-
spec.add_dependency "savon", "1.2.0"
|
29
|
-
spec.add_dependency "wasabi", "2.5.0"
|
30
|
-
end
|
data/lib/inovadora_xml.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require 'action_pack'
|
3
|
-
|
4
|
-
require "inovadora_xml/version"
|
5
|
-
|
6
|
-
require "inovadora_xml/assinador"
|
7
|
-
require "inovadora_xml/servidor_wsdl"
|
8
|
-
|
9
|
-
|
10
|
-
module InovadoraXml
|
11
|
-
extend ActiveSupport::Autoload
|
12
|
-
attr_accessor :xml_nfse, :schema, :metodo_soap, :xml_gerado, :retorno, :wsdl, :cert, :key, :errors
|
13
|
-
autoload :Modules
|
14
|
-
autoload :CustomExceptions
|
15
|
-
|
16
|
-
class Xml
|
17
|
-
attr_accessor :xml_nfse, :schema, :metodo_soap, :xml_gerado, :retorno, :wsdl, :cert, :key, :errors
|
18
|
-
|
19
|
-
include InovadoraXml::Modules::FormatadorNfse
|
20
|
-
include InovadoraXml::Modules::GeradorXml
|
21
|
-
|
22
|
-
def initialize(args = {})
|
23
|
-
self.errors = ActiveModel::Errors.new(self)
|
24
|
-
self.xml_gerado = self.gerar_xml()
|
25
|
-
|
26
|
-
self.validar_args()
|
27
|
-
# self.valid?
|
28
|
-
end
|
29
|
-
|
30
|
-
def comunicar(request_args = {})
|
31
|
-
if self.valid?
|
32
|
-
servidor = InovadoraXml::ServidorWsdl.new(
|
33
|
-
self.envelopar(),
|
34
|
-
self.metodo_soap,
|
35
|
-
self.wsdl,
|
36
|
-
self.cert,
|
37
|
-
self.key,
|
38
|
-
request_args
|
39
|
-
)
|
40
|
-
|
41
|
-
unless servidor.enviar
|
42
|
-
raise InovadoraXml::CustomExceptions::ServerError.new(servidor), "Server Error"
|
43
|
-
end
|
44
|
-
#usage: self.retorno.to_xml ou self.retorno.body
|
45
|
-
self.retorno = servidor.retorno
|
46
|
-
end
|
47
|
-
|
48
|
-
rescue InovadoraXml::CustomExceptions::ServerError => e
|
49
|
-
e.object.errors.full_messages.each {|e| "Erro na comunicação: #{self.errors.add(:base, e)}"}
|
50
|
-
rescue Exception => e
|
51
|
-
self.errors.add(:base, e.message)
|
52
|
-
ensure
|
53
|
-
return self.errors.blank?
|
54
|
-
end
|
55
|
-
|
56
|
-
def validar_args
|
57
|
-
self.errors.add(:base, "Metodo SOAP não especificado") if self.metodo_soap.blank?
|
58
|
-
self.errors.add(:base, "Schema não especificado") if self.schema.blank?
|
59
|
-
self.errors.add(:base, "WSDL não especificado") if self.wsdl.blank?
|
60
|
-
|
61
|
-
return self.errors.blank?
|
62
|
-
end
|
63
|
-
|
64
|
-
def valid?
|
65
|
-
erros = []
|
66
|
-
schema = open(self.schema)
|
67
|
-
xsd = Nokogiri::XML::Schema(schema)
|
68
|
-
xsd.validate(self.xml_gerado).each do |error|
|
69
|
-
unless error.message.to_s.include?("{http://www.w3.org/2000/09/xmldsig#}Signature") ||
|
70
|
-
error.message.to_s.include?("{http://www.w3.org/2000/09/xmldsig#}SignedInfo")
|
71
|
-
erros << "(Linha: " + error.line.to_s + ") => " + error.message.to_s
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
erros.each {|erro| self.errors.add(:base, erro)}
|
76
|
-
rescue Errno::ENOENT => e
|
77
|
-
self.errors.add(:base, "Arquivo schema não existe")
|
78
|
-
rescue Exception => e
|
79
|
-
self.errors.add(:base, e)
|
80
|
-
ensure
|
81
|
-
self.errors.blank?
|
82
|
-
end
|
83
|
-
|
84
|
-
def assinar(tag_assinar)
|
85
|
-
assinador = InovadoraXml::Assinador.new(self.xml_gerado, tag_assinar, self.cert, self.key)
|
86
|
-
assinador.assinar_xml
|
87
|
-
|
88
|
-
assinador.errors.each do |error|
|
89
|
-
self.errors.add(:base, error.full_message)
|
90
|
-
end
|
91
|
-
|
92
|
-
self.xml_gerado = assinador.xml_assinado if assinador.errors.blank?
|
93
|
-
ensure
|
94
|
-
return self.errors.blank?
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
#encoding=utf-8
|
2
|
-
module InovadoraXml
|
3
|
-
class Assinador
|
4
|
-
attr_accessor :xml_assinar, :xml_assinado, :tag_assinar, :cert, :key, :errors, :parametro
|
5
|
-
|
6
|
-
def initialize(xml, tag_assinar, cert, key)
|
7
|
-
self.errors = ActiveModel::Errors.new(self)
|
8
|
-
|
9
|
-
self.xml_assinar = xml.to_s
|
10
|
-
self.tag_assinar = tag_assinar
|
11
|
-
self.cert = cert
|
12
|
-
self.key = key
|
13
|
-
end
|
14
|
-
|
15
|
-
def assinar_xml()
|
16
|
-
if self.valid?
|
17
|
-
chave_privada = OpenSSL::PKey::RSA.new(File.read(self.key))
|
18
|
-
certificado = OpenSSL::X509::Certificate.new(File.read(self.cert))
|
19
|
-
|
20
|
-
self.xml_assinado = Nokogiri::XML(self.xml_assinar.to_s, &:noblanks)
|
21
|
-
self.xml_assinado.xpath("//xmlns:#{self.tag_assinar}").each do |node|
|
22
|
-
|
23
|
-
# 1. Digest Hash for all XML
|
24
|
-
xml_canon = node.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0)
|
25
|
-
xml_digest = Base64.encode64(OpenSSL::Digest::SHA1.digest(xml_canon)).strip
|
26
|
-
|
27
|
-
# 2. Add Signature Node
|
28
|
-
signature = Nokogiri::XML::Node.new('Signature', self.xml_assinado)
|
29
|
-
signature.default_namespace = 'http://www.w3.org/2000/09/xmldsig#'
|
30
|
-
node.after(signature)
|
31
|
-
|
32
|
-
# 3.1 Create Signature Info
|
33
|
-
signature_info = Nokogiri::XML::Node.new('SignedInfo', self.xml_assinado)
|
34
|
-
|
35
|
-
# 3.2 Add CanonicalizationMethod
|
36
|
-
child_node = Nokogiri::XML::Node.new('CanonicalizationMethod', self.xml_assinado)
|
37
|
-
child_node['Algorithm'] = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'
|
38
|
-
signature_info.add_child child_node
|
39
|
-
|
40
|
-
# 3.3 Add SignatureMethod
|
41
|
-
child_node = Nokogiri::XML::Node.new('SignatureMethod', self.xml_assinado)
|
42
|
-
child_node['Algorithm'] = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
|
43
|
-
signature_info.add_child child_node
|
44
|
-
|
45
|
-
# 3.4 Create Reference
|
46
|
-
reference = Nokogiri::XML::Node.new('Reference', self.xml_assinado)
|
47
|
-
reference['URI'] = "##{node.first.last}"
|
48
|
-
|
49
|
-
# 3.5 Add Transforms
|
50
|
-
transforms = Nokogiri::XML::Node.new('Transforms', self.xml_assinado)
|
51
|
-
|
52
|
-
child_node = Nokogiri::XML::Node.new('Transform', self.xml_assinado)
|
53
|
-
child_node['Algorithm'] = 'http://www.w3.org/2000/09/xmldsig#enveloped-signature'
|
54
|
-
transforms.add_child child_node
|
55
|
-
|
56
|
-
child_node = Nokogiri::XML::Node.new('Transform', self.xml_assinado)
|
57
|
-
child_node['Algorithm'] = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'
|
58
|
-
transforms.add_child child_node
|
59
|
-
|
60
|
-
reference.add_child transforms
|
61
|
-
|
62
|
-
# 3.6 Add Digest
|
63
|
-
child_node = Nokogiri::XML::Node.new('DigestMethod', self.xml_assinado)
|
64
|
-
child_node['Algorithm'] = 'http://www.w3.org/2000/09/xmldsig#sha1'
|
65
|
-
reference.add_child child_node
|
66
|
-
|
67
|
-
# 3.6 Add DigestValue
|
68
|
-
child_node = Nokogiri::XML::Node.new('DigestValue', self.xml_assinado)
|
69
|
-
child_node.content = xml_digest
|
70
|
-
reference.add_child child_node
|
71
|
-
|
72
|
-
# 3.7 Add Reference and Signature Info
|
73
|
-
signature_info.add_child reference
|
74
|
-
signature.add_child signature_info
|
75
|
-
|
76
|
-
# 4 Sign Signature
|
77
|
-
sign_canon = signature_info.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0)
|
78
|
-
signature_hash = chave_privada.sign(OpenSSL::Digest::SHA1.new, sign_canon)
|
79
|
-
signature_value = Base64.encode64(signature_hash).gsub("\n", '')
|
80
|
-
|
81
|
-
# 4.1 Add SignatureValue
|
82
|
-
child_node = Nokogiri::XML::Node.new('SignatureValue', self.xml_assinado)
|
83
|
-
child_node.content = signature_value
|
84
|
-
signature.add_child child_node
|
85
|
-
|
86
|
-
# 5 Create KeyInfo
|
87
|
-
key_info = Nokogiri::XML::Node.new('KeyInfo', self.xml_assinado)
|
88
|
-
|
89
|
-
# 5.1 Add X509 Data and Certificate
|
90
|
-
x509_data = Nokogiri::XML::Node.new('X509Data', self.xml_assinado)
|
91
|
-
x509_certificate = Nokogiri::XML::Node.new('X509Certificate', self.xml_assinado)
|
92
|
-
x509_certificate.content = certificado.to_s.gsub(/\-\-\-\-\-[A-Z]+ CERTIFICATE\-\-\-\-\-/, "").gsub(/\n/,"")
|
93
|
-
|
94
|
-
x509_data.add_child x509_certificate
|
95
|
-
key_info.add_child x509_data
|
96
|
-
|
97
|
-
# 5.2 Add KeyInfo
|
98
|
-
signature.add_child key_info
|
99
|
-
end
|
100
|
-
|
101
|
-
# Return XML
|
102
|
-
self.xml_assinado.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0)
|
103
|
-
end
|
104
|
-
rescue Exception => e
|
105
|
-
self.errors.add(:base, e.message)
|
106
|
-
ensure
|
107
|
-
return self.errors.blank?
|
108
|
-
end
|
109
|
-
|
110
|
-
def valid?
|
111
|
-
raise "Chave não informada" unless self.key.present?
|
112
|
-
raise "Certificado não informado" unless self.cert.present?
|
113
|
-
raise "Arquivo chave não encontrado" unless File.exists?(self.key)
|
114
|
-
raise "Arquivo certificado não encontrado" unless File.exists?(self.cert)
|
115
|
-
|
116
|
-
rescue Exception => e
|
117
|
-
self.errors.add(:base, e.message)
|
118
|
-
ensure
|
119
|
-
return self.errors.blank?
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
module InovadoraXml
|
2
|
-
module Modules
|
3
|
-
# extend ActiveSupport::Autoload
|
4
|
-
autoload :FormatadorNfse, "inovadora_xml/modules/formatador_nfse"
|
5
|
-
autoload :GeradorXml, "inovadora_xml/modules/gerador_xml"
|
6
|
-
autoload :DadosNfseService, "inovadora_xml/modules/dados_nfse_service"
|
7
|
-
end
|
8
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# encoding=utf-8
|
2
|
-
module InovadoraXml
|
3
|
-
module Modules
|
4
|
-
module DadosNfseService
|
5
|
-
def get_numero_lote_rps
|
6
|
-
self.fnnfse.build_fnnfses_sancionada if self.fnnfse.fnnfses_sancionada.blank?
|
7
|
-
if self.fnnfse.fnnfses_sancionada.numero_rps.to_s == ""
|
8
|
-
self.fnnfse.fnnfses_sancionada.numero_rps = self.fnnfse.class.connection.select_value("SELECT nextval('gestho.prox_nro_rps_nfse')")
|
9
|
-
self.fnnfse.fnnfses_sancionada.save
|
10
|
-
end
|
11
|
-
return self.fnnfse.fnnfses_sancionada.numero_rps
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_itens_servicos
|
15
|
-
case self.parametro.fornecedor
|
16
|
-
when 7..8 # Publica e #NF-em
|
17
|
-
get_itens_servicos_publica
|
18
|
-
else
|
19
|
-
"Não implementado para esse fornecedor"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_itens_servicos_publica
|
24
|
-
itens_da_nota= "{"
|
25
|
-
if self.fnnfse.descritivo_servico.to_s == ""
|
26
|
-
unless self.fnnfse.fnpacote.nil?
|
27
|
-
itens_da_nota += "[" +
|
28
|
-
"[Descricao=#{self.fnnfse.try(:fnpacote).try(:descricao)} #{fnnfse.obs_pacote}]" +
|
29
|
-
"[Quantidade=1.0]" +
|
30
|
-
"[ValorUnitario=#{self.fnnfse.valor_pacote}]" +
|
31
|
-
"[Deducoes=0]" +
|
32
|
-
"[DescontoCondicionado=0]" +
|
33
|
-
"[DescontoIncondicionado=#{self.fnnfse.valor_pacote_desconto.to_f.round(2)}]" +
|
34
|
-
"[Aliquota=#{get_aliquota}]" +
|
35
|
-
"[itemServico=#{get_item_lista_servico}]" +
|
36
|
-
"]"
|
37
|
-
end
|
38
|
-
self.fnnfse.fnnfseis.each do |fnnfsei|
|
39
|
-
qtde = fnnfsei.qtde.to_f.round(2) == 0 ? 1.0 : fnnfsei.qtde.to_f.round(2)
|
40
|
-
itens_da_nota += "[" +
|
41
|
-
"[Descricao=#{fnnfsei.ftforma.nome}]" +
|
42
|
-
"[Quantidade=#{qtde}]" +
|
43
|
-
"[ValorUnitario=#{(fnnfsei.valor.to_f / qtde).round(8)}]" +
|
44
|
-
"[Deducoes=0]" +
|
45
|
-
"[DescontoCondicionado=0]" +
|
46
|
-
"[DescontoIncondicionado=#{fnnfsei.desconto.to_s.to_d}]" +
|
47
|
-
"[Aliquota=#{get_aliquota}]" +
|
48
|
-
"[itemServico=#{get_item_lista_servico}]" +
|
49
|
-
"]"
|
50
|
-
end
|
51
|
-
else
|
52
|
-
itens_da_nota += "[" +
|
53
|
-
"[Descricao=#{self.fnnfse.descritivo_servico}]" +
|
54
|
-
"[Quantidade=1.0]" +
|
55
|
-
"[ValorUnitario=#{self.fnnfse.valor_servicos}]" +
|
56
|
-
"[Deducoes=0]" +
|
57
|
-
"[DescontoCondicionado=0]" +
|
58
|
-
"[DescontoIncondicionado=#{self.fnnfse.valor_descontos}]" +
|
59
|
-
"[Aliquota=#{get_aliquota}]" +
|
60
|
-
"[itemServico=#{get_item_lista_servico}]" +
|
61
|
-
"]"
|
62
|
-
end
|
63
|
-
itens_da_nota += "}"
|
64
|
-
end
|
65
|
-
|
66
|
-
def get_itens_servicos_texto
|
67
|
-
itens_da_nota = ""
|
68
|
-
if self.fnnfse.descritivo_servico.to_s == ""
|
69
|
-
if self.fnnfse.try(:fnpacote).present?
|
70
|
-
itens_da_nota += "#{self.fnnfse.try(:fnpacote).try(:descricao)} #{fnnfse.obs_pacote} " +
|
71
|
-
"Valor: #{self.fnnfse.valor_pacote} " +
|
72
|
-
"Desconto: #{self.fnnfse.valor_pacote_desconto.to_f.round(2)}"
|
73
|
-
end
|
74
|
-
if self.fnnfse.fnnfseis.size > 1
|
75
|
-
self.fnnfse.fnnfseis.each do |fnnfsei|
|
76
|
-
qtde = fnnfsei.qtde.to_f.round(2) == 0 ? 1.0 : fnnfsei.qtde.to_f.round(2)
|
77
|
-
itens_da_nota += "- #{fnnfsei.ftforma.nome} Qtde: #{qtde} " +
|
78
|
-
"Valor: #{((fnnfsei.valor.to_f / qtde).round(8)).round(2)} " +
|
79
|
-
(fnnfsei.desconto.to_s.to_d>0 ? "Desconto: #{fnnfsei.desconto.to_s.to_d.round(2)}" : "") +
|
80
|
-
" \n"
|
81
|
-
end
|
82
|
-
else
|
83
|
-
fnnfsei = self.fnnfse.fnnfseis.first
|
84
|
-
itens_da_nota += "#{fnnfsei.ftforma.nome}" rescue ""
|
85
|
-
end
|
86
|
-
else
|
87
|
-
itens_da_nota += "#{self.fnnfse.descritivo_servico} " +
|
88
|
-
"Valor: #{self.fnnfse.valor_servicos.to_d.round(2)} " +
|
89
|
-
(self.fnnfse.valor_descontos.to_d>0 ? "Desconto: #{self.fnnfse.valor_descontos.to_d.round(2)}" : "")
|
90
|
-
end
|
91
|
-
itens_da_nota
|
92
|
-
end
|
93
|
-
|
94
|
-
def get_informacoes_complementares
|
95
|
-
mensagem = self.fnnfse.observacao.to_s.strip
|
96
|
-
if self.fnnfse.cliente_type == "Paciente"
|
97
|
-
intern = self.fnnfse.fnnfses_interns.try(:first).try(:intern)
|
98
|
-
unless intern.blank?
|
99
|
-
mensagem += " Intern:#{intern.id}-#{intern.paciente.try(:nome).try(:strip)}"
|
100
|
-
mensagem += " Conv.:#{intern.convenio.try(:nome).try(:strip)}"
|
101
|
-
mensagem += " CPF:#{intern.paciente.cpf}" if intern.paciente.cpf.to_s.strip != "" && intern.paciente.cpf.to_s.strip != "0"
|
102
|
-
mensagem += " Nasc:#{intern.paciente.data_nascimento.to_s_br}"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
mensagem = nil if mensagem.to_s.strip.blank?
|
106
|
-
mensagem
|
107
|
-
end
|
108
|
-
|
109
|
-
def get_item_lista_servico
|
110
|
-
self.hospital.iss_cd_lei_116 || '4.03'
|
111
|
-
end
|
112
|
-
|
113
|
-
def get_aliquota
|
114
|
-
self.fnnfse.percentual_iss || 0.0
|
115
|
-
end
|
116
|
-
|
117
|
-
def get_cnpj_prestador
|
118
|
-
self.hospital.cgc.to_s.gsub(/[^0-9]/, "")
|
119
|
-
end
|
120
|
-
|
121
|
-
def get_inscricao_municipal_prestador
|
122
|
-
self.hospital.inscricao_municipal.to_s.gsub(/[^0-9]-/, "")
|
123
|
-
end
|
124
|
-
|
125
|
-
def get_codigo_municipio_prest_servico
|
126
|
-
self.hospital.cidade_ibge.try(:ibge_com_digito)
|
127
|
-
end
|
128
|
-
|
129
|
-
def persistir_fnnfses_xml(xml)
|
130
|
-
xml_tratado = Nokogiri::XML(CGI.unescapeHTML(xml.to_xml.to_s), &:noblanks)
|
131
|
-
xml_tratado = xml_tratado.to_xml(indent: 2).to_s
|
132
|
-
if xml_tratado.blank?
|
133
|
-
xml_tratado = "xml não recebido da prefeitura"
|
134
|
-
end
|
135
|
-
retorno_service = NotasVendas::XmlRetornoService.new(fnnfse: self.fnnfse, xml_envio: self.xml_gerado().to_s, xml_retorno: xml_tratado, errors: self.errors)
|
136
|
-
if retorno_service.retornou_dados_nota?
|
137
|
-
retorno_service.save
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
module InovadoraXml
|
3
|
-
module Modules
|
4
|
-
module FormatadorNfse
|
5
|
-
def data_formato_br(data)
|
6
|
-
# Padrão: 11/11/2011
|
7
|
-
data = data.to_time if data.class == String
|
8
|
-
data.strftime('%d/%m/%Y') unless data.nil? || data.to_s == ""
|
9
|
-
end
|
10
|
-
|
11
|
-
def data_nfse(data)
|
12
|
-
# Padrão: 2010-11-11
|
13
|
-
data = data.to_time if data.class == String
|
14
|
-
data.strftime('%Y-%m-%d') unless data.nil? || data.to_s == ""
|
15
|
-
end
|
16
|
-
|
17
|
-
def data_hora_nfse(data)
|
18
|
-
# Padrão: 2010-09-16T14:50:00
|
19
|
-
data = data.to_time if data.class == String
|
20
|
-
data.strftime('%Y-%m-%dT%H:%M:%S') unless data.nil?
|
21
|
-
end
|
22
|
-
|
23
|
-
def data_hora_gmt(data)
|
24
|
-
# Padrão: 2010-09-16T14:50:00
|
25
|
-
data = data.to_time if data.class == String
|
26
|
-
data.strftime('%Y-%m-%dT%H:%M:%S%:z') unless data.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
def hora_nfse(data)
|
30
|
-
# Padrão: 11:26:00
|
31
|
-
data = data.to_time if data.class == String
|
32
|
-
data.strftime('%H:%M:%S') unless data.nil?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
module InovadoraXml
|
3
|
-
module Modules
|
4
|
-
module GeradorXml
|
5
|
-
|
6
|
-
def elemento(elemento, valor = nil)
|
7
|
-
if valor.class == String
|
8
|
-
valor.strip!
|
9
|
-
valor = I18n.transliterate(valor)
|
10
|
-
regex = /[^a-zA-Z0-9,.\-_\/:\[\]\=\$\@\{\}\/\n ]/
|
11
|
-
#regex = /[^a-zA-Z0-9,.\-_\/:\[\]\=\$\@\{\}\/ ]/
|
12
|
-
valor = valor.gsub(regex, "")
|
13
|
-
end
|
14
|
-
self.xml_nfse.send(elemento, valor) {
|
15
|
-
yield if block_given?
|
16
|
-
} unless valor.nil?
|
17
|
-
end
|
18
|
-
|
19
|
-
def grupo(elemento, id = nil)
|
20
|
-
if id.present?
|
21
|
-
self.xml_nfse.send(elemento, id) {
|
22
|
-
yield if block_given?
|
23
|
-
}
|
24
|
-
else
|
25
|
-
self.xml_nfse.send(elemento) {
|
26
|
-
yield if block_given?
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def construir(elemento_raiz)
|
32
|
-
builder = Nokogiri::XML::Builder.new() do |xml|
|
33
|
-
self.xml_nfse = xml
|
34
|
-
elemento(elemento_raiz, get_namespace) {
|
35
|
-
yield
|
36
|
-
}
|
37
|
-
end
|
38
|
-
xml_builder = builder.to_xml(indent: 2, encoding: "UTF-8")
|
39
|
-
doc = Nokogiri::XML(xml_builder, &:noblanks)
|
40
|
-
return doc
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
module InovadoraXml
|
3
|
-
class ServidorWsdl
|
4
|
-
attr_accessor :xml_enviar, :metodo_soap, :wsdl, :args_request, :cert, :key, :retorno, :errors
|
5
|
-
|
6
|
-
def initialize(xml_enviar, metodo_soap, wsdl, cert = nil, key = nil, args_request = {})
|
7
|
-
self.xml_enviar = xml_enviar
|
8
|
-
self.metodo_soap = metodo_soap
|
9
|
-
self.wsdl = wsdl
|
10
|
-
|
11
|
-
self.cert = cert
|
12
|
-
self.key = key
|
13
|
-
|
14
|
-
self.args_request = args_request
|
15
|
-
|
16
|
-
self.errors = ActiveModel::Errors.new(self)
|
17
|
-
end
|
18
|
-
|
19
|
-
def enviar
|
20
|
-
begin
|
21
|
-
cliente = estabelecer_cliente()
|
22
|
-
|
23
|
-
response = cliente.request(self.metodo_soap, args_request) do
|
24
|
-
soap.xml = self.xml_enviar
|
25
|
-
end
|
26
|
-
self.retorno = response
|
27
|
-
rescue Savon::SOAP::Fault => fault
|
28
|
-
self.errors.add(:base, fault.to_s)
|
29
|
-
rescue Savon::HTTP::Error => fault2
|
30
|
-
self.errors.add(:base, fault2.to_s)
|
31
|
-
rescue Exception => e
|
32
|
-
self.errors.add(:base, e.message)
|
33
|
-
ensure
|
34
|
-
return self.errors.blank?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def estabelecer_cliente
|
39
|
-
Savon::Client.new do |wsdl, http|
|
40
|
-
wsdl.document = self.wsdl
|
41
|
-
http.auth.ssl.cert_file = self.cert unless self.cert.blank?
|
42
|
-
http.auth.ssl.cert_key_file = self.key unless self.key.blank?
|
43
|
-
http.auth.ssl.verify_mode = :none
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/inovadora_xml/xml.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
module InovadoraXml
|
3
|
-
class Xml
|
4
|
-
attr_accessor :xml_nfse, :schema, :metodo_soap, :xml_gerado, :retorno, :wsdl, :cert, :key, :errors
|
5
|
-
|
6
|
-
include InovadoraXml::Modules::FormatadorMfse
|
7
|
-
include InovadoraXml::Modules::GeradorXml
|
8
|
-
|
9
|
-
def initialize(args = {})
|
10
|
-
self.errors = ActiveModel::Errors.new(self)
|
11
|
-
self.xml_gerado = self.gerar_xml()
|
12
|
-
|
13
|
-
self.validar_args
|
14
|
-
# self.valid?
|
15
|
-
end
|
16
|
-
|
17
|
-
def comunicar(request_args = {})
|
18
|
-
self.valid?
|
19
|
-
|
20
|
-
if self.errors.blank?
|
21
|
-
servidor = InovadoraXml::ServidorWsdl.new(
|
22
|
-
envelopar(),
|
23
|
-
self.metodo_soap,
|
24
|
-
self.wsdl,
|
25
|
-
request_args
|
26
|
-
)
|
27
|
-
|
28
|
-
unless servidor.enviar
|
29
|
-
raise InovadoraXml::CustomExceptions::ServerError.new(servidor), "Server Error"
|
30
|
-
end
|
31
|
-
#usage: self.retorno.to_xml ou self.retorno.body
|
32
|
-
self.retorno = servidor.retorno
|
33
|
-
end
|
34
|
-
|
35
|
-
rescue InovadoraXml::CustomExceptions::ServerError => e
|
36
|
-
e.object.errors.full_messages.each {|e| self.errors.add(:base, e)}
|
37
|
-
rescue Exception => e
|
38
|
-
self.errors.add(:base, e.message)
|
39
|
-
ensure
|
40
|
-
return self.errors.blank?
|
41
|
-
end
|
42
|
-
|
43
|
-
def validar_args
|
44
|
-
self.errors.add(:base, "Metodo SOAP não especificado") if self.metodo_soap.blank?
|
45
|
-
self.errors.add(:base, "Schema não especificado") if self.schema.blank?
|
46
|
-
self.errors.add(:base, "WSDL não especificado") if self.wsdl.blank?
|
47
|
-
|
48
|
-
return self.errors.blank?
|
49
|
-
end
|
50
|
-
|
51
|
-
def valid?
|
52
|
-
erros = []
|
53
|
-
schema = open(self.schema)
|
54
|
-
xsd = Nokogiri::XML::Schema(schema)
|
55
|
-
xsd.validate(self.xml_gerado).each do |error|
|
56
|
-
unless error.message.to_s.include?("{http://www.w3.org/2000/09/xmldsig#}Signature") ||
|
57
|
-
error.message.to_s.include?("{http://www.w3.org/2000/09/xmldsig#}SignedInfo")
|
58
|
-
erros << "(Linha: " + error.line.to_s + ") => " + error.message.to_s
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
erros.each {|erro| self.errors.add(:base, erro)}
|
63
|
-
rescue Errno::ENOENT => e
|
64
|
-
self.errors.add(:base, "Arquivo schema não existe")
|
65
|
-
rescue Exception => e
|
66
|
-
self.errors.add(:base, e)
|
67
|
-
ensure
|
68
|
-
self.errors.blank?
|
69
|
-
end
|
70
|
-
|
71
|
-
def assinar(xml_assinar, tag_assinar)
|
72
|
-
Assinador.new(xml_assinar, tag_assinar).xml_assinado
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|