KayakoClient 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,52 @@
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 'test/unit'
16
+ require 'kayako_client'
17
+
18
+ class TestStatus < Test::Unit::TestCase
19
+
20
+ def test_status_methods
21
+ test = KayakoClient::TicketStatus.new
22
+
23
+ assert_raise NotImplementedError do
24
+ test.put
25
+ end
26
+
27
+ assert_raise NotImplementedError do
28
+ test.post
29
+ end
30
+
31
+ assert_raise NotImplementedError do
32
+ test.delete
33
+ end
34
+ end
35
+
36
+ def test_status_constants
37
+ assert KayakoClient::TicketStatus::STATUS_TYPES.include?(:public)
38
+ assert KayakoClient::TicketStatus::STATUS_TYPES.include?(:private)
39
+ end
40
+
41
+ def test_status_customs
42
+ test = KayakoClient::TicketStatus.new(
43
+ :staffvisibilitycustom => true,
44
+ :staffgroupid => [ 1, 2 ]
45
+ )
46
+
47
+ assert test.respond_to?(:visible_to_staff_group?)
48
+ assert test.visible_to_staff_group?(1)
49
+ assert !test.visible_to_staff_group?(3)
50
+ end
51
+
52
+ end
@@ -0,0 +1,152 @@
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 'test/unit'
16
+ require 'kayako_client'
17
+
18
+ class TestTicket < Test::Unit::TestCase
19
+
20
+ def test_ticket_readonly
21
+ test = KayakoClient::Ticket.new(
22
+ :contents => 'Test',
23
+ :auto_user_id => true,
24
+ :type => :default
25
+ )
26
+
27
+ assert_raise NoMethodError do
28
+ test.display_id = 'OLJ-171-16930'
29
+ end
30
+
31
+ assert_raise NoMethodError do
32
+ test.creation_time = Time.new
33
+ end
34
+
35
+ assert_nothing_raised do
36
+ test.contents = 'Test'
37
+ test.auto_user_id = true
38
+ test.type = :default
39
+ end
40
+
41
+ test.loaded!
42
+ assert_raise ArgumentError do
43
+ test.contents = 'Test'
44
+ test.auto_user_id = true
45
+ test.type = :default
46
+ end
47
+ end
48
+
49
+ def test_ticket_constants
50
+ assert_nothing_raised do
51
+ test = KayakoClient::Ticket::FLAG_NONE
52
+ test = KayakoClient::Ticket::FLAG_ORANGE
53
+ test = KayakoClient::Ticket::FLAG_BLUE
54
+ end
55
+ end
56
+
57
+ def test_ticket_verification
58
+ test = KayakoClient::Ticket.new(
59
+ :department_id => 1,
60
+ :status_id => 1,
61
+ :priority_id => 1,
62
+ :type_id => 1,
63
+ :full_name => 'Test Tester',
64
+ :email => 'test@test.com',
65
+ :subject => 'Test',
66
+ :contents => 'Test'
67
+ )
68
+
69
+ assert_raise ArgumentError do
70
+ test.post
71
+ end
72
+
73
+ test.user_id = 1
74
+ test.type = :test
75
+
76
+ assert test.post == false
77
+ assert test.has_errors?
78
+ end
79
+
80
+ def test_ticket_embedded
81
+ test = KayakoClient::Ticket.new(
82
+ :work_flow => {
83
+ :id => 1,
84
+ :title => 'Test'
85
+ },
86
+ :watcher => {
87
+ :staff_id => 1,
88
+ :name => 'Test'
89
+ }
90
+ )
91
+
92
+ assert_instance_of KayakoClient::TicketWorkflow, test.work_flow
93
+ assert_instance_of Array, test.watcher
94
+ assert_instance_of KayakoClient::TicketWatcher, test.watcher.first
95
+
96
+ assert_equal test.work_flow.title, 'Test'
97
+ assert_equal test.watcher.first.name, 'Test'
98
+ end
99
+
100
+ def test_ticket_assign
101
+ test = KayakoClient::Ticket.new(
102
+ :id => '1',
103
+ :creation_time => '1310922585',
104
+ :is_escalated => '0'
105
+ )
106
+
107
+ assert_equal test.id, 1
108
+ assert_instance_of Time, test.creation_time
109
+ assert_equal test.creation_time.to_i, 1310922585
110
+ assert_instance_of FalseClass, test.is_escalated
111
+ assert test.is_escalated == false
112
+ end
113
+
114
+ def test_ticket_search
115
+ assert KayakoClient::Ticket.respond_to?(:search)
116
+
117
+ assert_equal 0x07FF,
118
+ KayakoClient::Ticket::SEARCH_TICKET_ID |
119
+ KayakoClient::Ticket::SEARCH_CONTENTS |
120
+ KayakoClient::Ticket::SEARCH_AUTHOR |
121
+ KayakoClient::Ticket::SEARCH_EMAIL |
122
+ KayakoClient::Ticket::SEARCH_CREATOR_EMAIL |
123
+ KayakoClient::Ticket::SEARCH_FULL_NAME |
124
+ KayakoClient::Ticket::SEARCH_NOTES |
125
+ KayakoClient::Ticket::SEARCH_USER_GROUP |
126
+ KayakoClient::Ticket::SEARCH_USER_ORGANIZATION |
127
+ KayakoClient::Ticket::SEARCH_USER |
128
+ KayakoClient::Ticket::SEARCH_TAGS
129
+
130
+ end
131
+
132
+ def test_template_group
133
+ test = KayakoClient::Ticket.new(
134
+ :department_id => 1,
135
+ :status_id => 1,
136
+ :priority_id => 1,
137
+ :type_id => 1,
138
+ :full_name => 'Test Tester',
139
+ :email => 'test@test.com',
140
+ :subject => 'Test',
141
+ :contents => 'Test',
142
+ :staff_id => 1,
143
+ :template_group_id => 1,
144
+ :template_group_name => 'default'
145
+ )
146
+
147
+ assert_raise ArgumentError do
148
+ test.post
149
+ end
150
+ end
151
+
152
+ end
@@ -0,0 +1,193 @@
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 'test/unit'
16
+ require 'kayako_client'
17
+
18
+ class TestTicketCustomField < Test::Unit::TestCase
19
+
20
+ def test_ticket_custom_field_embedded
21
+ test = KayakoClient::TicketCustomField.new(
22
+ :group => {
23
+ :id => 1,
24
+ :title => 'Test',
25
+ :fields => [ {
26
+ :id => 1,
27
+ :type => KayakoClient::CustomField::TYPE_TEXT,
28
+ :title => 'Text',
29
+ :contents => 'Test'
30
+ }, {
31
+ :id => 2,
32
+ :type => KayakoClient::CustomField::TYPE_TEXT_AREA,
33
+ :title => 'Text area',
34
+ :contents => 'Test'
35
+ }, {
36
+ :id => 3,
37
+ :type => KayakoClient::CustomField::TYPE_PASSWORD,
38
+ :title => 'Password',
39
+ :contents => 'Test'
40
+ }, {
41
+ :id => 4,
42
+ :type => KayakoClient::CustomField::TYPE_CHECKBOX,
43
+ :title => 'Checkbox',
44
+ :contents => 'Test'
45
+ }, {
46
+ :id => 5,
47
+ :type => KayakoClient::CustomField::TYPE_RADIO,
48
+ :title => 'Radio',
49
+ :contents => 'Test'
50
+ }, {
51
+ :id => 6,
52
+ :type => KayakoClient::CustomField::TYPE_SELECT,
53
+ :title => 'Select',
54
+ :contents => 'Test'
55
+ }, {
56
+ :id => 7,
57
+ :type => KayakoClient::CustomField::TYPE_MULTI_SELECT,
58
+ :title => 'Multiselect',
59
+ :contents => 'Test, Item'
60
+ }, {
61
+ :id => 8,
62
+ :type => KayakoClient::CustomField::TYPE_CUSTOM,
63
+ :title => 'Custom',
64
+ :contents => 'Test'
65
+ }, {
66
+ :id => 9,
67
+ :type => KayakoClient::CustomField::TYPE_LINKED_SELECT,
68
+ :title => 'Linked select',
69
+ :contents => 'Test &gt; Test'
70
+ }, {
71
+ :id => 10,
72
+ :type => KayakoClient::CustomField::TYPE_DATE,
73
+ :title => 'Date',
74
+ :contents => 'May/24/2011'
75
+ }, {
76
+ :id => 11,
77
+ :type => KayakoClient::CustomField::TYPE_FILE,
78
+ :title => 'File',
79
+ :filename => 'test.txt',
80
+ :contents => 'VTI5dFpTQjBaWE4wSUhOMGNtbHVaeTQ9' # Some test string
81
+ } ]
82
+ }
83
+ )
84
+
85
+ assert_instance_of Array, test.groups
86
+ assert_instance_of KayakoClient::TicketCustomFieldGroup, test.groups.first
87
+ assert_equal test.groups.size, 1
88
+
89
+ assert_equal test.groups.first.id, 1
90
+ assert_equal test.groups.first.title, 'Test'
91
+
92
+ assert_instance_of Array, test.groups.first.fields
93
+ assert_instance_of KayakoClient::TicketCustomFieldValue, test.groups.first.fields.first
94
+ assert_equal test.groups.first.fields.size, 11
95
+
96
+ assert_equal test.groups.first.fields.first.id, 1
97
+ assert_equal test.groups.first.fields.first.type, KayakoClient::CustomField::TYPE_TEXT
98
+ assert_equal test.groups.first.fields.first.title, 'Text'
99
+ assert_nil test.groups.first.fields.first.file_name
100
+ assert_equal test.groups.first.fields.first.contents, 'Test'
101
+
102
+ assert_instance_of Time, test.groups.first.fields[9].contents
103
+ assert_equal test.groups.first.fields[9].contents.strftime('%m/%d/%Y'), '05/24/2011'
104
+
105
+ assert_equal test.groups.first.fields.last.file_name, 'test.txt'
106
+ assert_equal test.groups.first.fields.last.contents, 'Some test string.'
107
+ end
108
+
109
+ def test_ticket_custom_field_file
110
+ test = KayakoClient::TicketCustomFieldValue.new(
111
+ :id => 11,
112
+ :type => KayakoClient::CustomField::TYPE_FILE,
113
+ :title => 'File',
114
+ :filename => 'test.txt',
115
+ :contents => 'VTI5dFpTQjBaWE4wSUhOMGNtbHVaeTQ9' # Some test string.
116
+ )
117
+ test.loaded!
118
+ assert_instance_of Tempfile, test.file
119
+ assert_equal test.file.read, 'Some test string.'
120
+ end
121
+
122
+ def test_ticket_custom_field_customs
123
+ test = KayakoClient::TicketCustomField.new
124
+
125
+ assert test.respond_to?(:empty?)
126
+ assert test.empty?
127
+
128
+ test = KayakoClient::TicketCustomField.new(
129
+ :group => {
130
+ :id => 1,
131
+ :title => 'Test',
132
+ :fields => [ {
133
+ :id => 4,
134
+ :type => KayakoClient::CustomField::TYPE_CHECKBOX,
135
+ :title => 'Checkbox',
136
+ :contents => 'Test'
137
+ }, {
138
+ :id => 9,
139
+ :type => KayakoClient::CustomField::TYPE_LINKED_SELECT,
140
+ :title => 'Linked select',
141
+ :contents => 'Test &gt; Test'
142
+ } ]
143
+ }
144
+ )
145
+
146
+ assert_equal test.custom_field(4), 'Test'
147
+ assert_equal test.custom_field('Linked select'), 'Test &gt; Test'
148
+ assert_nil test.custom_field('Does not exist')
149
+
150
+ assert_equal test[9], 'Test &gt; Test'
151
+ assert_equal test['Checkbox'], 'Test'
152
+ assert_nil test[20]
153
+
154
+ assert_instance_of Array, test['groups']
155
+ assert_instance_of Array, test[:groups]
156
+
157
+ assert test.respond_to?(:each)
158
+ end
159
+
160
+ def test_4_40_954
161
+ test = KayakoClient::TicketCustomFieldValue.new
162
+
163
+ assert_raise NoMethodError do
164
+ test.id = 1
165
+ end
166
+
167
+ test.contents = 'Test'
168
+ assert_equal test.contents, 'Test'
169
+
170
+ assert KayakoClient::TicketCustomField.support?(:post)
171
+
172
+ test = KayakoClient::TicketCustomField.new(:ticket_id => 1,
173
+ 'l8bo9bitv8s0' => 'Test')
174
+
175
+ assert test.respond_to?(:ticket_id)
176
+ assert test.respond_to?(:ticket_id=)
177
+
178
+ assert_equal test.ticket_id, 1
179
+ assert_equal test['l8bo9bitv8s0'], 'Test'
180
+ assert_equal test.custom_field('l8bo9bitv8s0'), 'Test'
181
+
182
+ assert !test.empty?
183
+
184
+ test['qgwj1d0r0qhc'] = 'Name'
185
+
186
+ test = KayakoClient::TicketCustomField.new
187
+
188
+ assert_raise RuntimeError do
189
+ test.post
190
+ end
191
+ end
192
+
193
+ end
@@ -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 'test/unit'
16
+ require 'kayako_client'
17
+
18
+ class TestTimeTrack < Test::Unit::TestCase
19
+
20
+ def test_time_track_methods
21
+ test = KayakoClient::TicketTimeTrack.new
22
+
23
+ assert_raise NotImplementedError do
24
+ test.put
25
+ end
26
+ end
27
+
28
+ def test_time_track_ticket_api
29
+ assert KayakoClient::TicketTimeTrack.included_modules.include?(KayakoClient::TicketAPI)
30
+
31
+ assert_raise ArgumentError do
32
+ KayakoClient::TicketTimeTrack.all
33
+ end
34
+
35
+ assert_raise ArgumentError do
36
+ KayakoClient::TicketTimeTrack.get(1)
37
+ end
38
+
39
+ assert_raise ArgumentError do
40
+ KayakoClient::TicketTimeTrack.delete(1)
41
+ end
42
+ end
43
+
44
+ def test_time_track_associates
45
+ test = KayakoClient::TicketTimeTrack.new(
46
+ :ticket_id => 0,
47
+ :worker_staff_id => 0,
48
+ :creator_staff_id => 0
49
+ )
50
+
51
+ assert test.respond_to?(:ticket)
52
+ assert test.respond_to?(:worker_staff)
53
+ assert test.respond_to?(:creator_staff)
54
+
55
+ assert_nil test.ticket
56
+ assert_nil test.worker_staff
57
+ assert_nil test.creator_staff
58
+ end
59
+
60
+ def test_time_track_note_colors
61
+ assert KayakoClient::TicketTimeTrack.options[:note_color][:range].include?(KayakoClient::TicketNote::COLOR_YELLOW)
62
+ assert KayakoClient::TicketTimeTrack.options[:note_color][:range].include?(KayakoClient::TicketNote::COLOR_PURPLE)
63
+ assert KayakoClient::TicketTimeTrack.options[:note_color][:range].include?(KayakoClient::TicketNote::COLOR_BLUE)
64
+ assert KayakoClient::TicketTimeTrack.options[:note_color][:range].include?(KayakoClient::TicketNote::COLOR_GREEN)
65
+ assert KayakoClient::TicketTimeTrack.options[:note_color][:range].include?(KayakoClient::TicketNote::COLOR_RED)
66
+ end
67
+
68
+ end