ipiranga 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de47785dc4e54740f84889c72eea0c4e544cd9cd
4
+ data.tar.gz: 996bd90a549b975e9b30e113e6eb18d05f7fab97
5
+ SHA512:
6
+ metadata.gz: 5b5843892980ba32c1d0b4836b26d79db92069242686576532d373be6f78790ab40ce5b82628fa0a45531c2832f8ce3d6ab4b588c0afbea52282f67435cf4d19
7
+ data.tar.gz: 2b7d9ef6c35334a507e51ef9f37083ba2bf900ce52292f1ee28e74655c8d2358a2dfbeffddc79be68947be8a69327900a3e9f1e856744a75852989a187d31027
data/lib/ipiranga.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'ipiranga/clients'
2
+ require 'ipiranga/version'
@@ -0,0 +1,63 @@
1
+ require 'lolsoap'
2
+ require 'open-uri'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'akami'
6
+
7
+ module Ipiranga
8
+ class Client
9
+ attr_reader :wsdl, :soap, :wsdl_url
10
+ attr_accessor :username, :password
11
+
12
+ def initialize(opts = {})
13
+ @wsdl_url = URI(opts.fetch(:wsdl, wsdl_url))
14
+ @username = opts[:username]
15
+ @password = opts[:password]
16
+
17
+ operations.each do |operation|
18
+ define_singleton_method(operation) do |&block|
19
+ post(operation, &block)
20
+ end
21
+ end
22
+ end
23
+
24
+ def wsdl
25
+ @wsdl ||= open(@wsdl_url.to_s).read.gsub("http://eaidev:2010", "https://#{@wsdl_url.host}")
26
+ end
27
+
28
+ def soap
29
+ @soap ||= LolSoap::Client.new(wsdl)
30
+ end
31
+
32
+ def operations
33
+ soap.wsdl.operations.keys
34
+ end
35
+
36
+ def post(operation)
37
+ request = soap.request(operation)
38
+
39
+ yield request.body if block_given?
40
+
41
+ append_wsse(request) if has_credentials?
42
+
43
+ uri = URI(request.url)
44
+ http = Net::HTTP.new(uri.host, uri.port)
45
+ http.use_ssl = true
46
+ http_response = http.post(uri.path.gsub(".cls", ".CLS"), request.content, request.headers)
47
+
48
+ soap.response(request, http_response.body).body_hash
49
+ end
50
+
51
+ def has_credentials?
52
+ !username.nil? && !password.nil?
53
+ end
54
+
55
+ private
56
+
57
+ def append_wsse(request)
58
+ wsse = Akami.wsse
59
+ wsse.credentials(username, password)
60
+ request.header.__node__ << wsse.to_xml
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ require 'ipiranga/client'
2
+
3
+ module Ipiranga
4
+ class PF < Client
5
+ def wsdl_url
6
+ "https://b2bdv.ipiranga.com.br/csp/ensb2cws/cbpi.bs.participantePF.Service.CLS?WSDL=1"
7
+ end
8
+ end
9
+
10
+ class KM < Client
11
+ def wsdl_url
12
+ "https://b2bdv.ipiranga.com.br/csp/ensb2cws/cbpi.bs.km.pedido.Service.CLS?WSDL=1"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Ipiranga
2
+ # Major version number
3
+ MAJOR = 0
4
+ # Minor version number
5
+ MINOR = 0
6
+ # Tiny version number
7
+ TINY = 1
8
+
9
+ # Joins the version numbers
10
+ VERSION = [MAJOR, MINOR, TINY].join('.')
11
+
12
+ # Returns {VERSION}
13
+ # @return [String]
14
+ def self.version
15
+ VERSION
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ipiranga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Amadeus Folego
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lolsoap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: akami
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ description: A simple Ipiranga Web Services Client
42
+ email: amadeusfolego@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/ipiranga.rb
48
+ - lib/ipiranga/version.rb
49
+ - lib/ipiranga/client.rb
50
+ - lib/ipiranga/clients.rb
51
+ homepage: https://github.com/badosu/Ipiranga
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Ipiranga Web Services Client
75
+ test_files: []