Skip to content

MSPCFO/autotask_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutotaskApi

Short description and motivation.

Usage

How to use my plugin.

Installation

Add this line to your application's Gemfile:

gem 'autotask_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install autotask_api

Query

See the "Query XML elements and attributes" section of the Autotask API Users Guide for more information.

Simple field test

SQL:

firstname = 'Joe'

Objects:

e1 = AutotaskApi::Expression.new('firstname', 'equals', 'Joe')
c = AutotaskApi::Condition.new(e1)

AutotaskApi::Contact.where(c)

Hash:

AutotaskApi::Condition.from_hash(
    expressions: [
        { field: 'firstname', operator: 'equals', value: 'Joe' }
    ]
)

Multiple Field Test

SQL:

firstname = ‘Joe’ AND lastname = ‘Smith’

Objects:

e1 = AutotaskApi::Expression.new('firstname', 'equals', 'Joe')
e2 = AutotaskApi::Expression.new('lastname', 'equals', 'Smith')
c = AutotaskApi::Condition.new([e1, e2])

AutotaskApi::Contact.where(c)

Hash:

c = AutotaskApi::Condition.from_hash(
    expressions: [
      { field: 'firstname', operator: 'equals', value: 'Joe' },
      { field: 'lastname', operator: 'equals', value: 'Smith' }
    ]
)

AutotaskApi::Contact.where(c)

Multiple Fields combined with OR

SQL:

firstname = ‘Joe’ OR lastname = ‘Brown’

Objects:

e1 = AutotaskApi::Expression.new('firstname', 'equals', 'Joe')
e2 = AutotaskApi::Expression.new('lastname', 'equals', 'Brown')
c = AutotaskApi::Condition.new([e1, e2], 'OR')

AutotaskApi::Contact.where(c)

Hash:

c = AutotaskApi::Condition.from_hash(
    expressions: [
        { field: 'firstname', operator: 'equals', value: 'Joe' },
        { field: 'lastname', operator: 'equals', value: 'Brown' }
    ],
    operator: 'OR'
)

AutotaskApi::Contact.where(c)

Nested Conditions

SQL:

(
  firstname = ‘Joe’
  OR
  (
    (firstname = ‘Larry’ and lastname = ‘Brown’)
    OR
    (firstname = ‘Mary’ and lastname = ‘Smith’)
  )
)
# AND city != 'Albany'

Objects:

e1 = AutotaskApi::Expression.new('firstname', 'equals', 'Larry')
e2 = AutotaskApi::Expression.new('lastname', 'equals', 'Brown')
c1 = AutotaskApi::Condition.new([e1, e2])

e3 = AutotaskApi::Expression.new('firstname', 'equals', 'Mary')
e4 = AutotaskApi::Expression.new('lastname', 'equals', 'Smith')
c2 = AutotaskApi::Condition.new([e3, e4])

c3 = AutotaskApi::Condition.new([c1, c2], 'OR')

e5 = AutotaskApi::Expression.new('firstname', 'equals', 'Joe')
c4 = AutotaskApi::Condition.new([e5, c3], 'OR')

e6 = AutotaskApi::Expression.new('city', 'notequal', 'Albany')
c5 = AutotaskApi::Condition.new([c4, e6])

AutotaskApi::Query.new('contact', c5).fetch

Hash:

c = AutotaskApi::Condition.from_hash(
    expressions: [
        {
            expressions: [
                { field: 'firstname', operator: 'equals', value: 'Joe' },
                {
                    expressions: [
                        {
                            expressions: [
                                { field: 'firstname', operator: 'equals', value: 'Larry' },
                                { field: 'lastname', operator: 'equals', value: 'Brown' }
                            ]
                        },
                        {
                            expressions: [
                                { field: 'firstname', operator: 'equals', value: 'Marry' },
                                { field: 'lastname', operator: 'equals', value: 'Smith' }
                            ]
                        }
                    ],
                    operator: 'OR'
                }
            ],
            operator: 'OR'
        },
        { field: 'city', operator: 'notequal', value: 'Albany' }
    ]
)

AutotaskApi::Contact.where(c)

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.

About

Autotask API Wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •