autotask_ruby 0.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.ruby-version +2 -1
- data/Gemfile.lock +64 -66
- data/lib/autotask_ruby.rb +3 -0
- data/lib/autotask_ruby/account.rb +7 -8
- data/lib/autotask_ruby/account_to_do.rb +22 -13
- data/lib/autotask_ruby/action_type.rb +7 -7
- data/lib/autotask_ruby/appointment.rb +10 -13
- data/lib/autotask_ruby/association.rb +35 -33
- data/lib/autotask_ruby/client.rb +97 -79
- data/lib/autotask_ruby/configuration.rb +18 -18
- data/lib/autotask_ruby/constants.rb +3 -3
- data/lib/autotask_ruby/contact.rb +16 -17
- data/lib/autotask_ruby/create_response.rb +5 -3
- data/lib/autotask_ruby/delete_response.rb +5 -3
- data/lib/autotask_ruby/entity.rb +107 -108
- data/lib/autotask_ruby/fields.rb +11 -11
- data/lib/autotask_ruby/project.rb +12 -13
- data/lib/autotask_ruby/query.rb +15 -15
- data/lib/autotask_ruby/query_response.rb +4 -4
- data/lib/autotask_ruby/query_xml.rb +49 -0
- data/lib/autotask_ruby/resource.rb +15 -15
- data/lib/autotask_ruby/response.rb +23 -21
- data/lib/autotask_ruby/service_call.rb +20 -18
- data/lib/autotask_ruby/service_call_ticket.rb +9 -7
- data/lib/autotask_ruby/service_call_ticket_resource.rb +9 -7
- data/lib/autotask_ruby/task.rb +12 -12
- data/lib/autotask_ruby/ticket.rb +11 -11
- data/lib/autotask_ruby/update_response.rb +7 -0
- data/lib/autotask_ruby/version.rb +1 -1
- data/lib/autotask_ruby/zone_info.rb +23 -20
- metadata +5 -4
@@ -1,25 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module AutotaskRuby
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :integration_code
|
6
|
+
attr_accessor :version
|
7
|
+
attr_accessor :namespace
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
def initialize
|
10
|
+
@integration_code = nil
|
11
|
+
@version = 1.5
|
12
|
+
@namespace = 'http://autotask.net/ATWS/v1_5/'
|
13
13
|
end
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def configure
|
21
|
-
yield(configuration)
|
22
|
-
end
|
16
|
+
class << self
|
17
|
+
def configuration
|
18
|
+
@configuration ||= Configuration.new
|
23
19
|
end
|
24
20
|
|
21
|
+
def configure
|
22
|
+
yield(configuration)
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
@@ -1,26 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AutotaskRuby
|
4
|
+
# Represents the Autotask Entity Contact
|
5
|
+
class Contact
|
6
|
+
include Entity
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
FIELDS = %i[id Active AddressLine City Country CreateDate EMailAddress Extension FirstName AccountID LastName MobilePhone Phone State Title ZipCode].freeze
|
10
|
-
.each do |field|
|
11
|
-
self.attr_accessor :"#{field.to_s.underscore}"
|
12
|
-
end
|
8
|
+
FIELDS = %i[id Active AddressLine City Country CreateDate EMailAddress Extension FirstName AccountID LastName MobilePhone Phone State Title ZipCode].freeze
|
9
|
+
.each do |field|
|
10
|
+
attr_accessor :"#{field.to_s.underscore}"
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def post_initialize
|
14
|
+
belongs_to :account
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def full_name
|
18
|
+
[@first_name, @last_name].join(' ')
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
def email
|
22
|
+
@e_mail_address
|
25
23
|
end
|
24
|
+
end
|
26
25
|
end
|
data/lib/autotask_ruby/entity.rb
CHANGED
@@ -1,113 +1,112 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AutotaskRuby
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
"<#{field_name}>#{field_value}</#{field_name}>"
|
111
|
-
end
|
4
|
+
# The base type for all objects represented by AutotaskRuby.
|
5
|
+
# This module should extend any object type being used with AutoTask.
|
6
|
+
module Entity
|
7
|
+
include AutotaskRuby::Constants
|
8
|
+
include AutotaskRuby::Association
|
9
|
+
|
10
|
+
FIELDS = %i[id].freeze
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.const_set :FIELDS, Entity::FIELDS unless base.const_defined?(:FIELDS)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@client = options if options.instance_of?(Client)
|
18
|
+
return unless options.is_a?(Hash)
|
19
|
+
|
20
|
+
options.each do |k, v|
|
21
|
+
instance_variable_set("@#{k}", v)
|
22
|
+
end
|
23
|
+
|
24
|
+
post_initialize
|
25
|
+
end
|
26
|
+
|
27
|
+
# default post_initialize methods.
|
28
|
+
# Other classes that implement the Entity Class may override this.
|
29
|
+
def post_initialize; end
|
30
|
+
|
31
|
+
# Iterates the fields of a Entity Class Type.
|
32
|
+
# The fields are turned into instance variables.
|
33
|
+
# Fields could include id, StartDateTime, Title, etc.
|
34
|
+
def build(entity)
|
35
|
+
self.class.const_get(:FIELDS).each do |field|
|
36
|
+
instance_variable_set("@#{field}".underscore, field_set(entity, field))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# updates the entity in the AutoTask API.
|
41
|
+
# All fields are iterated and this builds the XML message that is sent to AutoTask.
|
42
|
+
# Any field that is not filled out will be sent as empty. This means that it will wipe
|
43
|
+
# any value that AutoTask has for that field.
|
44
|
+
def update
|
45
|
+
@client.soap_client.call(:update, message: "<Entity xsi:type=\"#{self.class.to_s.demodulize}\">#{fields_to_xml}</Entity>")
|
46
|
+
end
|
47
|
+
|
48
|
+
# creates an entity in AutoTask.
|
49
|
+
def create
|
50
|
+
result = @client.soap_client.call(:create, message: "<Entity xsi:type=\"#{self.class.to_s.demodulize}\">#{fields_to_xml}</Entity>")
|
51
|
+
CreateResponse.new(@client, result)
|
52
|
+
end
|
53
|
+
|
54
|
+
# converts the AutoTask dateTime string value to a ActiveSupport::TimeWithZone object.
|
55
|
+
# All dateTimes in AutoTask are in the Eastern Timezone.
|
56
|
+
def to_date_time(arg)
|
57
|
+
Time.find_zone!('Eastern Time (US & Canada)').parse(arg)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Converts the specified field in the AutoTask XML response to the entity object field/attribute.
|
61
|
+
# @param
|
62
|
+
# - entity
|
63
|
+
# - field
|
64
|
+
def field_set(entity, field)
|
65
|
+
node = entity.xpath("Autotask:#{field}", Autotask: AutotaskRuby.configuration.namespace)
|
66
|
+
|
67
|
+
# entity may not contain all fields that are possible.
|
68
|
+
# Example: The entity may not have a contact specified.
|
69
|
+
return if node.blank?
|
70
|
+
|
71
|
+
return node.text.to_i if node.attr('type').blank? || node.attr('type').text.eql?('xsd:int')
|
72
|
+
return to_date_time(node.text) if node.attr('type').text.eql?('xsd:dateTime')
|
73
|
+
return node.text.to_f if node.attr('type').text.eql?('xsd:double')
|
74
|
+
return node.text.to_f if node.attr('type').text.eql?('xsd:decimal')
|
75
|
+
|
76
|
+
node.text
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_bool(arg)
|
80
|
+
return true if arg == true || arg =~ /(true|t|yes|y|1)$/i
|
81
|
+
return false if arg == false || arg.empty? || arg =~ /(false|f|no|n|0)$/i
|
82
|
+
|
83
|
+
raise ArgumentError, "invalid value for Boolean: \"#{arg}\""
|
84
|
+
end
|
85
|
+
|
86
|
+
# converts the entity attributes to XML representation.
|
87
|
+
# This is used when sending the object to the AutoTask API.
|
88
|
+
def fields_to_xml
|
89
|
+
str = ++''
|
90
|
+
|
91
|
+
self.class.const_get(:FIELDS).each do |field|
|
92
|
+
obj = instance_variable_get("@#{field}".underscore)
|
93
|
+
next unless obj
|
94
|
+
|
95
|
+
str << format_field_to_xml(field, obj)
|
96
|
+
end
|
97
|
+
str
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns the specified field as an XML element for the XML Body.
|
101
|
+
# I.E. <id>xxx</id>
|
102
|
+
# @param field_name
|
103
|
+
# the field name
|
104
|
+
# @param field_value
|
105
|
+
# the field value.
|
106
|
+
def format_field_to_xml(field_name, field_value)
|
107
|
+
return "<#{field_name}>#{field_value.strftime(AUTOTASK_TIME_FORMAT)}</#{field_name}>" if field_value.instance_of?(ActiveSupport::TimeWithZone)
|
108
|
+
|
109
|
+
"<#{field_name}>#{field_value}</#{field_name}>"
|
112
110
|
end
|
111
|
+
end
|
113
112
|
end
|
data/lib/autotask_ruby/fields.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AutotaskRuby
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
4
|
+
# Converts Autotask Entity Fields into methods.
|
5
|
+
module Fields
|
6
|
+
def field(method_name)
|
7
|
+
inst_variable_name = "@#{method_name}".to_sym
|
8
|
+
define_method method_name do
|
9
|
+
instance_variable_get inst_variable_name
|
10
|
+
end
|
11
|
+
define_method "#{method_name}=" do |new_value|
|
12
|
+
instance_variable_set inst_variable_name, new_value
|
13
|
+
end
|
15
14
|
end
|
15
|
+
end
|
16
16
|
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AutotaskRuby
|
4
|
+
# Represents the Autotask Entity Project
|
5
|
+
class Project
|
6
|
+
include Entity
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
EndDateTime Duration EstimatedTime Status ProjectLeadResourceID StatusDetail StatusDateTime].freeze
|
11
|
-
.each do |field|
|
12
|
-
self.attr_accessor :"#{field.to_s.underscore}"
|
13
|
-
end
|
8
|
+
FIELDS = %i[id ProjectName AccountID Type ProjectNumber Description CreateDateTime StartDateTime
|
9
|
+
EndDateTime Duration EstimatedTime Status ProjectLeadResourceID StatusDetail StatusDateTime].freeze
|
10
|
+
.each do |field|
|
11
|
+
attr_accessor :"#{field.to_s.underscore}"
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
def post_initialize
|
15
|
+
has_many :tasks
|
16
|
+
belongs_to :account
|
19
17
|
end
|
18
|
+
end
|
20
19
|
end
|
data/lib/autotask_ruby/query.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AutotaskRuby
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Query
|
5
|
+
def query(entity_type, field = 'id', op = 'equals', value)
|
6
|
+
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>")
|
7
|
+
AutotaskRuby::QueryResponse.new(@client, result)
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
# @param entity, id
|
11
|
+
# pass in the entity_type, I.E. AccountToDo, Resource, etc. and the ID of the entity.
|
12
|
+
# @return Entity
|
13
|
+
# Returns a single Entity if a match was found.
|
14
|
+
# Returns nil if no match is found.
|
15
|
+
def find(entity, field = 'id', id)
|
16
|
+
response = query(entity, field, id)
|
17
|
+
return nil if response.entities.empty?
|
18
18
|
|
19
|
-
|
20
|
-
end
|
19
|
+
response.entities.first
|
21
20
|
end
|
21
|
+
end
|
22
22
|
end
|