Class: AutotaskRuby::Client

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



9
10
11
# File 'lib/autotask_ruby/client.rb', line 9

def headers
  @headers
end

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/autotask_ruby/client.rb', line 9

def logger
  @logger
end

#soap_clientObject

Returns the value of attribute soap_client.



9
10
11
# File 'lib/autotask_ruby/client.rb', line 9

def soap_client
  @soap_client
end

Instance Method Details

#create(entity_xml) ⇒ Object

creates an entity in AutoTask.



101
102
103
104
# 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) ⇒ Object

Returns AutotaskRuby::DeleteResponse.

Parameters:

  • entity_type

    include the entity type. ServiceCall, Appointment, etc.

  • ids

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

Returns:

  • AutotaskRuby::DeleteResponse



77
78
79
80
81
82
83
84
# 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) ⇒ Object

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

Parameters:

  • entity,

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

Returns:

  • Entity



53
54
55
56
57
58
59
# 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

#operationsObject

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



44
45
46
# File 'lib/autotask_ruby/client.rb', line 44

def operations
  @soap_client.operations
end

#query(entity_type, field = 'id', operation = 'equals', value) ⇒ Object

Other parameters, are optional.

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

Queries the Autotask QUERY API. Returns a QueryResponse result set.

Parameters:

  • entity_type

    and value

Returns:

  • AutotaskRuby::Response.



66
67
68
69
# 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) ⇒ Object



86
87
88
89
# 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_infoObject



106
107
108
109
# 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) ⇒ Object

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.



95
96
97
98
# 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