class Savon::Client

Attributes

globals[R]

Public Class Methods

new(globals = {}, &block) click to toggle source
# File lib/savon/client.rb, line 10
def initialize(globals = {}, &block)
  unless globals.kind_of? Hash
    raise_version1_initialize_error! globals
  end

  set_globals(globals, block)

  unless wsdl_or_endpoint_and_namespace_specified?
    raise_initialization_error!
  end

  build_wsdl_document
end

Public Instance Methods

build_request(operation_name, locals = {}, &block) click to toggle source
# File lib/savon/client.rb, line 44
def build_request(operation_name, locals = {}, &block)
  operation(operation_name).request(locals, &block)
end
call(operation_name, locals = {}, &block) click to toggle source
# File lib/savon/client.rb, line 35
def call(operation_name, locals = {}, &block)
  operation(operation_name).call(locals, &block)
end
operation(operation_name) click to toggle source
# File lib/savon/client.rb, line 31
def operation(operation_name)
  Operation.create(operation_name, @wsdl, @globals)
end
operations() click to toggle source
# File lib/savon/client.rb, line 26
def operations
  raise_missing_wsdl_error! unless @wsdl.document?
  @wsdl.soap_actions
end
service_name() click to toggle source
# File lib/savon/client.rb, line 39
def service_name
  raise_missing_wsdl_error! unless @wsdl.document?
  @wsdl.service_name
end

Private Instance Methods

build_wsdl_document() click to toggle source
# File lib/savon/client.rb, line 57
def build_wsdl_document
  @wsdl = Wasabi::Document.new

  @wsdl.document    = @globals[:wsdl]        if @globals.include? :wsdl
  @wsdl.endpoint    = @globals[:endpoint]    if @globals.include? :endpoint
  @wsdl.namespace   = @globals[:namespace]   if @globals.include? :namespace
  @wsdl.servicename = @globals[:servicename] if @globals.include? :servicename
  @wsdl.adapter     = @globals[:adapter]     if @globals.include? :adapter

  @wsdl.request = WSDLRequest.new(@globals).build
end
raise_initialization_error!() click to toggle source
# File lib/savon/client.rb, line 80
def raise_initialization_error!
  raise InitializationError,
        "Expected either a WSDL document or the SOAP endpoint and target namespace options.\n\n" \
        "Savon.client(wsdl: '/Users/me/project/service.wsdl')                              # to use a local WSDL document\n" \
        "Savon.client(wsdl: 'http://example.com?wsdl')                                     # to use a remote WSDL document\n" \
        "Savon.client(endpoint: 'http://example.com', namespace: 'http://v1.example.com')  # if you don't have a WSDL document"
end
raise_missing_wsdl_error!() click to toggle source
# File lib/savon/client.rb, line 88
def raise_missing_wsdl_error!
  raise "Unable to inspect the service without a WSDL document."
end
raise_version1_initialize_error!(object) click to toggle source
# File lib/savon/client.rb, line 73
def raise_version1_initialize_error!(object)
  raise InitializationError,
    "Some code tries to initialize Savon with the #{object.inspect} (#{object.class}) \n" \
    "Savon 2 expects a Hash of options for creating a new client and executing requests.\n" \
    "Please read the updated documentation for version 2: http://savonrb.com/version2.html"
end
set_globals(globals, block) click to toggle source
# File lib/savon/client.rb, line 50
def set_globals(globals, block)
  globals = GlobalOptions.new(globals)
  BlockInterface.new(globals).evaluate(block) if block

  @globals = globals
end
wsdl_or_endpoint_and_namespace_specified?() click to toggle source
# File lib/savon/client.rb, line 69
def wsdl_or_endpoint_and_namespace_specified?
  @globals.include?(:wsdl) || (@globals.include?(:endpoint) && @globals.include?(:namespace))
end