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.
- data/lib/kayako_client.rb +31 -0
- data/lib/kayako_client/base.rb +23 -0
- data/lib/kayako_client/custom_field.rb +14 -0
- data/lib/kayako_client/department.rb +18 -3
- data/lib/kayako_client/http/http.rb +14 -0
- data/lib/kayako_client/http/http_backend.rb +14 -0
- data/lib/kayako_client/http/http_client.rb +14 -0
- data/lib/kayako_client/http/http_response.rb +14 -0
- data/lib/kayako_client/http/net_http.rb +14 -0
- data/lib/kayako_client/knowledgebase_article.rb +131 -0
- data/lib/kayako_client/knowledgebase_attachment.rb +59 -0
- data/lib/kayako_client/knowledgebase_category.rb +71 -0
- data/lib/kayako_client/knowledgebase_comment.rb +32 -0
- data/lib/kayako_client/mixins/api.rb +14 -0
- data/lib/kayako_client/mixins/article_client.rb +76 -0
- data/lib/kayako_client/mixins/attachment.rb +16 -1
- data/lib/kayako_client/mixins/authentication.rb +14 -0
- data/lib/kayako_client/mixins/client.rb +300 -0
- data/lib/kayako_client/mixins/comment_object.rb +102 -0
- data/lib/kayako_client/mixins/convert_api.rb +39 -0
- data/lib/kayako_client/mixins/creator_api.rb +44 -0
- data/lib/kayako_client/mixins/knowledgebase_article_api.rb +69 -0
- data/lib/kayako_client/mixins/knowledgebase_category_client.rb +51 -0
- data/lib/kayako_client/mixins/logger.rb +14 -0
- data/lib/kayako_client/mixins/news_category_client.rb +51 -0
- data/lib/kayako_client/mixins/news_client.rb +51 -0
- data/lib/kayako_client/mixins/object.rb +24 -7
- data/lib/kayako_client/mixins/post_client.rb +14 -0
- data/lib/kayako_client/mixins/staff_visibility_api.rb +14 -0
- data/lib/kayako_client/mixins/ticket_api.rb +14 -0
- data/lib/kayako_client/mixins/ticket_client.rb +14 -0
- data/lib/kayako_client/mixins/troubleshooter_step_api.rb +69 -0
- data/lib/kayako_client/mixins/troubleshooter_step_client.rb +76 -0
- data/lib/kayako_client/mixins/user_visibility_api.rb +14 -0
- data/lib/kayako_client/news_category.rb +29 -0
- data/lib/kayako_client/news_comment.rb +32 -0
- data/lib/kayako_client/news_item.rb +81 -0
- data/lib/kayako_client/news_subscriber.rb +33 -0
- data/lib/kayako_client/staff.rb +14 -0
- data/lib/kayako_client/staff_group.rb +14 -0
- data/lib/kayako_client/ticket.rb +24 -1
- data/lib/kayako_client/ticket_attachment.rb +18 -0
- data/lib/kayako_client/ticket_count.rb +14 -0
- data/lib/kayako_client/ticket_custom_field.rb +14 -0
- data/lib/kayako_client/ticket_note.rb +14 -1
- data/lib/kayako_client/ticket_post.rb +15 -0
- data/lib/kayako_client/ticket_priority.rb +14 -0
- data/lib/kayako_client/ticket_status.rb +14 -0
- data/lib/kayako_client/ticket_time_track.rb +14 -0
- data/lib/kayako_client/ticket_type.rb +14 -0
- data/lib/kayako_client/troubleshooter_attachment.rb +68 -0
- data/lib/kayako_client/troubleshooter_category.rb +51 -0
- data/lib/kayako_client/troubleshooter_comment.rb +32 -0
- data/lib/kayako_client/troubleshooter_step.rb +100 -0
- data/lib/kayako_client/user.rb +42 -0
- data/lib/kayako_client/user_group.rb +14 -0
- data/lib/kayako_client/user_organization.rb +14 -0
- data/lib/kayako_client/xml/lib_xml.rb +14 -0
- data/lib/kayako_client/xml/rexml_document.rb +14 -0
- data/lib/kayako_client/xml/xml.rb +14 -0
- data/lib/kayako_client/xml/xml_backend.rb +14 -0
- data/test/test_attachment.rb +77 -0
- data/test/test_client.rb +191 -0
- data/test/test_configuration.rb +110 -0
- data/test/test_count.rb +162 -0
- data/test/test_custom_field.rb +86 -0
- data/test/test_department.rb +136 -0
- data/test/test_http.rb +34 -0
- data/test/test_knowledgebase.rb +155 -0
- data/test/test_news.rb +117 -0
- data/test/test_note.rb +64 -0
- data/test/test_post.rb +64 -0
- data/test/test_priority.rb +46 -0
- data/test/test_properties.rb +114 -0
- data/test/test_staff.rb +77 -0
- data/test/test_status.rb +52 -0
- data/test/test_ticket.rb +152 -0
- data/test/test_ticket_custom_field.rb +193 -0
- data/test/test_time_track.rb +68 -0
- data/test/test_troubleshooter.rb +106 -0
- data/test/test_type.rb +65 -0
- data/test/test_user.rb +95 -0
- data/test/test_xml.rb +183 -0
- metadata +89 -42
data/lib/kayako_client/user.rb
CHANGED
@@ -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/user_group'
|
2
16
|
require 'kayako_client/user_organization'
|
3
17
|
|
@@ -57,5 +71,33 @@ module KayakoClient
|
|
57
71
|
super(options.merge(:e => e))
|
58
72
|
end
|
59
73
|
|
74
|
+
def self.search(query, options = {})
|
75
|
+
unless configured? || (options[:api_url] && options[:api_key] && options[:secret_key])
|
76
|
+
raise RuntimeError, "client not configured"
|
77
|
+
end
|
78
|
+
raise ArgumentError, "query can't be empty" if query.empty?
|
79
|
+
|
80
|
+
response = post_request(options.merge(:e => '/Base/UserSearch', :query => query))
|
81
|
+
log = options[:logger] || logger
|
82
|
+
if response.is_a?(KayakoClient::HTTPOK)
|
83
|
+
objects = []
|
84
|
+
if log
|
85
|
+
log.debug "Response:"
|
86
|
+
log.debug response.body
|
87
|
+
end
|
88
|
+
payload = xml_backend.new(response.body, { :logger => log })
|
89
|
+
payload.each do |element|
|
90
|
+
object = new(payload.to_hash(element).merge(inherited_options(options)))
|
91
|
+
object.loaded!
|
92
|
+
objects << object
|
93
|
+
end
|
94
|
+
log.info ":post(:search, '#{query}') successful (#{objects.size} objects)" if log
|
95
|
+
objects
|
96
|
+
else
|
97
|
+
log.error "Response: #{response.status} #{response.body}" if log
|
98
|
+
raise StandardError, "server returned #{response.status}: #{response.body}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
60
102
|
end
|
61
103
|
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
|
module KayakoClient
|
2
16
|
class UserGroup < KayakoClient::Base
|
3
17
|
|
@@ -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
|
module KayakoClient
|
2
16
|
class UserOrganization < KayakoClient::Base
|
3
17
|
|
@@ -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 'libxml'
|
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 'rexml/document'
|
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
|
module KayakoClient
|
2
16
|
module XML
|
3
17
|
|
@@ -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
|
module KayakoClient
|
2
16
|
|
3
17
|
module XMLBackend
|
@@ -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 TestAttachment < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def test_attachment_put
|
21
|
+
test = KayakoClient::TicketAttachment.new
|
22
|
+
assert_raise NotImplementedError do
|
23
|
+
test.put
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_attachment_file
|
28
|
+
test = KayakoClient::TicketAttachment.new(
|
29
|
+
:file => __FILE__
|
30
|
+
)
|
31
|
+
assert_equal test.file_name, File.basename(__FILE__)
|
32
|
+
assert_equal test.contents.size, File.size?(__FILE__)
|
33
|
+
|
34
|
+
assert_raise RuntimeError do
|
35
|
+
test.file
|
36
|
+
end
|
37
|
+
|
38
|
+
test = KayakoClient::TicketAttachment.new(
|
39
|
+
:id => 1,
|
40
|
+
:file_name => 'test.txt',
|
41
|
+
:contents => 'Test file content.'
|
42
|
+
)
|
43
|
+
test.loaded!
|
44
|
+
assert_instance_of Tempfile, test.file
|
45
|
+
|
46
|
+
assert_equal test.file_name, 'test.txt'
|
47
|
+
assert_equal test.contents, 'Test file content.'
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_attachment_api
|
51
|
+
test = KayakoClient::TicketAttachment.new(
|
52
|
+
:id => 1,
|
53
|
+
:ticket_id => 1,
|
54
|
+
:ticket_post_id => 1,
|
55
|
+
:file_name => 'test.txt'
|
56
|
+
)
|
57
|
+
assert_nil test.contents
|
58
|
+
|
59
|
+
test.loaded!
|
60
|
+
assert_raise RuntimeError do
|
61
|
+
test.contents
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_raise ArgumentError do
|
65
|
+
KayakoClient::TicketAttachment.all
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_raise ArgumentError do
|
69
|
+
KayakoClient::TicketAttachment.get(1)
|
70
|
+
end
|
71
|
+
|
72
|
+
assert_raise ArgumentError do
|
73
|
+
KayakoClient::TicketAttachment.delete(1)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/test/test_client.rb
ADDED
@@ -0,0 +1,191 @@
|
|
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 TestClient < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def test_client_base
|
21
|
+
test = KayakoClient::Base.new
|
22
|
+
|
23
|
+
assert test.respond_to?(:departments)
|
24
|
+
assert test.respond_to?(:get_department)
|
25
|
+
assert test.respond_to?(:post_department)
|
26
|
+
assert test.respond_to?(:delete_department)
|
27
|
+
assert test.respond_to?(:staff)
|
28
|
+
assert test.respond_to?(:get_staff)
|
29
|
+
assert test.respond_to?(:post_staff)
|
30
|
+
assert test.respond_to?(:delete_staff)
|
31
|
+
assert test.respond_to?(:staff_groups)
|
32
|
+
assert test.respond_to?(:get_staff_group)
|
33
|
+
assert test.respond_to?(:post_staff_group)
|
34
|
+
assert test.respond_to?(:delete_staff_group)
|
35
|
+
assert test.respond_to?(:tickets)
|
36
|
+
assert test.respond_to?(:get_ticket)
|
37
|
+
assert test.respond_to?(:ticket_search)
|
38
|
+
assert test.respond_to?(:post_ticket)
|
39
|
+
assert test.respond_to?(:delete_ticket)
|
40
|
+
assert test.respond_to?(:ticket_attachments)
|
41
|
+
assert test.respond_to?(:get_ticket_attachment)
|
42
|
+
assert test.respond_to?(:post_ticket_attachment)
|
43
|
+
assert test.respond_to?(:delete_ticket_attachment)
|
44
|
+
assert test.respond_to?(:ticket_count)
|
45
|
+
assert test.respond_to?(:ticket_custom_fields)
|
46
|
+
assert test.respond_to?(:ticket_notes)
|
47
|
+
assert test.respond_to?(:get_ticket_note)
|
48
|
+
assert test.respond_to?(:post_ticket_note)
|
49
|
+
assert test.respond_to?(:delete_ticket_note)
|
50
|
+
assert test.respond_to?(:ticket_posts)
|
51
|
+
assert test.respond_to?(:get_ticket_post)
|
52
|
+
assert test.respond_to?(:post_ticket_post)
|
53
|
+
assert test.respond_to?(:delete_ticket_post)
|
54
|
+
assert test.respond_to?(:ticket_priorities)
|
55
|
+
assert test.respond_to?(:get_ticket_priority)
|
56
|
+
assert test.respond_to?(:ticket_statuses)
|
57
|
+
assert test.respond_to?(:get_ticket_status)
|
58
|
+
assert test.respond_to?(:ticket_time_tracks)
|
59
|
+
assert test.respond_to?(:get_ticket_time_track)
|
60
|
+
assert test.respond_to?(:post_ticket_time_track)
|
61
|
+
assert test.respond_to?(:delete_ticket_time_track)
|
62
|
+
assert test.respond_to?(:ticket_types)
|
63
|
+
assert test.respond_to?(:get_ticket_type)
|
64
|
+
assert test.respond_to?(:users)
|
65
|
+
assert test.respond_to?(:get_user)
|
66
|
+
assert test.respond_to?(:user_search)
|
67
|
+
assert test.respond_to?(:post_user)
|
68
|
+
assert test.respond_to?(:delete_user)
|
69
|
+
assert test.respond_to?(:user_groups)
|
70
|
+
assert test.respond_to?(:get_user_group)
|
71
|
+
assert test.respond_to?(:post_user_group)
|
72
|
+
assert test.respond_to?(:delete_user_group)
|
73
|
+
assert test.respond_to?(:user_organizations)
|
74
|
+
assert test.respond_to?(:get_user_organization)
|
75
|
+
assert test.respond_to?(:post_user_organization)
|
76
|
+
assert test.respond_to?(:delete_user_organization)
|
77
|
+
|
78
|
+
assert test.respond_to?(:find_department)
|
79
|
+
assert test.respond_to?(:create_department)
|
80
|
+
assert test.respond_to?(:destroy_department)
|
81
|
+
assert test.respond_to?(:staff_users)
|
82
|
+
assert test.respond_to?(:find_staff)
|
83
|
+
assert test.respond_to?(:create_staff)
|
84
|
+
assert test.respond_to?(:destroy_staff)
|
85
|
+
assert test.respond_to?(:find_staff_group)
|
86
|
+
assert test.respond_to?(:create_staff_group)
|
87
|
+
assert test.respond_to?(:destroy_staff_group)
|
88
|
+
assert test.respond_to?(:find_ticket)
|
89
|
+
assert test.respond_to?(:create_ticket)
|
90
|
+
assert test.respond_to?(:destroy_ticket)
|
91
|
+
assert test.respond_to?(:find_ticket_attachment)
|
92
|
+
assert test.respond_to?(:create_ticket_attachment)
|
93
|
+
assert test.respond_to?(:destroy_ticket_attachment)
|
94
|
+
assert test.respond_to?(:find_ticket_note)
|
95
|
+
assert test.respond_to?(:create_ticket_note)
|
96
|
+
assert test.respond_to?(:destroy_ticket_note)
|
97
|
+
assert test.respond_to?(:find_ticket_post)
|
98
|
+
assert test.respond_to?(:create_ticket_post)
|
99
|
+
assert test.respond_to?(:destroy_ticket_post)
|
100
|
+
assert test.respond_to?(:find_ticket_priority)
|
101
|
+
assert test.respond_to?(:find_ticket_status)
|
102
|
+
assert test.respond_to?(:find_ticket_time_track)
|
103
|
+
assert test.respond_to?(:create_ticket_time_track)
|
104
|
+
assert test.respond_to?(:destroy_ticket_time_track)
|
105
|
+
assert test.respond_to?(:find_ticket_type)
|
106
|
+
assert test.respond_to?(:find_user)
|
107
|
+
assert test.respond_to?(:create_user)
|
108
|
+
assert test.respond_to?(:destroy_user)
|
109
|
+
assert test.respond_to?(:find_user_group)
|
110
|
+
assert test.respond_to?(:create_user_group)
|
111
|
+
assert test.respond_to?(:destroy_user_group)
|
112
|
+
assert test.respond_to?(:find_user_organization)
|
113
|
+
assert test.respond_to?(:create_user_organization)
|
114
|
+
assert test.respond_to?(:destroy_user_organization)
|
115
|
+
assert test.respond_to?(:custom_fields)
|
116
|
+
assert test.respond_to?(:custom_field_options)
|
117
|
+
|
118
|
+
test = KayakoClient::Ticket.new
|
119
|
+
|
120
|
+
assert !test.respond_to?(:get_ticket)
|
121
|
+
assert !test.respond_to?(:get_ticket_post)
|
122
|
+
assert !test.respond_to?(:user_organizations)
|
123
|
+
assert !test.respond_to?(:find_staff_group)
|
124
|
+
assert !test.respond_to?(:find_user_group)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_client_ticket
|
128
|
+
assert KayakoClient::Ticket.respond_to?(:count)
|
129
|
+
|
130
|
+
test = KayakoClient::Ticket.new
|
131
|
+
|
132
|
+
assert test.respond_to?(:attachments)
|
133
|
+
assert test.respond_to?(:get_attachment)
|
134
|
+
assert test.respond_to?(:post_attachment)
|
135
|
+
assert test.respond_to?(:delete_attachment)
|
136
|
+
assert test.respond_to?(:custom_fields)
|
137
|
+
assert test.respond_to?(:notes)
|
138
|
+
assert test.respond_to?(:get_note)
|
139
|
+
assert test.respond_to?(:post_note)
|
140
|
+
assert test.respond_to?(:delete_note)
|
141
|
+
assert test.respond_to?(:get_post)
|
142
|
+
assert test.respond_to?(:post_post)
|
143
|
+
assert test.respond_to?(:delete_post)
|
144
|
+
assert test.respond_to?(:time_tracks)
|
145
|
+
assert test.respond_to?(:get_time_track)
|
146
|
+
assert test.respond_to?(:post_time_track)
|
147
|
+
assert test.respond_to?(:delete_time_track)
|
148
|
+
|
149
|
+
assert test.respond_to?(:find_attachment)
|
150
|
+
assert test.respond_to?(:create_attachment)
|
151
|
+
assert test.respond_to?(:destroy_attachment)
|
152
|
+
assert test.respond_to?(:find_note)
|
153
|
+
assert test.respond_to?(:create_note)
|
154
|
+
assert test.respond_to?(:destroy_note)
|
155
|
+
assert test.respond_to?(:find_post)
|
156
|
+
assert test.respond_to?(:create_post)
|
157
|
+
assert test.respond_to?(:destroy_post)
|
158
|
+
assert test.respond_to?(:find_time_track)
|
159
|
+
assert test.respond_to?(:create_time_track)
|
160
|
+
assert test.respond_to?(:destroy_time_track)
|
161
|
+
|
162
|
+
test = KayakoClient::Base.new
|
163
|
+
|
164
|
+
assert !test.respond_to?(:attachments)
|
165
|
+
assert !test.respond_to?(:delete_post)
|
166
|
+
assert !test.respond_to?(:notes)
|
167
|
+
assert !test.respond_to?(:create_attachment)
|
168
|
+
assert !test.respond_to?(:find_post)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_client_inheritance
|
172
|
+
require 'kayako_client/http/http_client'
|
173
|
+
require 'kayako_client/http/net_http'
|
174
|
+
|
175
|
+
nethttp = KayakoClient::NetHTTP.new
|
176
|
+
httpclient = KayakoClient::HTTPClient.new
|
177
|
+
|
178
|
+
KayakoClient::Base.http_backend = nethttp
|
179
|
+
assert_equal nethttp.object_id, KayakoClient::Base.client.object_id
|
180
|
+
|
181
|
+
instance = KayakoClient::User.new
|
182
|
+
assert_equal nethttp.object_id, instance.client.object_id
|
183
|
+
|
184
|
+
client = KayakoClient::Base.new
|
185
|
+
client.http_backend = httpclient
|
186
|
+
|
187
|
+
assert_equal httpclient.object_id, client.client.object_id
|
188
|
+
assert_not_equal client.client.object_id, nethttp.object_id
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
@@ -0,0 +1,110 @@
|
|
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 TestConfiguration < Test::Unit::TestCase
|
19
|
+
|
20
|
+
API_URL = 'http://restapi.kayako.com/api/index.php?'
|
21
|
+
API_KEY = '2fa87390-7160-54c4-e9ce-bec638a5a153'
|
22
|
+
SECRET_KEY = 'Yzg3M2E3OWQtODM5MS1jNmY0LThkZjgtODJjZTU1MGE4MzcyYWY4NjQ2MTUtNDkxZS1lNDE0LTgxYzQtYWNjZmM5MzVjMmIz'
|
23
|
+
|
24
|
+
def test_001_no_configuration
|
25
|
+
assert_equal KayakoClient::Base.api_url, ''
|
26
|
+
assert_equal KayakoClient::Base.api_key, ''
|
27
|
+
assert_equal KayakoClient::Base.secret_key, ''
|
28
|
+
|
29
|
+
assert_raise RuntimeError do
|
30
|
+
KayakoClient::StaffGroup.get(1)
|
31
|
+
end
|
32
|
+
assert_raise RuntimeError do
|
33
|
+
KayakoClient::StaffGroup.post(
|
34
|
+
:title => 'Test',
|
35
|
+
:is_admin => true
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
test = KayakoClient::StaffGroup.new
|
40
|
+
assert_raise RuntimeError do
|
41
|
+
test.post
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_002_instance_configuration
|
46
|
+
instance1 = KayakoClient::Base.new(API_URL, API_KEY, SECRET_KEY)
|
47
|
+
instance2 = KayakoClient::Base.new
|
48
|
+
|
49
|
+
assert_equal instance1.api_url, API_URL
|
50
|
+
assert_equal instance1.api_key, API_KEY
|
51
|
+
assert_equal instance1.secret_key, SECRET_KEY
|
52
|
+
|
53
|
+
assert_equal instance2.api_url, ''
|
54
|
+
assert_equal instance2.api_key, ''
|
55
|
+
assert_equal instance2.secret_key, ''
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_003_global_configuration
|
59
|
+
KayakoClient::Base.configure do |config|
|
60
|
+
config.api_url = API_URL
|
61
|
+
config.api_key = API_KEY
|
62
|
+
end
|
63
|
+
assert_equal KayakoClient::Base.api_url, API_URL
|
64
|
+
assert_equal KayakoClient::Base.api_key, API_KEY
|
65
|
+
|
66
|
+
KayakoClient::Base.secret_key = SECRET_KEY
|
67
|
+
assert_equal KayakoClient::Base.secret_key, SECRET_KEY
|
68
|
+
|
69
|
+
assert_equal KayakoClient::StaffGroup.new.api_key, API_KEY
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_004_http_backend
|
73
|
+
assert_raise ArgumentError do
|
74
|
+
KayakoClient::Base.http_backend = 'This should be a class name!'
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_raise LoadError do
|
78
|
+
KayakoClient::Base.http_backend = 'NotExistingHTTPBackendClass'
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_nothing_raised do
|
82
|
+
KayakoClient::Base.http_backend = 'NetHTTP'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_005_xml_backend
|
87
|
+
assert_raise ArgumentError do
|
88
|
+
KayakoClient::Base.xml_backend = 'This should be a class name!'
|
89
|
+
end
|
90
|
+
|
91
|
+
assert_raise LoadError do
|
92
|
+
KayakoClient::Base.xml_backend = 'NotExistingXMLBackendClass'
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_nothing_raised do
|
96
|
+
KayakoClient::Base.xml_backend = 'REXMLDocument'
|
97
|
+
end
|
98
|
+
|
99
|
+
assert_nothing_raised do
|
100
|
+
KayakoClient::Base.xml_backend = 'LibXML'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_006_http_configuration
|
105
|
+
KayakoClient::Base.proxy = { :host => '127.0.0.1', :port => 3128 }
|
106
|
+
assert_equal KayakoClient::Base.proxy[:host], '127.0.0.1'
|
107
|
+
assert_equal KayakoClient::Base.proxy[:port], 3128
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|