baixarxml 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/baixarxml.rb +19 -5
- metadata +1 -1
data/lib/baixarxml.rb
CHANGED
@@ -11,8 +11,9 @@ end
|
|
11
11
|
|
12
12
|
class BaixarXml
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
def initialize(email, senha)
|
16
|
+
if email.nil? or not email.is_a? String or email.empty?
|
16
17
|
raise ArgumentError, 'Usuário inválido'
|
17
18
|
end
|
18
19
|
|
@@ -20,7 +21,13 @@ class BaixarXml
|
|
20
21
|
raise ArgumentError, 'Senha inválida'
|
21
22
|
end
|
22
23
|
|
23
|
-
@url =
|
24
|
+
@url = 'http://baixarxml.com.br/api/invoices'
|
25
|
+
@email = email
|
26
|
+
@senha = senha
|
27
|
+
end
|
28
|
+
|
29
|
+
def token=(token)
|
30
|
+
@token = token
|
24
31
|
end
|
25
32
|
|
26
33
|
def enviar_xml(xml)
|
@@ -30,12 +37,19 @@ class BaixarXml
|
|
30
37
|
checar_xml!
|
31
38
|
|
32
39
|
begin
|
33
|
-
|
40
|
+
@url = "#{@url}?token=#{@token}" if @token
|
41
|
+
requisicao = RestClient::Request.new(
|
42
|
+
:method => :post,
|
43
|
+
:url => @url,
|
44
|
+
:user => @email,
|
45
|
+
:password => @senha
|
46
|
+
)
|
47
|
+
resposta = requisicao.execute
|
34
48
|
resultado = XmlSimple.xml_in resposta
|
35
49
|
return resultado
|
36
50
|
rescue => e
|
37
51
|
if e.message.include? '401'
|
38
|
-
raise AuthError, 'Erro ao autenticar:
|
52
|
+
raise AuthError, 'Erro ao autenticar: token inválido'
|
39
53
|
else
|
40
54
|
raise RequestError, "Erro ao enviar XML: #{e}"
|
41
55
|
end
|