ipiranga 0.0.3 → 0.0.4

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: 023d173728ed0638b9168f2cdb02eafa934c98ee
4
- data.tar.gz: 3a24165d33b2a3f12b2f463489cb5f0cdcc89f08
3
+ metadata.gz: e9d4546ea3d7360b5f7d3eec0fb9204a1d606241
4
+ data.tar.gz: f288c690eb211d14154b291c89f9e0c954412607
5
5
  SHA512:
6
- metadata.gz: d6452f00a36f162b83f560f366d8321726eec73566106e45ce4ccc2ecc018da3fab56299a9005e593c6aea0c6352de532fa0e2892afbe6bef68293e38aaf933e
7
- data.tar.gz: 19011f0f72f228e27f672eeea764de9d15fd7d04433a16e0507feb1f76922b97c3f52a67039dda8102155e2631636568a9bc6fd348d2a12bb9a6f2443aab89c2
6
+ metadata.gz: 285fe5be93c5767b47a56cc2cccca98092b64ec9a595e39229c2dadafc4a4f2980616a655db51d807cc390f3e8afa96fda56c288e8d81cb780433bf56d4fd712
7
+ data.tar.gz: b9a547b0ac2f5d10ad248428c19a3dc7e0195867adf8146dd65e1f7e50d4bc18e9bc1bbb6ad910d3236ab62f2467fd805122804086954fd7da45cbedfa56fefc
data/lib/ipiranga.rb CHANGED
@@ -1,2 +1,3 @@
1
+ require 'ipiranga/error'
1
2
  require 'ipiranga/clients'
2
3
  require 'ipiranga/version'
@@ -16,7 +16,7 @@ module Ipiranga
16
16
  @wsdl = opts[:wsdl]
17
17
 
18
18
  operations.each do |operation|
19
- define_singleton_method(operation) do |&block|
19
+ define_singleton_method("post_#{operation}") do |&block|
20
20
  post(operation, &block)
21
21
  end
22
22
  end
@@ -52,7 +52,7 @@ module Ipiranga
52
52
  http.use_ssl = true
53
53
  http_response = http.post(uri.path.gsub(".cls", ".CLS"), request.content, request.headers)
54
54
 
55
- soap.response(request, http_response.body).body_hash
55
+ soap.response(request, http_response.body)
56
56
  end
57
57
 
58
58
  def has_credentials?
@@ -9,6 +9,18 @@ module Ipiranga
9
9
  "https://b2bdv.ipiranga.com.br/csp/ensb2cws/cbpi.bs.participantePF.Service.CLS?WSDL=1"
10
10
  end
11
11
  end
12
+
13
+ def cadastrar(&block)
14
+ result = post_cadastrar(&block).body_hash["cadastrarResult"]
15
+
16
+ Ipiranga.raise_exception(result) if result["status"].nil? || result["status"] == "false"
17
+
18
+ if result["status"] == "true" && result["statusMimetica"] == "2"
19
+ raise UserAlreadyExists.new(result)
20
+ end
21
+
22
+ return result["statusMimetica"] == "0"
23
+ end
12
24
  end
13
25
 
14
26
  class KM < Client
@@ -0,0 +1,37 @@
1
+ module Ipiranga
2
+ class Exception < StandardError
3
+ attr_accessor :result
4
+
5
+ def initialize(error)
6
+ if error.kind_of?(String)
7
+ super(error)
8
+ else
9
+ @result = error
10
+ super(error["msgErro"])
11
+ end
12
+ end
13
+
14
+ def inspect
15
+ "#{message}#{" - response: #{result.inspect}" unless result.nil?}"
16
+ end
17
+
18
+ def to_s
19
+ inspect
20
+ end
21
+ end
22
+
23
+ class UserAlreadyExists < ::Exception; end
24
+ class InvalidCredentials < ::Exception; end
25
+ 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
+ end
@@ -1,13 +1,6 @@
1
1
  module Ipiranga
2
- # Major version number
3
- MAJOR = 0
4
- # Minor version number
5
- MINOR = 0
6
- # Tiny version number
7
- TINY = 3
8
-
9
2
  # Joins the version numbers
10
- VERSION = [MAJOR, MINOR, TINY].join('.')
3
+ VERSION = [0, 0, 4].join('.')
11
4
 
12
5
  # Returns {VERSION}
13
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amadeus Folego
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-meta
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.5
41
69
  description: A simple Ipiranga Web Services Client
42
70
  email: amadeusfolego@gmail.com
43
71
  executables: []
@@ -47,6 +75,7 @@ files:
47
75
  - lib/ipiranga.rb
48
76
  - lib/ipiranga/version.rb
49
77
  - lib/ipiranga/client.rb
78
+ - lib/ipiranga/error.rb
50
79
  - lib/ipiranga/clients.rb
51
80
  homepage: https://github.com/badosu/Ipiranga
52
81
  licenses: