KayakoClient 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/lib/kayako_client.rb +31 -0
  2. data/lib/kayako_client/base.rb +23 -0
  3. data/lib/kayako_client/custom_field.rb +14 -0
  4. data/lib/kayako_client/department.rb +18 -3
  5. data/lib/kayako_client/http/http.rb +14 -0
  6. data/lib/kayako_client/http/http_backend.rb +14 -0
  7. data/lib/kayako_client/http/http_client.rb +14 -0
  8. data/lib/kayako_client/http/http_response.rb +14 -0
  9. data/lib/kayako_client/http/net_http.rb +14 -0
  10. data/lib/kayako_client/knowledgebase_article.rb +131 -0
  11. data/lib/kayako_client/knowledgebase_attachment.rb +59 -0
  12. data/lib/kayako_client/knowledgebase_category.rb +71 -0
  13. data/lib/kayako_client/knowledgebase_comment.rb +32 -0
  14. data/lib/kayako_client/mixins/api.rb +14 -0
  15. data/lib/kayako_client/mixins/article_client.rb +76 -0
  16. data/lib/kayako_client/mixins/attachment.rb +16 -1
  17. data/lib/kayako_client/mixins/authentication.rb +14 -0
  18. data/lib/kayako_client/mixins/client.rb +300 -0
  19. data/lib/kayako_client/mixins/comment_object.rb +102 -0
  20. data/lib/kayako_client/mixins/convert_api.rb +39 -0
  21. data/lib/kayako_client/mixins/creator_api.rb +44 -0
  22. data/lib/kayako_client/mixins/knowledgebase_article_api.rb +69 -0
  23. data/lib/kayako_client/mixins/knowledgebase_category_client.rb +51 -0
  24. data/lib/kayako_client/mixins/logger.rb +14 -0
  25. data/lib/kayako_client/mixins/news_category_client.rb +51 -0
  26. data/lib/kayako_client/mixins/news_client.rb +51 -0
  27. data/lib/kayako_client/mixins/object.rb +24 -7
  28. data/lib/kayako_client/mixins/post_client.rb +14 -0
  29. data/lib/kayako_client/mixins/staff_visibility_api.rb +14 -0
  30. data/lib/kayako_client/mixins/ticket_api.rb +14 -0
  31. data/lib/kayako_client/mixins/ticket_client.rb +14 -0
  32. data/lib/kayako_client/mixins/troubleshooter_step_api.rb +69 -0
  33. data/lib/kayako_client/mixins/troubleshooter_step_client.rb +76 -0
  34. data/lib/kayako_client/mixins/user_visibility_api.rb +14 -0
  35. data/lib/kayako_client/news_category.rb +29 -0
  36. data/lib/kayako_client/news_comment.rb +32 -0
  37. data/lib/kayako_client/news_item.rb +81 -0
  38. data/lib/kayako_client/news_subscriber.rb +33 -0
  39. data/lib/kayako_client/staff.rb +14 -0
  40. data/lib/kayako_client/staff_group.rb +14 -0
  41. data/lib/kayako_client/ticket.rb +24 -1
  42. data/lib/kayako_client/ticket_attachment.rb +18 -0
  43. data/lib/kayako_client/ticket_count.rb +14 -0
  44. data/lib/kayako_client/ticket_custom_field.rb +14 -0
  45. data/lib/kayako_client/ticket_note.rb +14 -1
  46. data/lib/kayako_client/ticket_post.rb +15 -0
  47. data/lib/kayako_client/ticket_priority.rb +14 -0
  48. data/lib/kayako_client/ticket_status.rb +14 -0
  49. data/lib/kayako_client/ticket_time_track.rb +14 -0
  50. data/lib/kayako_client/ticket_type.rb +14 -0
  51. data/lib/kayako_client/troubleshooter_attachment.rb +68 -0
  52. data/lib/kayako_client/troubleshooter_category.rb +51 -0
  53. data/lib/kayako_client/troubleshooter_comment.rb +32 -0
  54. data/lib/kayako_client/troubleshooter_step.rb +100 -0
  55. data/lib/kayako_client/user.rb +42 -0
  56. data/lib/kayako_client/user_group.rb +14 -0
  57. data/lib/kayako_client/user_organization.rb +14 -0
  58. data/lib/kayako_client/xml/lib_xml.rb +14 -0
  59. data/lib/kayako_client/xml/rexml_document.rb +14 -0
  60. data/lib/kayako_client/xml/xml.rb +14 -0
  61. data/lib/kayako_client/xml/xml_backend.rb +14 -0
  62. data/test/test_attachment.rb +77 -0
  63. data/test/test_client.rb +191 -0
  64. data/test/test_configuration.rb +110 -0
  65. data/test/test_count.rb +162 -0
  66. data/test/test_custom_field.rb +86 -0
  67. data/test/test_department.rb +136 -0
  68. data/test/test_http.rb +34 -0
  69. data/test/test_knowledgebase.rb +155 -0
  70. data/test/test_news.rb +117 -0
  71. data/test/test_note.rb +64 -0
  72. data/test/test_post.rb +64 -0
  73. data/test/test_priority.rb +46 -0
  74. data/test/test_properties.rb +114 -0
  75. data/test/test_staff.rb +77 -0
  76. data/test/test_status.rb +52 -0
  77. data/test/test_ticket.rb +152 -0
  78. data/test/test_ticket_custom_field.rb +193 -0
  79. data/test/test_time_track.rb +68 -0
  80. data/test/test_troubleshooter.rb +106 -0
  81. data/test/test_type.rb +65 -0
  82. data/test/test_user.rb +95 -0
  83. data/test/test_xml.rb +183 -0
  84. metadata +89 -42
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/department'
2
16
 
3
17
  require 'kayako_client/staff'
@@ -92,7 +106,9 @@ module KayakoClient
92
106
  property :auto_user_id, :boolean, :new => true
93
107
  property :staff_id, :integer, :new => true
94
108
  property :type, :symbol, :new => true, :in => TICKET_TYPES
95
- property :template_group_id, :integer
109
+ property :template_group_id, :integer, :set => :templategroup
110
+ property :template_group_name, :string, :set => :templategroup
111
+ property :ignore_autoresponder, :boolean, :new => true
96
112
 
97
113
  property :work_flow, :object, :class => TicketWorkflow
98
114
  property :watcher, [ :object ], :class => TicketWatcher
@@ -107,6 +123,10 @@ module KayakoClient
107
123
  associate :organization, :user_organization_id, UserOrganization
108
124
  associate :owner_staff, :owner_staff_id, Staff
109
125
 
126
+ if method_defined?(:posts)
127
+ remove_method(:posts)
128
+ end
129
+
110
130
  def posts
111
131
  if instance_variable_defined?(:@posts)
112
132
  instance_variable_get(:@posts)
@@ -235,6 +255,9 @@ module KayakoClient
235
255
  raise ArgumentError, ":auto_user_id, :user_id or :staff_id is required"
236
256
  end
237
257
  end
258
+ if params.has_key?(:template_group_id) && params.has_key?(:template_group_name)
259
+ raise ArgumentError, "Only one of :template_group_id or :template_group_name should be used"
260
+ end
238
261
  end
239
262
 
240
263
  end
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/mixins/ticket_api'
2
16
  require 'kayako_client/mixins/attachment'
3
17
 
@@ -23,6 +37,10 @@ module KayakoClient
23
37
  associate :ticket, :ticket_id, Ticket
24
38
  associate :ticket_post, :ticket_post_id, TicketPost
25
39
 
40
+ if method_defined?(:contents)
41
+ remove_method(:contents)
42
+ end
43
+
26
44
  def contents
27
45
  if instance_variable_defined?(:@contents)
28
46
  instance_variable_get(:@contents)
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/ticket_status'
2
16
  require 'kayako_client/ticket_type'
3
17
  require 'kayako_client/staff'
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'base64'
2
16
  require 'time'
3
17
 
@@ -1,7 +1,20 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/mixins/ticket_api'
2
16
 
3
17
  require 'kayako_client/staff'
4
- require 'kayako_client/ticket'
5
18
  require 'kayako_client/user'
6
19
  require 'kayako_client/user_organization'
7
20
 
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/mixins/ticket_api'
2
16
 
3
17
  require 'kayako_client/staff'
@@ -31,6 +45,7 @@ module KayakoClient
31
45
  property :ticket_id, :integer, :new => true, :required => :post
32
46
  property :subject, :string, :new => true, :required => :post
33
47
  property :ticket_post_id, :integer, :readonly => true
48
+ property :is_private, :boolean, :new => true, :required => :post
34
49
 
35
50
  associate :user, :user_id, User
36
51
  associate :staff, :staff_id, Staff
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/mixins/user_visibility_api'
2
16
 
3
17
  module KayakoClient
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/department'
2
16
 
3
17
  module KayakoClient
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/mixins/ticket_api'
2
16
 
3
17
  module KayakoClient
@@ -1,3 +1,17 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
1
15
  require 'kayako_client/mixins/user_visibility_api'
2
16
 
3
17
  require 'kayako_client/department'
@@ -0,0 +1,68 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
15
+ require 'kayako_client/mixins/troubleshooter_step_api'
16
+
17
+ require 'kayako_client/troubleshooter_step'
18
+
19
+ module KayakoClient
20
+ class TroubleshooterAttachment < KayakoClient::Troubleshooter
21
+ include KayakoClient::TroubleshooterStepAPI
22
+ include KayakoClient::Attachment
23
+
24
+ path '/Troubleshooter/Attachment'
25
+
26
+ supports :all, :get, :post, :delete
27
+
28
+ property :id, :integer, :readonly => true
29
+ property :troubleshooter_step_id, :integer, :required => :post
30
+ property :file_name, :string, :required => :post
31
+ property :file_size, :integer, :readonly => true
32
+ property :file_type, :string, :readonly => true
33
+ property :date_line, :date, :readonly => true
34
+ property :contents, :binary, :required => :post, :new => true
35
+ property :link, :string, :readonly => true
36
+
37
+ associate :troubleshooter_step, :troubleshooter_step_id, TroubleshooterStep
38
+
39
+ if method_defined?(:contents)
40
+ remove_method(:contents)
41
+ end
42
+
43
+ def contents
44
+ if instance_variable_defined?(:@contents)
45
+ instance_variable_get(:@contents)
46
+ else
47
+ if !new? && id && id > 0
48
+ if troubleshooter_step_id.nil? && !link.nil? && link.match(%r{/[0-9]+/([0-9]+)/([0-9]+)/?$}) && $2.to_i == id
49
+ troubleshooter_step_id = $1.to_i
50
+ end
51
+ if troubleshooter_step_id && troubleshooter_step_id > 0
52
+ logger.debug "contents are missing - trying to reload" if logger
53
+ if reload!(:e => "#{self.class.path}/#{troubleshooter_step_id.to_i}/#{id.to_i}") && instance_variable_defined?(:@contents)
54
+ instance_variable_get(:@contents)
55
+ else
56
+ instance_variable_set(:@contents, nil)
57
+ end
58
+ else
59
+ nil
60
+ end
61
+ else
62
+ nil
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,51 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
15
+ require 'kayako_client/mixins/convert_api'
16
+
17
+ require 'kayako_client/staff'
18
+ require 'kayako_client/user_group'
19
+ require 'kayako_client/staff_group'
20
+
21
+ module KayakoClient
22
+ class TroubleshooterCategory < KayakoClient::Troubleshooter
23
+ include KayakoClient::ConvertAPI
24
+ include KayakoClient::UserVisibilityAPI
25
+ include KayakoClient::StaffVisibilityAPI
26
+
27
+ path '/Troubleshooter/Category'
28
+
29
+ TYPE_GLOBAL = 1
30
+ TYPE_PUBLIC = 2
31
+ TYPE_PRIVATE = 3
32
+
33
+ property :id, :integer, :readonly => true
34
+ property :staff_id, :integer, :required => :post, :new => true
35
+ property :staff_name, :string, :readonly => true
36
+ property :title, :string, :required => :post
37
+ property :description, :string
38
+ property :category_type, :integer, :required => :post, :range => 1..3
39
+ property :display_order, :integer
40
+ property :views, :integer, :readonly => true
41
+ property :user_visibility_custom, :boolean
42
+ property :user_group_ids, [ :integer ], :get => :usergroupidlist, :set => :usergroupidlist, :condition => { :user_visibility_custom => true }
43
+ property :staff_visibility_custom, :boolean
44
+ property :staff_group_ids, [ :integer ], :get => :staffgroupidlist, :set => :staffgroupidlist, :condition => { :staff_visibility_custom => true }
45
+
46
+ associate :staff, :staff_id, Staff
47
+ associate :user_groups, :user_group_ids, UserGroup
48
+ associate :staff_groups, :staff_group_ids, StaffGroup
49
+
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
15
+ require 'kayako_client/mixins/creator_api'
16
+ require 'kayako_client/mixins/comment_object'
17
+
18
+ require 'kayako_client/troubleshooter_step'
19
+
20
+ module KayakoClient
21
+ class TroubleshooterComment < KayakoClient::Troubleshooter
22
+ include KayakoClient::CreatorAPI
23
+ include KayakoClient::CommentObject
24
+
25
+ path '/Troubleshooter/Comment'
26
+
27
+ property :troubleshooter_step_id, :integer, :required => :post
28
+
29
+ associate :troubleshooter_step, :troubleshooter_step_id, TroubleshooterStep
30
+
31
+ end
32
+ end
@@ -0,0 +1,100 @@
1
+ #######################################################################
2
+ #
3
+ # Kayako Ruby REST API library
4
+ # _____________________________________________________________________
5
+ #
6
+ # @author Andriy Lesyuk
7
+ #
8
+ # @package KayakoClient
9
+ # @copyright Copyright (c) 2011-2013, Kayako
10
+ # @license FreeBSD
11
+ # @link http://forge.kayako.com/projects/kayako-ruby-api-library
12
+ #
13
+ #######################################################################
14
+
15
+ require 'kayako_client/mixins/convert_api'
16
+
17
+ require 'kayako_client/troubleshooter_category'
18
+
19
+ require 'kayako_client/staff'
20
+ require 'kayako_client/department'
21
+ require 'kayako_client/ticket_type'
22
+ require 'kayako_client/ticket_priority'
23
+
24
+ module KayakoClient
25
+
26
+ class TroubleshooterAttachment < KayakoClient::Troubleshooter
27
+ end
28
+
29
+ class TroubleshooterStep < KayakoClient::Troubleshooter
30
+ include KayakoClient::ConvertAPI
31
+ include KayakoClient::TroubleshooterStepClient
32
+
33
+ path '/Troubleshooter/Step'
34
+
35
+ STATUS_PUBLISHED = 1
36
+ STATUS_DRAFT = 2
37
+
38
+ property :id, :integer, :readonly => true
39
+ property :category_id, :integer, :required => :post, :new => true
40
+ property :staff_id, :integer, :required => :post, :new => true
41
+ property :staff_name, :string, :readonly => true
42
+ property :subject, :string, :required => :post
43
+ property :edited, :boolean, :readonly => true
44
+ property :edited_staff_id, :integer, :required => :put
45
+ property :edited_staff_name, :string, :readonly => true
46
+ property :display_order, :integer
47
+ property :views, :integer, :readonly => true
48
+ property :allow_comments, :boolean
49
+ property :has_attachments, :boolean, :readonly => true
50
+ property :parent_step_ids, [ :integer ], :get => :parentsteps, :set => :parentstepidlist
51
+ property :child_step_ids, [ :integer ], :readonly => true, :get => :childsteps
52
+ property :redirect_tickets, :boolean, :readonly => true
53
+ property :ticket_subject, :string
54
+ property :redirect_department_id, :integer
55
+ property :ticket_type_id, :integer
56
+ property :ticket_priority_id, :integer, :get => :priorityid
57
+ property :contents, :string, :required => :post
58
+ property :enable_ticket_redirection, :boolean
59
+ property :step_status, :integer, :range => 1..2
60
+
61
+ property :attachments, [ :object ], :class => TroubleshooterAttachment
62
+
63
+ associate :category, :category_id, TroubleshooterCategory
64
+ associate :staff, :staff_id, Staff
65
+ associate :edited_staff, :edited_staff_id, Staff
66
+ associate :parent_steps, :parent_step_ids, TroubleshooterStep
67
+ associate :child_steps, :child_step_ids, TroubleshooterStep
68
+ associate :redirect_department, :redirect_department_id, Department
69
+ associate :ticket_type, :ticket_type_id, TicketType
70
+ associate :priority, :ticket_priority_id, TicketPriority
71
+
72
+ def has_parent_steps?
73
+ !parent_step_ids.nil? && parent_step_ids.size > 0
74
+ end
75
+
76
+ def has_child_steps?
77
+ !child_step_ids.nil? && child_step_ids.size > 0
78
+ end
79
+
80
+ def in_step?(step)
81
+ step.respond_to?(:to_i) && !parent_step_ids.nil? && parent_step_ids.include?(step.to_i)
82
+ end
83
+
84
+ def has_step?(step)
85
+ step.respond_to?(:to_i) && !child_step_ids.nil? && child_step_ids.include?(step.to_i)
86
+ end
87
+
88
+ private
89
+
90
+ def validate(method, params)
91
+ if method == :put
92
+ unless changes.include?(:edited_staff_id) && params[:edited_staff_id].to_i > 0
93
+ raise ArgumentError, ":edited_staff_id is required"
94
+ end
95
+ end
96
+ end
97
+
98
+ end
99
+
100
+ end