Class: Sylfy::Service::SOAPWSDL

Inherits:
Object
  • Object
show all
Defined in:
lib/sylfy/service/soapwsdl.rb

Direct Known Subclasses

ChEBI::SOAP, Miriam::SOAP

Instance Method Summary collapse

Constructor Details

#initialize(wsdl, options = {}) ⇒ SOAPWSDL

Parameters:

wsdl
options


33
34
35
36
37
38
39
# File 'lib/sylfy/service/soapwsdl.rb', line 33

def initialize(wsdl, options = {})
    @options = options
    @options[:wsdl] = wsdl
    @options[:log] = false if !@options.has_key?(:log)
    @options[:pretty_print_xml] = true if @options.has_key?(:log_level) && @options[:log_level] == :debug
    @client = Savon.client(@options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (private)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sylfy/service/soapwsdl.rb', line 46

def method_missing(m, *args, &block)
    response = @client.call(m, message: args[0])
    if @options[:log_level] == :debug
        puts response.body 
        puts response.success?     # => false
        puts response.soap_fault?  # => true
        puts response.http_error?
    end
    
    if response.body[:"#{m}_response"].has_key?(:"#{m}_return")
        result = response.body[:"#{m}_response"][:"#{m}_return"]
    else
        result = response.body[:"#{m}_response"][:return]
    end
    
    if result.class == Hash
        result.delete_if {|k, v| k.to_s =~ /^@/}
        return result.empty? ? "" : result
    else
        return result
    end
end

Instance Method Details

#list_methodsObject

List of methods defined by WSDL



42
43
44
# File 'lib/sylfy/service/soapwsdl.rb', line 42

def list_methods
    @client.operations
end