Class: AutotaskApi::Client

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

Constant Summary collapse

NAMESPACE =
'http://autotask.net/ATWS/v1_6/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|@config| ... } ⇒ Client

Returns a new instance of Client.

Yields:



16
17
18
19
# File 'lib/autotask_api/client.rb', line 16

def initialize
  @config = AutotaskApi.config
  yield @config if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/autotask_api/client.rb', line 14

def config
  @config
end

Instance Method Details

#call(operation, message = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/autotask_api/client.rb', line 32

def call(operation, message = {})
  savon_client.call(
    operation,
    message: message,
    attributes: { xmlns: NAMESPACE }
  )
end

#savon_clientObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/autotask_api/client.rb', line 21

def savon_client
  @savon_client ||= Savon.client(
    wsdl: config.wsdl,
    logger: Rails.logger,
    log_level: :debug,
    log: config.debug,
    basic_auth: [config.username, config.password],
    soap_header: soap_header
  )
end

#soap_headerObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/autotask_api/client.rb', line 40

def soap_header
  return nil unless config.integration_code

  xml = Nokogiri::XML::Builder.new do |xml|
    xml.AutotaskIntegrations xmlns: NAMESPACE do
      xml.IntegrationCode config.integration_code
    end
  end

  xml.doc.root.to_s
end