Class: AutotaskRuby::Client
- Inherits:
-
Object
- Object
- AutotaskRuby::Client
- 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
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#soap_client ⇒ Object
Returns the value of attribute soap_client.
Instance Method Summary collapse
-
#create(entity_xml) ⇒ Object
creates an entity in AutoTask.
-
#delete(entity_type, *ids) ⇒ Object
AutotaskRuby::DeleteResponse.
-
#find(entity, id) ⇒ Object
Returns a single Entity if a match was found.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#operations ⇒ Object
Public: Get the names of all wsdl operations.
-
#query(entity_type, field = 'id', operation = 'equals', value) ⇒ Object
Other parameters, are optional.
- #query_for(message) ⇒ Object
- #threshold_and_usage_info ⇒ Object
-
#update(entity_xml) ⇒ Object
updates the entity in the AutoTask API.
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( = {}) @headers = { 'tns:AutotaskIntegrations' => { 'tns:IntegrationCode' => [:integration_code] } } @ssl_version = [:ssl_version] || :TLSv1_2 @endpoint = [:endpoint] || 'https://webservices.autotask.net/ATServices/1.5/atws.asmx' # Override optional Savon attributes = {} %w[read_timeout open_timeout proxy raise_errors log_level basic_auth log raise_errors].each do |prop| key = prop.to_sym [key] = [key] if .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: [:log] || true, log_level: [:log_level] || :info, endpoint: @endpoint, ssl_version: @ssl_version # Sets ssl_version for HTTPI adapter }.update()) end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
9 10 11 |
# File 'lib/autotask_ruby/client.rb', line 9 def headers @headers end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/autotask_ruby/client.rb', line 9 def logger @logger end |
#soap_client ⇒ Object
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.
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.
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 |
#operations ⇒ Object
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.
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() result = @soap_client.call(:query, message: ) AutotaskRuby::QueryResponse.new(self, result) end |
#threshold_and_usage_info ⇒ Object
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 |