Class: Ipiranga::Client
- Inherits:
-
Object
- Object
- Ipiranga::Client
- Defined in:
- lib/ipiranga/client.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#soap ⇒ Object
readonly
Returns the value of attribute soap.
-
#username ⇒ Object
Returns the value of attribute username.
-
#wsdl ⇒ Object
Returns the value of attribute wsdl.
-
#wsdl_url ⇒ Object
readonly
Returns the value of attribute wsdl_url.
Instance Method Summary collapse
- #has_credentials? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #operation(key) ⇒ Object
- #operations ⇒ Object
- #post(operation) {|pRequest| ... } ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ipiranga/client.rb', line 12 def initialize(opts = {}) @wsdl_url = URI(opts.fetch(:wsdl_url, wsdl_url)) @username = opts[:username] @password = opts[:password] @wsdl = opts[:wsdl] operations.each do |operation| define_singleton_method("post_#{operation}") do |&block| post(operation, &block) end define_singleton_method(operation) do |&block| post(operation, &block).body_hash end unless respond_to?(operation) end end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/ipiranga/client.rb', line 10 def password @password end |
#soap ⇒ Object (readonly)
Returns the value of attribute soap.
9 10 11 |
# File 'lib/ipiranga/client.rb', line 9 def soap @soap end |
#username ⇒ Object
Returns the value of attribute username.
10 11 12 |
# File 'lib/ipiranga/client.rb', line 10 def username @username end |
#wsdl ⇒ Object
Returns the value of attribute wsdl.
10 11 12 |
# File 'lib/ipiranga/client.rb', line 10 def wsdl @wsdl end |
#wsdl_url ⇒ Object (readonly)
Returns the value of attribute wsdl_url.
9 10 11 |
# File 'lib/ipiranga/client.rb', line 9 def wsdl_url @wsdl_url end |
Instance Method Details
#has_credentials? ⇒ Boolean
62 63 64 |
# File 'lib/ipiranga/client.rb', line 62 def has_credentials? !username.nil? && !password.nil? end |
#operation(key) ⇒ Object
41 42 43 |
# File 'lib/ipiranga/client.rb', line 41 def operation(key) soap.wsdl.operations[key] end |
#operations ⇒ Object
37 38 39 |
# File 'lib/ipiranga/client.rb', line 37 def operations soap.wsdl.operations.keys end |
#post(operation) {|pRequest| ... } ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ipiranga/client.rb', line 45 def post(operation) request = soap.request(operation) pRequest = request.body.pRequest yield pRequest if block_given? append_wsse(request) if has_credentials? uri = URI(request.url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http_response = http.post(uri.path.gsub(".cls", ".CLS"), request.content, request.headers) soap.response(request, http_response.body) end |