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.
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copied from https://github.com/scoop/autotask_api/blob/master/lib/autotask_api/query_xml.rb
4
+ # Thank you for the great work.
5
+
6
+ module AutotaskRuby
7
+ class QueryXML
8
+ Condition = Struct.new(:field, :op, :expression)
9
+ attr_accessor :entity, :op, :field, :expression, :conditions
10
+
11
+ def initialize
12
+ yield self
13
+ self.op ||= 'equals'
14
+ end
15
+
16
+ def add_condition(field, op, expression)
17
+ self.conditions ||= []
18
+ self.conditions << Condition.new(field, op, expression)
19
+ end
20
+
21
+ def to_s
22
+ Nokogiri::XML::Builder.new do
23
+ sXML do
24
+ cdata(Nokogiri::XML::Builder.new do |xml|
25
+ xml.queryxml do
26
+ xml.entity entity
27
+ xml.query do
28
+ if field
29
+ xml.field field do
30
+ xml.expression expression, op: op
31
+ end
32
+ else
33
+ conditions.each do |condition|
34
+ xml.condition do
35
+ xml.field condition.field do
36
+ xml.expression condition.expression,
37
+ op: condition.op
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end.doc.root)
45
+ end
46
+ end.doc.root.to_xml
47
+ end
48
+ end
49
+ end
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutotaskRuby
4
- # Represents the Autotask Entity Resource
5
- class Resource
6
- include AutotaskRuby::Entity
7
- include AutotaskRuby::Query
4
+ # Represents the Autotask Entity Resource
5
+ class Resource
6
+ include AutotaskRuby::Entity
7
+ include AutotaskRuby::Query
8
8
 
9
- FIELDS = %i[id Email Email2 Email3 FirstName HomePhone Initials LastName LocationID MiddleName
10
- MobilePhone OfficeExtension OfficePhone ResourceType Title UserName UserType Active].freeze
11
- .each do |field|
12
- self.attr_accessor :"#{field.to_s.underscore}"
13
- end
9
+ FIELDS = %i[id Email Email2 Email3 FirstName HomePhone Initials LastName LocationID MiddleName
10
+ MobilePhone OfficeExtension OfficePhone ResourceType Title UserName UserType Active].freeze
11
+ .each do |field|
12
+ attr_accessor :"#{field.to_s.underscore}"
13
+ end
14
14
 
15
- def post_initialize
16
- has_many :account_to_dos, foreign_key: 'AssignedToResourceID'
17
- has_many :appointments, foreign_key: 'ResourceID'
18
- has_many :tickets, foreign_key: 'AssignedResourceID'
19
- has_many :tasks, foreign_key: 'AssignedResourceID'
20
- end
15
+ def post_initialize
16
+ has_many :account_to_dos, foreign_key: 'AssignedToResourceID'
17
+ has_many :appointments, foreign_key: 'ResourceID'
18
+ has_many :tickets, foreign_key: 'AssignedResourceID'
19
+ has_many :tasks, foreign_key: 'AssignedResourceID'
21
20
  end
21
+ end
22
22
  end
@@ -1,28 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutotaskRuby
2
- module Response
3
- include Constants
4
- attr_accessor :entity_type, :errors, :return_code, :entities
4
+ module Response
5
+ include Constants
6
+ attr_accessor :entity_type, :errors, :return_code, :entities
5
7
 
6
- def initialize(client, response)
7
- @client = client
8
- @entities = []
9
- @errors = response.xpath('//Autotask:Errors', Autotask: AutotaskRuby.configuration.namespace).text
10
- @return_code = response.xpath('//Autotask:ReturnCode', Autotask: AutotaskRuby.configuration.namespace).text.to_i
11
- @entity_type = response.xpath('//Autotask:EntityResultType', Autotask: AutotaskRuby.configuration.namespace).text.classify
12
- parse_entities(response.xpath('//Autotask:Entity', Autotask: AutotaskRuby.configuration.namespace))
13
- end
8
+ def initialize(client, response)
9
+ @client = client
10
+ @entities = []
11
+ @errors = response.xpath('//Autotask:Errors', Autotask: AutotaskRuby.configuration.namespace).text
12
+ @return_code = response.xpath('//Autotask:ReturnCode', Autotask: AutotaskRuby.configuration.namespace).text.to_i
13
+ @entity_type = response.xpath('//Autotask:EntityResultType', Autotask: AutotaskRuby.configuration.namespace).text.classify
14
+ parse_entities(response.xpath('//Autotask:Entity', Autotask: AutotaskRuby.configuration.namespace))
15
+ end
14
16
 
15
- private
17
+ private
16
18
 
17
- def parse_entities(results)
18
- return [] if results.blank?
19
+ def parse_entities(results)
20
+ return [] if results.blank?
19
21
 
20
- klass = ('AutotaskRuby::' + results.first.attribute('type').to_s).constantize
21
- results.collect do |entity|
22
- obj = klass.new(client: @client)
23
- obj.build(entity)
24
- @entities.push(obj)
25
- end
26
- end
22
+ klass = ('AutotaskRuby::' + results.first.attribute('type').to_s).constantize
23
+ results.collect do |entity|
24
+ obj = klass.new(client: @client)
25
+ obj.build(entity)
26
+ @entities.push(obj)
27
+ end
27
28
  end
29
+ end
28
30
  end
@@ -1,24 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutotaskRuby
2
- # Represents the Autotask Entity ServiceCall
3
- class ServiceCall
4
- include Entity
5
- include Query
4
+ # Represents the Autotask Entity ServiceCall
5
+ class ServiceCall
6
+ include Entity
7
+ include Query
6
8
 
7
- FIELDS = %i[id AccountID StartDateTime EndDateTime Description Complete CreateDateTime LastModifiedDateTime Duration Status].freeze
8
- .each do |field|
9
- self.attr_accessor :"#{field.to_s.underscore}"
10
- end
9
+ FIELDS = %i[id AccountID StartDateTime EndDateTime Description Complete CreateDateTime LastModifiedDateTime Duration Status].freeze
10
+ .each do |field|
11
+ attr_accessor :"#{field.to_s.underscore}"
12
+ end
11
13
 
12
- # Returns the associated ResourceID.
13
- def resource_id
14
- service_call_ticket = find('ServiceCallTicket', 'ServiceCallId', self.id)
15
- service_call_ticket_resource = find('ServiceCallTicketResource', 'ServiceCallTicketId', service_call_ticket.id)
16
- service_call_ticket_resource.resource_id
17
- end
14
+ # Returns the associated ResourceID.
15
+ def resource_id
16
+ service_call_ticket = find('ServiceCallTicket', 'ServiceCallId', id)
17
+ service_call_ticket_resource = find('ServiceCallTicketResource', 'ServiceCallTicketId', service_call_ticket.id)
18
+ service_call_ticket_resource.resource_id
19
+ end
18
20
 
19
- # Returns the associated Resource
20
- def resource
21
- find('Resource', resource_id)
22
- end
21
+ # Returns the associated Resource
22
+ def resource
23
+ find('Resource', resource_id)
23
24
  end
25
+ end
24
26
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutotaskRuby
2
- # Represents the Autotask Entity ServiceCallTicket
3
- class ServiceCallTicket
4
- include Entity
4
+ # Represents the Autotask Entity ServiceCallTicket
5
+ class ServiceCallTicket
6
+ include Entity
5
7
 
6
- FIELDS = %i[id ServiceCallID TicketID].freeze
7
- .each do |field|
8
- self.attr_accessor :"#{field.to_s.underscore}"
9
- end
8
+ FIELDS = %i[id ServiceCallID TicketID].freeze
9
+ .each do |field|
10
+ attr_accessor :"#{field.to_s.underscore}"
10
11
  end
12
+ end
11
13
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutotaskRuby
2
- # Represents the Autotask Entity ServiceCallTicketResource
3
- class ServiceCallTicketResource
4
- include Entity
4
+ # Represents the Autotask Entity ServiceCallTicketResource
5
+ class ServiceCallTicketResource
6
+ include Entity
5
7
 
6
- FIELDS = %i[id ServiceCallTicketID ResourceID].freeze
7
- .each do |field|
8
- self.attr_accessor :"#{field.to_s.underscore}"
9
- end
8
+ FIELDS = %i[id ServiceCallTicketID ResourceID].freeze
9
+ .each do |field|
10
+ attr_accessor :"#{field.to_s.underscore}"
10
11
  end
12
+ end
11
13
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutotaskRuby
4
- # Represents the Autotask Entity Task
5
- class Task
6
- include Entity
4
+ # Represents the Autotask Entity Task
5
+ class Task
6
+ include Entity
7
7
 
8
- FIELDS = %i[id AllocationCodeID AssignedResourceID CreateDateTime DepartmentID Description EstimatedHours
9
- LastActivityDateTime ProjectID Status TaskNumber TaskType Title ].freeze
10
- .each do |field|
11
- self.attr_accessor :"#{field.to_s.underscore}"
12
- end
8
+ FIELDS = %i[id AllocationCodeID AssignedResourceID CreateDateTime DepartmentID Description EstimatedHours
9
+ LastActivityDateTime ProjectID Status TaskNumber TaskType Title ].freeze
10
+ .each do |field|
11
+ attr_accessor :"#{field.to_s.underscore}"
12
+ end
13
13
 
14
- def post_initialize
15
- belongs_to :resource
16
- belongs_to :project
17
- end
14
+ def post_initialize
15
+ belongs_to :resource
16
+ belongs_to :project
18
17
  end
18
+ end
19
19
  end
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutotaskRuby
4
- # Represents the Autotask Entity Ticket
5
- class Ticket
6
- include Entity
4
+ # Represents the Autotask Entity Ticket
5
+ class Ticket
6
+ include Entity
7
7
 
8
- FIELDS = %i[id AccountID ContactID CreateDate Description DueDateTime LastActivityDate AssignedResourceID Status TicketNumber Title].freeze
9
- .each do |field|
10
- self.attr_accessor :"#{field.to_s.underscore}"
11
- end
8
+ FIELDS = %i[id AccountID ContactID CreateDate Description DueDateTime LastActivityDate AssignedResourceID Status TicketNumber Title].freeze
9
+ .each do |field|
10
+ attr_accessor :"#{field.to_s.underscore}"
11
+ end
12
12
 
13
- def post_initialize
14
- belongs_to :account
15
- belongs_to :contact
16
- end
13
+ def post_initialize
14
+ belongs_to :account
15
+ belongs_to :contact
17
16
  end
17
+ end
18
18
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AutotaskRuby
4
+ class UpdateResponse
5
+ include Response
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutotaskRuby
4
- VERSION = '0.1.0'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -1,31 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutotaskRuby
4
- class ZoneInfo
5
- attr_reader :raw_result
4
+ class ZoneInfo
5
+ attr_reader :raw_result
6
6
 
7
- ENDPOINT = 'https://webservices.autotask.net/ATServices/1.5/atws.asmx'
7
+ ENDPOINT = 'https://webservices.autotask.net/ATServices/1.5/atws.asmx'
8
8
 
9
- def initialize(username)
10
- @client = Savon.client(wsdl: './atws.wsdl', endpoint: ENDPOINT)
11
- @raw_result = @client.call(:get_zone_info, message: { 'UserName' => username })
12
- @zone_info = @raw_result.body[:get_zone_info_response][:get_zone_info_result]
13
- end
9
+ def initialize(username)
10
+ @client = Savon.client(wsdl: './atws.wsdl', endpoint: ENDPOINT)
11
+ @raw_result = @client.call(:get_zone_info, message: {'UserName' => username})
12
+ @zone_info = @raw_result.body[:get_zone_info_response][:get_zone_info_result]
13
+ end
14
14
 
15
- def error_code
16
- @zone_info[:error_code].to_i
17
- end
15
+ def error_code
16
+ @zone_info[:error_code].to_i
17
+ end
18
18
 
19
- def web_url
20
- @zone_info[:web_url]
21
- end
19
+ def web_url
20
+ @zone_info[:web_url]
21
+ end
22
22
 
23
- def url
24
- @zone_info[:url]
25
- end
23
+ def url
24
+ @zone_info[:url]
25
+ end
26
26
 
27
- def method_missing(method, *_args)
28
- @zone_info[method]
29
- end
27
+ # @param [Object] method
28
+ # @param [Array] _args
29
+ # @return [Object]
30
+ def method_missing(method, *_args)
31
+ @zone_info[method]
30
32
  end
33
+ end
31
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autotask_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared L Jennings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2020-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -235,6 +235,7 @@ files:
235
235
  - lib/autotask_ruby/project.rb
236
236
  - lib/autotask_ruby/query.rb
237
237
  - lib/autotask_ruby/query_response.rb
238
+ - lib/autotask_ruby/query_xml.rb
238
239
  - lib/autotask_ruby/resource.rb
239
240
  - lib/autotask_ruby/response.rb
240
241
  - lib/autotask_ruby/service_call.rb
@@ -242,6 +243,7 @@ files:
242
243
  - lib/autotask_ruby/service_call_ticket_resource.rb
243
244
  - lib/autotask_ruby/task.rb
244
245
  - lib/autotask_ruby/ticket.rb
246
+ - lib/autotask_ruby/update_response.rb
245
247
  - lib/autotask_ruby/version.rb
246
248
  - lib/autotask_ruby/zone_info.rb
247
249
  homepage: https://github.com/trepidity/autotask_ruby
@@ -265,8 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
267
  - !ruby/object:Gem::Version
266
268
  version: '0'
267
269
  requirements: []
268
- rubyforge_project:
269
- rubygems_version: 2.7.8
270
+ rubygems_version: 3.1.2
270
271
  signing_key:
271
272
  specification_version: 4
272
273
  summary: A ruby client for the Autotask API