Sha256: 5dad4b9aadd0081ab64ac2b602f99f610767f9f3865c06f3b07096d6d53ff325

Contents?: true

Size: 819 Bytes

Versions: 13

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

module AutotaskRuby
  module Query
    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

    # @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.
    def find(entity, field = 'id', id)
      response = query(entity, field, id)
      return nil if response.entities.empty?

      response.entities.first
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
autotask_ruby-2.4.2 lib/autotask_ruby/query.rb
autotask_ruby-2.4.1 lib/autotask_ruby/query.rb
autotask_ruby-2.4.0 lib/autotask_ruby/query.rb
autotask_ruby-2.3.2 lib/autotask_ruby/query.rb
autotask_ruby-2.3.1 lib/autotask_ruby/query.rb
autotask_ruby-2.3.0 lib/autotask_ruby/query.rb
autotask_ruby-2.2.0 lib/autotask_ruby/query.rb
autotask_ruby-2.1.3 lib/autotask_ruby/query.rb
autotask_ruby-2.1.2 lib/autotask_ruby/query.rb
autotask_ruby-2.1.1 lib/autotask_ruby/query.rb
autotask_ruby-2.1.0 lib/autotask_ruby/query.rb
autotask_ruby-2.0.1 lib/autotask_ruby/query.rb
autotask_ruby-2.0.0 lib/autotask_ruby/query.rb