notasegura 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/notasegura.rb +17 -1
- metadata +1 -1
data/lib/notasegura.rb
CHANGED
@@ -11,7 +11,6 @@ end
|
|
11
11
|
|
12
12
|
class NotaSegura
|
13
13
|
|
14
|
-
|
15
14
|
def initialize(email, senha)
|
16
15
|
if email.nil? or not email.is_a? String or email.empty?
|
17
16
|
raise ArgumentError, 'Usuário inválido'
|
@@ -76,6 +75,23 @@ class NotaSegura
|
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
78
|
+
def enviar_anexo(hash, arquivo)
|
79
|
+
begin
|
80
|
+
url = "#{@url}/api/uploads"
|
81
|
+
url = "#{url}?token=#{@token}" if @token
|
82
|
+
requisicao = RestClient::Resource.new(url, @email, @senha)
|
83
|
+
resposta = requisicao.post({:hash => hash, :file => arquivo})
|
84
|
+
resultado = XmlSimple.xml_in resposta
|
85
|
+
return resultado
|
86
|
+
rescue => e
|
87
|
+
if e.message.include? '401'
|
88
|
+
raise AuthError, 'Erro ao autenticar: token inválido'
|
89
|
+
else
|
90
|
+
raise RequestError, "Erro ao enviar anexo: #{e}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
79
95
|
private
|
80
96
|
|
81
97
|
def ler_xml!
|