class AutotaskRuby::Client

the primary client that interfaces with the SOAP Client that will interface with AutoTask.

Attributes

headers[RW]
logger[RW]
soap_client[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/autotask_ruby/client.rb, line 11
def initialize(options = {})
  @headers = {
    'tns:AutotaskIntegrations' =>
        {
          'tns:IntegrationCode' => options[:integration_code]
        }
  }

  @ssl_version = options[:ssl_version] || :TLSv1_2
  @endpoint = options[:endpoint] || 'https://webservices.autotask.net/ATServices/1.5/atws.asmx'

  # Override optional Savon attributes
  savon_options = {}
  %w[read_timeout open_timeout proxy raise_errors log_level basic_auth log raise_errors].each do |prop|
    key = prop.to_sym
    savon_options[key] = options[key] if options.key?(key)
  end

  @soap_client = Savon.client({
    wsdl: './atws.wsdl',
    soap_header: @headers,
    namespaces: { xmlns: AutotaskRuby.configuration.namespace },
    logger: Logger.new($stdout),
    raise_errors: false,
    log: options[:log] || true,
    log_level: options[:log_level] || :info,
    endpoint: @endpoint,
    ssl_version: @ssl_version # Sets ssl_version for HTTPI adapter
  }.update(savon_options))
end

Public Instance Methods

create(entity_xml) click to toggle source

creates an entity in AutoTask.

# File lib/autotask_ruby/client.rb, line 101
def create(entity_xml)
  result = @soap_client.call(:create, message: "<Entities>#{entity_xml}</Entities>")
  CreateResponse.new(@client, result)
end
delete(entity_type, *ids) click to toggle source

@param entity_type

include the entity type. ServiceCall, Appointment, etc.

@param ids

One or more entity ID's that should be deleted.

@return

AutotaskRuby::DeleteResponse
# File lib/autotask_ruby/client.rb, line 77
def delete(entity_type, *ids)
  entities = ++''
  ids.each do |id|
    entities << "<Entity xsi:type=\"#{entity_type}\"><id xsi:type=\"xsd:int\">#{id}</id></Entity>"
  end
  resp = @soap_client.call(:delete, message: "<Entities>#{entities}</Entities>")
  AutotaskRuby::DeleteResponse.new(@client, resp)
end
find(entity, id) click to toggle source

@param entity, id

pass in the entity_type, I.E. AccountToDo, Resource, etc. and the ID of the entity.

@return Entity Returns a single Entity if a match was found. Returns nil if no match is found.

# File lib/autotask_ruby/client.rb, line 53
def find(entity, id)
  response = query(entity.to_s, id)

  return nil if response.entities.empty?

  response.entities.first
end
operations() click to toggle source

Public: Get the names of all wsdl operations. List all available operations from the atws.wsdl

# File lib/autotask_ruby/client.rb, line 44
def operations
  @soap_client.operations
end
query(entity_type, field = 'id', operation = 'equals', value) click to toggle source

@param entity_type and value Other parameters, are optional.

full set of parameters include entity_type, field, operation, value.

Queries the Autotask QUERY API. Returns a QueryResponse result set. @return AutotaskRuby::Response.

# File lib/autotask_ruby/client.rb, line 66
def query(entity_type, field = 'id', operation = 'equals', value)
  result = @soap_client.call(:query, message: "<sXML><![CDATA[<queryxml><entity>#{entity_type}</entity><query><field>#{field}<expression op=\"#{operation}\">#{value}</expression></field></query></queryxml>]]></sXML>")
  AutotaskRuby::QueryResponse.new(self, result)
end
query_for(message) click to toggle source
# File lib/autotask_ruby/client.rb, line 86
def query_for(message)
  result = @soap_client.call(:query, message: message)
  AutotaskRuby::QueryResponse.new(self, result)
end
threshold_and_usage_info() click to toggle source
# File lib/autotask_ruby/client.rb, line 106
def threshold_and_usage_info
  result = @soap_client.call(:get_threshold_and_usage_info)
  ThresholdAndUsageInfoResponse.new(@client, result)
end
update(entity_xml) click to toggle source

updates the entity in the AutoTask API. All fields are iterated and this builds the XML message that is sent to AutoTask. Any field that is not filled out will be sent as empty. This means that it will wipe any value that AutoTask has for that field.

# File lib/autotask_ruby/client.rb, line 95
def update(entity_xml)
  result = @soap_client.call(:update, message: "<Entities>#{entity_xml}</Entities>")
  UpdateResponse.new(@client, result)
end