Class: Zm::Client::SoapBaseConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/connector/soap_base.rb

Direct Known Subclasses

SoapAccountConnector, SoapAdminConnector

Constant Summary collapse

BASESPACE =
'urn:zimbra'
HTTP_HEADERS =
{
  'Content-Type' => 'application/json; charset=utf-8',
  'User-Agent' => 'ZmRubyClient'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, soap_path) ⇒ SoapBaseConnector

Returns a new instance of SoapBaseConnector.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zm/client/connector/soap_base.rb', line 20

def initialize(url, soap_path)
  @verbose = false
  @timeout = 300

  @ssl_options = {
    verify: false,
    verify_hostname: false,
    verify_mode: OpenSSL::SSL::VERIFY_NONE
  }

  @url = url
  @soap_path = soap_path

  @context = SoapContext.new
end

Instance Attribute Details

#cache=(value) ⇒ Object (writeonly)

Sets the attribute cache

Parameters:

  • value

    the value to set the attribute cache to.



18
19
20
# File 'lib/zm/client/connector/soap_base.rb', line 18

def cache=(value)
  @cache = value
end

#contextObject (readonly)

Returns the value of attribute context.



17
18
19
# File 'lib/zm/client/connector/soap_base.rb', line 17

def context
  @context
end

#logger=(value) ⇒ Object (writeonly)

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



18
19
20
# File 'lib/zm/client/connector/soap_base.rb', line 18

def logger=(value)
  @logger = value
end

#timeout=(value) ⇒ Object (writeonly)

Sets the attribute timeout

Parameters:

  • value

    the value to set the attribute timeout to.



18
19
20
# File 'lib/zm/client/connector/soap_base.rb', line 18

def timeout=(value)
  @timeout = value
end

Instance Method Details

#http_client!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zm/client/connector/soap_base.rb', line 51

def http_client!
  @http_client = Faraday.new(
    url: @url,
    headers: HTTP_HEADERS,
    request: {
      timeout: @timeout
    },
    ssl: @ssl_options
  ) do |faraday|
    faraday.request :json
    faraday.response :logger, nil, { headers: true, bodies: true, errors: true } if @verbose
  end
end

#invoke(soap_element, error_handler = SoapError) ⇒ Object



40
41
42
# File 'lib/zm/client/connector/soap_base.rb', line 40

def invoke(soap_element, error_handler = SoapError)
  do_request(envelope(soap_element), error_handler)[:Body]
end

#target_invoke(soap_element, target_id, error_handler = SoapError) ⇒ Object



44
45
46
47
48
49
# File 'lib/zm/client/connector/soap_base.rb', line 44

def target_invoke(soap_element, target_id, error_handler = SoapError)
  @context.target_server(target_id)
  resp = invoke(soap_element, error_handler)
  @context.target_server(nil)
  resp
end

#verbose!Object



36
37
38
# File 'lib/zm/client/connector/soap_base.rb', line 36

def verbose!
  @verbose = true
end