Class: Savon::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/client.rb

Overview

The main entry point for Savon.

Holds global configuration, owns the WSDL document, and dispatches named operations. A single Client instance is typically shared across multiple calls to the same service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(globals = {}, &block) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/savon/client.rb', line 17

def initialize(globals = {}, &block)
  unless globals.is_a? Hash
    raise_version1_initialize_error! globals
  end

  set_globals(globals, block)
  @globals.validate_transport!

  unless wsdl_or_endpoint_and_namespace_specified?
    raise_initialization_error!
  end

  build_wsdl_document
end

Instance Attribute Details

#globalsObject (readonly)

Returns the value of attribute globals.



32
33
34
# File 'lib/savon/client.rb', line 32

def globals
  @globals
end

#wsdlObject (readonly)

Returns the value of attribute wsdl.



32
33
34
# File 'lib/savon/client.rb', line 32

def wsdl
  @wsdl
end

Instance Method Details

#build_request(operation_name, locals = {}, &block) ⇒ Object



64
65
66
# File 'lib/savon/client.rb', line 64

def build_request(operation_name, locals = {}, &block)
  operation(operation_name).request(locals, &block)
end

#call(operation_name, locals = {}, &block) ⇒ Object



55
56
57
# File 'lib/savon/client.rb', line 55

def call(operation_name, locals = {}, &block)
  operation(operation_name).call(locals, &block)
end

#faradayObject

Returns the memoized Faraday::Connection for this client. Callers use this to configure middleware, SSL, auth, timeouts, and any other transport-level concern before making calls. Raises ArgumentError if transport is not :faraday.



38
39
40
41
42
43
44
# File 'lib/savon/client.rb', line 38

def faraday
  unless @globals[:transport] == :faraday
    raise ArgumentError, "client.faraday is only available when transport: :faraday is set"
  end

  @faraday ||= ::Faraday.new
end

#operation(operation_name) ⇒ Object



51
52
53
# File 'lib/savon/client.rb', line 51

def operation(operation_name)
  Operation.create(operation_name, @wsdl, @globals, build_transport)
end

#operationsObject



46
47
48
49
# File 'lib/savon/client.rb', line 46

def operations
  raise_missing_wsdl_error! unless @wsdl.document?
  @wsdl.soap_actions
end

#service_nameObject



59
60
61
62
# File 'lib/savon/client.rb', line 59

def service_name
  raise_missing_wsdl_error! unless @wsdl.document?
  @wsdl.service_name
end