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.
Files changed (2) hide show
  1. data/lib/baixarxml.rb +19 -5
  2. metadata +1 -1
data/lib/baixarxml.rb CHANGED
@@ -11,8 +11,9 @@ end
11
11
 
12
12
  class BaixarXml
13
13
 
14
- def initialize(usuario, senha)
15
- if usuario.nil? or not usuario.is_a? String or usuario.empty?
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 = "http://#{usuario}:#{senha}@baixarxml.com.br/api/invoices"
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
- resposta = RestClient.post @url, :xml => @xml
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: usuário e/ou senha incorretos'
52
+ raise AuthError, 'Erro ao autenticar: token inválido'
39
53
  else
40
54
  raise RequestError, "Erro ao enviar XML: #{e}"
41
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baixarxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: