Class: TrivialSoap
- Inherits:
-
Object
- Object
- TrivialSoap
- Defined in:
- lib/trivial_soap.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
-
#initialize(opts) ⇒ TrivialSoap
constructor
A new instance of TrivialSoap.
- #request(action, &b) ⇒ Object
- #soap_envelope ⇒ Object
Constructor Details
#initialize(opts) ⇒ TrivialSoap
Returns a new instance of TrivialSoap.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trivial_soap.rb', line 22 def initialize opts fail unless opts.is_a? Hash @opts = opts return unless @opts[:host] # for testcases @http = Net::HTTP.new(@opts[:host], @opts[:port], @opts[:proxyHost], @opts[:proxyPort]) if @opts[:ssl] require 'net/https' @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX @http.cert = OpenSSL::X509::Certificate.new(@opts[:cert]) if @opts[:cert] @http.key = OpenSSL::PKey::RSA.new(@opts[:key]) if @opts[:key] end @http.set_debug_output(STDERR) if $DEBUG @http.read_timeout = 60 @http.open_timeout = 5 @http.start @debug = @opts[:debug] @cookie = nil @lock = Mutex.new end |
Instance Attribute Details
#cookie ⇒ Object
Returns the value of attribute cookie.
19 20 21 |
# File 'lib/trivial_soap.rb', line 19 def @cookie end |
#debug ⇒ Object
Returns the value of attribute debug.
19 20 21 |
# File 'lib/trivial_soap.rb', line 19 def debug @debug end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
20 21 22 |
# File 'lib/trivial_soap.rb', line 20 def http @http end |
Instance Method Details
#request(action, &b) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/trivial_soap.rb', line 56 def request action, &b headers = { 'content-type' => 'text/xml; charset=utf-8', 'SOAPAction' => action } headers['cookie'] = @cookie if @cookie body = soap_envelope(&b).target! if @debug $stderr.puts "Request:" $stderr.puts body $stderr.puts end start_time = Time.now response = @lock.synchronize { profile(:post) { @http.request_post(@opts[:path], body, headers) } } end_time = Time.now @cookie = response['set-cookie'] if response.key? 'set-cookie' nk = Nokogiri(response.body) if @debug $stderr.puts "Response (in #{'%.3f' % (end_time - start_time)} s)" $stderr.puts nk $stderr.puts end nk.xpath('//soapenv:Body/*').select(&:element?).first end |
#soap_envelope ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trivial_soap.rb', line 43 def soap_envelope xsd = 'http://www.w3.org/2001/XMLSchema' env = 'http://schemas.xmlsoap.org/soap/envelope/' xsi = 'http://www.w3.org/2001/XMLSchema-instance' xml = Builder::XmlMarkup.new :indent => 0 xml.tag!('env:Envelope', 'xmlns:xsd' => xsd, 'xmlns:env' => env, 'xmlns:xsi' => xsi) do xml.tag!('env:Body') do yield xml if block_given? end end xml end |