Module: AutotaskRuby::Query

Included in:
AccountToDo, Resource, ServiceCall, Ticket
Defined in:
lib/autotask_ruby/query.rb

Instance Method Summary collapse

Instance Method Details

#find(entity, field = 'id', 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



15
16
17
18
19
20
# File 'lib/autotask_ruby/query.rb', line 15

def find(entity, field = 'id', id)
  response = query(entity, field, id)
  return nil if response.entities.empty?

  response.entities.first
end

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



5
6
7
8
# File 'lib/autotask_ruby/query.rb', line 5

def query(entity_type, field = 'id', op = 'equals', value)
  result = @client.soap_client.call(:query, message: "<sXML><![CDATA[<queryxml><entity>#{entity_type}</entity><query><field>#{field}<expression op=\"#{op}\">#{value}</expression></field></query></queryxml>]]></sXML>")
  AutotaskRuby::QueryResponse.new(@client, result)
end