Class: AutotaskAPI::Client

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

Constant Summary collapse

NAMESPACE =
'http://autotask.net/ATWS/v1_5/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Client

Returns a new instance of Client

Yields:

  • (_self)

Yield Parameters:


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/autotask_api/client.rb', line 6

def initialize
  yield self
  self.savon_client ||= Savon.client do |c|
    c.basic_auth basic_auth
    c.wsdl wsdl
    c.pretty_print_xml true
    c.log !!log
    c.read_timeout 30
    c.open_timeout 30
  end
  Entity.client ||= self
end

Instance Attribute Details

#basic_authObject

Returns the value of attribute basic_auth


4
5
6
# File 'lib/autotask_api/client.rb', line 4

def basic_auth
  @basic_auth
end

#logObject

Returns the value of attribute log


4
5
6
# File 'lib/autotask_api/client.rb', line 4

def log
  @log
end

#queryObject

Returns the value of attribute query


4
5
6
# File 'lib/autotask_api/client.rb', line 4

def query
  @query
end

#savon_clientObject

Returns the value of attribute savon_client


4
5
6
# File 'lib/autotask_api/client.rb', line 4

def savon_client
  @savon_client
end

#wsdlObject

Returns the value of attribute wsdl


4
5
6
# File 'lib/autotask_api/client.rb', line 4

def wsdl
  @wsdl
end

Instance Method Details

#create(xml) ⇒ Object


29
30
31
32
# File 'lib/autotask_api/client.rb', line 29

def create(xml)
  savon_client.call :create, message: "<Entities>#{xml}</Entities>",
    attributes: { xmlns: NAMESPACE }
end

#entities_for(query) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/autotask_api/client.rb', line 34

def entities_for(query)
  self.query = query

  entities = response.xpath '//Autotask:Entity',
    Autotask: NAMESPACE

  return [] if entities.blank?

  klass = ('AutotaskAPI::' + entities.first.attribute('type').to_s).constantize
  entities.collect do |entity|
    klass.new entity
  end
end

#field_info(entity_name) ⇒ Object


48
49
50
# File 'lib/autotask_api/client.rb', line 48

def field_info(entity_name)
  savon_client.call :get_field_info, message: { psObjectType: entity_name }
end

#responseObject


19
20
21
22
# File 'lib/autotask_api/client.rb', line 19

def response
  savon_client.call :query, message: query,
    attributes: { xmlns: NAMESPACE }
end

#udf_info(entity_name) ⇒ Object


52
53
54
# File 'lib/autotask_api/client.rb', line 52

def udf_info(entity_name)
  savon_client.call :get_udf_info, message: { psTable: entity_name }
end

#update(xml) ⇒ Object


24
25
26
27
# File 'lib/autotask_api/client.rb', line 24

def update(xml)
  savon_client.call :update, message: "<Entities>#{xml}</Entities>",
    attributes: { xmlns: NAMESPACE }
end

#zone_info(user_name = nil) ⇒ Object


56
57
58
59
# File 'lib/autotask_api/client.rb', line 56

def zone_info(user_name = nil)
  savon_client.call :get_zone_info,
    message: { 'UserName' => user_name || basic_auth.first }
end