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,117 @@
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 TestNews < Test::Unit::TestCase
19
+
20
+ def test_path
21
+ assert_equal KayakoClient::NewsCategory.path, '/News/Category'
22
+ assert_equal KayakoClient::NewsComment.path, '/News/Comment'
23
+ assert_equal KayakoClient::NewsItem.path, '/News/NewsItem'
24
+ assert_equal KayakoClient::NewsSubscriber.path,'/News/Subscriber'
25
+ end
26
+
27
+ def test_category
28
+ test = KayakoClient::NewsCategory.new(
29
+ :title => 'Test'
30
+ )
31
+
32
+ test.visibility_type = 'test'
33
+
34
+ assert_equal test.post, false
35
+ assert test.has_errors?
36
+ end
37
+
38
+ def test_category_client
39
+ test = KayakoClient::NewsCategory.new
40
+
41
+ assert test.respond_to?(:news)
42
+ assert test.respond_to?(:get_news)
43
+ assert test.respond_to?(:post_news)
44
+ assert test.respond_to?(:delete_news)
45
+ end
46
+
47
+ def test_comment
48
+ assert KayakoClient::NewsComment.const_defined?(:CREATOR_USER)
49
+ assert KayakoClient::NewsComment.const_defined?(:CREATOR_STAFF)
50
+
51
+ assert KayakoClient::NewsComment.const_defined?(:STATUS_PENDING)
52
+ assert KayakoClient::NewsComment.const_defined?(:STATUS_APPROVED)
53
+ assert KayakoClient::NewsComment.const_defined?(:STATUS_SPAM)
54
+
55
+ test = KayakoClient::NewsComment.new
56
+
57
+ assert test.respond_to?(:creator=)
58
+
59
+ assert_raise NotImplementedError do
60
+ test.put
61
+ end
62
+
63
+ assert test.respond_to?(:creator_type)
64
+ assert test.respond_to?(:creator_id)
65
+ assert test.respond_to?(:parent_comment_id)
66
+ assert test.respond_to?(:parent_comment)
67
+
68
+ assert test.respond_to?(:news_item_id)
69
+ assert test.respond_to?(:news_item)
70
+
71
+ assert_raise ArgumentError do
72
+ KayakoClient::NewsComment.all
73
+ end
74
+ end
75
+
76
+ def test_news
77
+ assert KayakoClient::NewsItem.included_modules.include?(KayakoClient::ConvertAPI)
78
+
79
+ test = KayakoClient::NewsItem.new(
80
+ :category_ids => [ 1 ]
81
+ )
82
+
83
+ assert test.respond_to?(:comments)
84
+ assert test.respond_to?(:get_comment)
85
+ assert test.respond_to?(:post_comment)
86
+ assert test.respond_to?(:delete_comment)
87
+
88
+ assert test.respond_to?(:user_visibility_custom)
89
+ assert test.respond_to?(:user_group_ids)
90
+ assert test.respond_to?(:visible_to_user_group?)
91
+ assert test.respond_to?(:staff_visibility_custom)
92
+ assert test.respond_to?(:staff_group_ids)
93
+ assert test.respond_to?(:visible_to_staff_group?)
94
+
95
+ assert_raise ArgumentError do
96
+ KayakoClient::NewsItem.all(1, 2)
97
+ end
98
+
99
+ assert test.in_category?(1)
100
+
101
+ category = KayakoClient::NewsCategory.new(
102
+ :id => 1
103
+ )
104
+
105
+ assert test.in_category?(category)
106
+ end
107
+
108
+ def test_subscriber
109
+ test = KayakoClient::NewsSubscriber.new(
110
+ :tgroupid => 1
111
+ )
112
+
113
+ assert_equal test.template_group_id, 1
114
+ assert_equal test.template_group_id, test.tgroupid
115
+ end
116
+
117
+ end
@@ -0,0 +1,64 @@
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 TestNote < Test::Unit::TestCase
19
+
20
+ def test_note_methods
21
+ test = KayakoClient::TicketNote.new
22
+ assert_raise NotImplementedError do
23
+ test.put
24
+ end
25
+ end
26
+
27
+ def test_note_ticket_api
28
+ assert KayakoClient::TicketNote.included_modules.include?(KayakoClient::TicketAPI)
29
+ end
30
+
31
+ def test_note_constants
32
+ assert KayakoClient::TicketNote::NOTE_TYPES.include?(:ticket)
33
+ assert KayakoClient::TicketNote::NOTE_TYPES.include?(:user)
34
+ assert KayakoClient::TicketNote::NOTE_TYPES.include?(:userorganization)
35
+ assert KayakoClient::TicketNote::NOTE_TYPES.include?(:timetrack)
36
+
37
+ assert_equal KayakoClient::TicketNote::COLOR_YELLOW, 1
38
+ assert_equal KayakoClient::TicketNote::COLOR_PURPLE, 2
39
+ assert_equal KayakoClient::TicketNote::COLOR_BLUE, 3
40
+ assert_equal KayakoClient::TicketNote::COLOR_GREEN, 4
41
+ assert_equal KayakoClient::TicketNote::COLOR_RED, 5
42
+ end
43
+
44
+ def test_note_validate
45
+ test = KayakoClient::TicketNote.new(
46
+ :ticket_id => 1,
47
+ :contents => 'Test'
48
+ )
49
+ assert_raise ArgumentError do
50
+ test.post
51
+ end
52
+ end
53
+
54
+ def test_note_associates
55
+ test = KayakoClient::TicketNote.new
56
+
57
+ assert test.respond_to?(:creator_staff)
58
+ assert test.respond_to?(:for_staff)
59
+ assert test.respond_to?(:user)
60
+ assert test.respond_to?(:user_organization)
61
+ assert test.respond_to?(:worker_staff)
62
+ end
63
+
64
+ end
@@ -0,0 +1,64 @@
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 TestPost < Test::Unit::TestCase
19
+
20
+ def test_post_methods
21
+ test = KayakoClient::TicketPost.new
22
+ assert_raise NotImplementedError do
23
+ test.put
24
+ end
25
+ end
26
+
27
+ def test_post_ticket_api
28
+ assert KayakoClient::TicketPost.included_modules.include?(KayakoClient::TicketAPI)
29
+ end
30
+
31
+ def test_post_constants
32
+ assert_equal KayakoClient::TicketPost::CREATOR_STAFF, 1
33
+ assert_equal KayakoClient::TicketPost::CREATOR_USER, 2
34
+ end
35
+
36
+ def test_post_validate
37
+ test = KayakoClient::TicketPost.new(
38
+ :ticket_id => 1,
39
+ :subject => 'Test',
40
+ :contents => 'Test.'
41
+ )
42
+
43
+ assert_raise ArgumentError do
44
+ test.post
45
+ end
46
+ end
47
+
48
+ def test_post_boolean
49
+ test = KayakoClient::TicketPost.new(
50
+ :has_attachments => 1,
51
+ :is_third_party => 0,
52
+ :is_html => 1,
53
+ :is_emailed => 0,
54
+ :is_survey_comment => 1
55
+ )
56
+
57
+ assert test.has_attachments?
58
+ assert !test.is_third_party?
59
+ assert test.is_html?
60
+ assert !test.is_emailed?
61
+ assert test.is_survey_comment?
62
+ end
63
+
64
+ end
@@ -0,0 +1,46 @@
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 TestPriority < Test::Unit::TestCase
19
+
20
+ def test_priority_mixins
21
+ assert KayakoClient::TicketPriority.included_modules.include?(KayakoClient::UserVisibilityAPI)
22
+
23
+ test = KayakoClient::TicketPriority.new(
24
+ :user_visibility_custom => true,
25
+ :user_group_ids => [ 1 ]
26
+ )
27
+ assert test.visible_to_user_group?(1)
28
+ end
29
+
30
+ def test_priority_methods
31
+ test = KayakoClient::TicketPriority.new
32
+
33
+ assert_raise NotImplementedError do
34
+ test.put
35
+ end
36
+
37
+ assert_raise NotImplementedError do
38
+ test.post
39
+ end
40
+
41
+ assert_raise NotImplementedError do
42
+ test.delete
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,114 @@
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 TestProperties < Test::Unit::TestCase
19
+
20
+ def test_new
21
+ test = KayakoClient::StaffGroup.new
22
+ assert test.new?
23
+
24
+ test.loaded!
25
+ assert !test.new?
26
+ end
27
+
28
+ def test_changed
29
+ test = KayakoClient::StaffGroup.new
30
+ assert !test.changed?
31
+
32
+ test.title = 'Test'
33
+ assert test.changed?
34
+
35
+ test.loaded!
36
+ assert !test.changed?
37
+ end
38
+
39
+ def test_identifier
40
+ test = KayakoClient::StaffGroup.new
41
+ assert_equal test.to_i, 0
42
+ end
43
+
44
+ def test_array_accessor
45
+ test = KayakoClient::StaffGroup.new(
46
+ :title => 'Administrators',
47
+ :is_admin => true
48
+ )
49
+
50
+ assert_raise ArgumentError do
51
+ test[:test] = 'Test'
52
+ end
53
+
54
+ assert_raise ArgumentError do
55
+ test[:id] = 1
56
+ end
57
+
58
+ assert_nothing_raised do
59
+ test[:title] = 'Test'
60
+ end
61
+
62
+ assert_nil test[:id]
63
+
64
+ test = KayakoClient::TicketWorkflow.new(
65
+ :id => 1,
66
+ :title => 'Test'
67
+ )
68
+
69
+ assert_raise ArgumentError do
70
+ test[:title] = 'Test'
71
+ end
72
+
73
+ assert_nil test[:test]
74
+ assert_not_nil test[:title]
75
+ end
76
+
77
+ def test_accessor
78
+ test = KayakoClient::StaffGroup.new(
79
+ :title => 'Administrators',
80
+ :is_admin => true
81
+ )
82
+
83
+ assert_raise NoMethodError do
84
+ test.id = 1
85
+ end
86
+
87
+ assert_nil test.id
88
+ assert_equal test.title, 'Administrators'
89
+
90
+ test = KayakoClient::TicketWorkflow.new(
91
+ :id => 1,
92
+ :title => 'Test'
93
+ )
94
+
95
+ assert_raise NoMethodError do
96
+ test.title = 'Test'
97
+ end
98
+
99
+ assert_equal test.id, 1
100
+ assert_equal test.title, 'Test'
101
+ end
102
+
103
+ def test_embedded
104
+ assert_equal KayakoClient::TicketWorkflow.embedded?, true
105
+ end
106
+
107
+ def test_path
108
+ assert_equal KayakoClient::User.path, '/Base/User'
109
+ assert_equal KayakoClient::Staff.path, '/Base/Staff'
110
+ assert_equal KayakoClient::Ticket.path, '/Tickets/Ticket'
111
+ assert_equal KayakoClient::TicketType.path, '/Tickets/TicketType'
112
+ end
113
+
114
+ end
@@ -0,0 +1,77 @@
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 TestDepartment < Test::Unit::TestCase
19
+
20
+ def test_staff_readonly
21
+ test = KayakoClient::Staff.new(
22
+ :id => 1,
23
+ :user_name => 'test',
24
+ :first_name => 'Test',
25
+ :last_name => 'Test'
26
+ )
27
+
28
+ assert_raise NoMethodError do
29
+ test.id = 2
30
+ end
31
+
32
+ assert_raise NoMethodError do
33
+ test.fullname = 'Test Test'
34
+ end
35
+ end
36
+
37
+ def test_staff_assign
38
+ test = KayakoClient::Staff.new
39
+
40
+ group = KayakoClient::StaffGroup.new(
41
+ :id => 1,
42
+ :title => 'Test'
43
+ )
44
+ test.staff_group_id = group
45
+ assert_equal test.staff_group_id, 1
46
+
47
+ test.is_enabled = true
48
+ assert test.is_enabled
49
+
50
+ test.is_enabled = 0
51
+ assert test.is_enabled == false
52
+ end
53
+
54
+ def test_staff_required
55
+ test = KayakoClient::Staff.new(
56
+ :id => 1,
57
+ :user_name => 'test',
58
+ :first_name => 'Test',
59
+ :last_name => 'Test'
60
+ )
61
+ assert_raise ArgumentError do
62
+ test.put
63
+ end
64
+
65
+ test = KayakoClient::Staff.new(
66
+ :user_name => 'test',
67
+ :first_name => 'Test',
68
+ :last_name => 'Test',
69
+ :email => 'test@test.com',
70
+ :staff_group_id => 1
71
+ )
72
+ assert_raise ArgumentError do
73
+ test.post
74
+ end
75
+ end
76
+
77
+ end