ipiranga 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9d4546ea3d7360b5f7d3eec0fb9204a1d606241
4
- data.tar.gz: f288c690eb211d14154b291c89f9e0c954412607
3
+ metadata.gz: 9ba581b8afe71d12ded58bfea512196e1684cbd6
4
+ data.tar.gz: 41d7b838b54c7720f726327d56184bd9a7eee037
5
5
  SHA512:
6
- metadata.gz: 285fe5be93c5767b47a56cc2cccca98092b64ec9a595e39229c2dadafc4a4f2980616a655db51d807cc390f3e8afa96fda56c288e8d81cb780433bf56d4fd712
7
- data.tar.gz: b9a547b0ac2f5d10ad248428c19a3dc7e0195867adf8146dd65e1f7e50d4bc18e9bc1bbb6ad910d3236ab62f2467fd805122804086954fd7da45cbedfa56fefc
6
+ metadata.gz: dd523ead6de24192b77a2eb7e983f455d0ebbbeaa176aa56a3a5c925be7c0f93ea0f3bbd165a1ed72f4feee3f9aad13f9afd7254bc5342fee326bfd011b92180
7
+ data.tar.gz: dbea4913f2c2eaede45650b48f31ea1f88e1c72895f7a1e030d7f57567109b2d9a2caa9f6b3e9bd3a70bd097e945095a625f491f33ad1671b1b0430411a818fe
data/lib/ipiranga.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'ipiranga/error'
2
- require 'ipiranga/clients'
2
+ require 'ipiranga/clients/km'
3
+ require 'ipiranga/clients/pf'
3
4
  require 'ipiranga/version'
@@ -19,6 +19,10 @@ module Ipiranga
19
19
  define_singleton_method("post_#{operation}") do |&block|
20
20
  post(operation, &block)
21
21
  end
22
+
23
+ define_singleton_method(operation) do |&block|
24
+ post(operation, &block).body_hash
25
+ end unless respond_to?(operation)
22
26
  end
23
27
  end
24
28
 
@@ -0,0 +1,23 @@
1
+ require 'ipiranga/client'
2
+
3
+ module Ipiranga
4
+ class KM < Client
5
+ def wsdl_url
6
+ if defined?(RAILS_ENV) && RAILS_ENV == "production"
7
+ "https://b2b.ipiranga.com.br/csp/ensb2cws/cbpi.bs.km.pedido.Service.CLS?WSDL=1"
8
+ else
9
+ "https://b2bdv.ipiranga.com.br/csp/ensb2cws/cbpi.bs.km.pedido.Service.CLS?WSDL=1"
10
+ end
11
+ end
12
+
13
+ def gerarPedidoAcumulo(&block)
14
+ result = post_gerarPedidoAcumulo(&block).
15
+ body_hash["gerarPedidoAcumuloResult"]
16
+
17
+ raise RequestAlreadyExists.new(result) if result["codigoRetorno"] == "2"
18
+ raise ::Exception.new(result) if result["codigoRetorno"] != "0"
19
+
20
+ return result["codigoRequisicao"].to_i
21
+ end
22
+ end
23
+ end
@@ -13,7 +13,7 @@ module Ipiranga
13
13
  def cadastrar(&block)
14
14
  result = post_cadastrar(&block).body_hash["cadastrarResult"]
15
15
 
16
- Ipiranga.raise_exception(result) if result["status"].nil? || result["status"] == "false"
16
+ raise_exception(result) if result["status"].nil? || result["status"] == "false"
17
17
 
18
18
  if result["status"] == "true" && result["statusMimetica"] == "2"
19
19
  raise UserAlreadyExists.new(result)
@@ -21,14 +21,17 @@ module Ipiranga
21
21
 
22
22
  return result["statusMimetica"] == "0"
23
23
  end
24
- end
25
24
 
26
- class KM < Client
27
- def wsdl_url
28
- if defined?(RAILS_ENV) && RAILS_ENV == "production"
29
- "https://b2b.ipiranga.com.br/csp/ensb2cws/cbpi.bs.km.pedido.Service.CLS?WSDL=1"
25
+ private
26
+
27
+ def self.raise_exception(result)
28
+ case result["msgErro"]
29
+ when "Usuario/Password Inválido"
30
+ raise InvalidCredentials.new(result)
31
+ when "Erro interno"
32
+ raise InternalError.new(result)
30
33
  else
31
- "https://b2bdv.ipiranga.com.br/csp/ensb2cws/cbpi.bs.km.pedido.Service.CLS?WSDL=1"
34
+ raise ::Exception.new(result)
32
35
  end
33
36
  end
34
37
  end
@@ -20,18 +20,8 @@ module Ipiranga
20
20
  end
21
21
  end
22
22
 
23
+ class RequestAlreadyExists < ::Exception; end
23
24
  class UserAlreadyExists < ::Exception; end
24
25
  class InvalidCredentials < ::Exception; end
25
26
  class InternalError < ::Exception; end
26
-
27
- def self.raise_exception(result)
28
- case result["msgErro"]
29
- when "Usuario/Password Inválido"
30
- raise InvalidCredentials.new(result)
31
- when "Erro interno"
32
- raise InternalError.new(result)
33
- else
34
- raise ::Exception.new(result)
35
- end
36
- end
37
27
  end
@@ -1,6 +1,6 @@
1
1
  module Ipiranga
2
2
  # Joins the version numbers
3
- VERSION = [0, 0, 4].join('.')
3
+ VERSION = [0, 0, 5].join('.')
4
4
 
5
5
  # Returns {VERSION}
6
6
  # @return [String]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipiranga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amadeus Folego
@@ -73,10 +73,11 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/ipiranga.rb
76
+ - lib/ipiranga/clients/km.rb
77
+ - lib/ipiranga/clients/pf.rb
76
78
  - lib/ipiranga/version.rb
77
79
  - lib/ipiranga/client.rb
78
80
  - lib/ipiranga/error.rb
79
- - lib/ipiranga/clients.rb
80
81
  homepage: https://github.com/badosu/Ipiranga
81
82
  licenses:
82
83
  - MIT