zendesk_support_api 0.5.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.
- checksums.yaml +7 -0
- data/.gitlab-ci.yml +13 -0
- data/.yardoc/checksums +10 -0
- data/.yardoc/complete +0 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/README.md +73 -0
- data/lib/zendesk_support_api.rb +10 -0
- data/lib/zendesk_support_api/client.rb +93 -0
- data/lib/zendesk_support_api/deleted_tickets.rb +130 -0
- data/lib/zendesk_support_api/groups.rb +178 -0
- data/lib/zendesk_support_api/jobs.rb +95 -0
- data/lib/zendesk_support_api/organizations.rb +268 -0
- data/lib/zendesk_support_api/search.rb +115 -0
- data/lib/zendesk_support_api/tickets.rb +335 -0
- data/lib/zendesk_support_api/users.rb +317 -0
- data/lib/zendesk_support_api/version.rb +7 -0
- data/zendesk_support_api.gemspec +21 -0
- metadata +88 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ZendeskSupportAPI
|
4
|
+
# Jobs class - https://developer.zendesk.com/rest_api/docs/support/job_statuses
|
5
|
+
class Jobs
|
6
|
+
# Make a request to show the job status
|
7
|
+
#
|
8
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
9
|
+
# @param id [String] The id of the job to check
|
10
|
+
# @return [Hash]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# client = ZendeskSupportAPI::Client.new('user', '123', 'zendesk.com/api')
|
14
|
+
# ZendeskSupportAPI::Jobs.show(client, 'abc123')
|
15
|
+
# #=> {
|
16
|
+
# #=> "job_status"=> {
|
17
|
+
# #=> "id"=>"abc123",
|
18
|
+
# #=> "url"=>"abc123.json",
|
19
|
+
# #=> "total"=>2,
|
20
|
+
# #=> "progress"=>2,
|
21
|
+
# #=> "status"=>"completed",
|
22
|
+
# #=> "message"=>"Completed at 2020-04-29 13:26:40 +0000",
|
23
|
+
# #=> "results"=> [
|
24
|
+
# #=> {
|
25
|
+
# #=> "id"=>369731992959,
|
26
|
+
# #=> "status"=>"Updated",
|
27
|
+
# #=> "email"=>"test@example.com"
|
28
|
+
# #=> },
|
29
|
+
# #=> {
|
30
|
+
# #=> "id"=>369728778639,
|
31
|
+
# #=> "status"=>"Updated",
|
32
|
+
# #=> "email"=>"test2@example.com"
|
33
|
+
# #=> }
|
34
|
+
# #=> ]
|
35
|
+
# #=> }
|
36
|
+
# #=> }
|
37
|
+
|
38
|
+
def self.show(client, id)
|
39
|
+
client.request(:get, "job_statuses/#{id}.json")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Make a request to show all job statuses
|
43
|
+
#
|
44
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
45
|
+
# @return [Hash]
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# ZendeskSupportAPI::Jobs.show_many(client, ['abc123', 'def456'])
|
49
|
+
# #=> {
|
50
|
+
# #=> "job_statuses": [
|
51
|
+
# #=> {
|
52
|
+
# #=> "id": "abc123",
|
53
|
+
# #=> "status": "completed",
|
54
|
+
# #=> ...
|
55
|
+
# #=> },
|
56
|
+
# #=> {
|
57
|
+
# #=> "id": "def456",
|
58
|
+
# #=> "status": "completed",
|
59
|
+
# #=> ...
|
60
|
+
# #=> }
|
61
|
+
# #=> ]
|
62
|
+
# #=> }
|
63
|
+
|
64
|
+
def self.list(client)
|
65
|
+
client.request(:get, 'job_statuses.json')['job_statuses']
|
66
|
+
end
|
67
|
+
|
68
|
+
# Show many job statuses
|
69
|
+
#
|
70
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
71
|
+
# @param ids [Array] An Array of job IDs to show
|
72
|
+
# @return [Hash]
|
73
|
+
#
|
74
|
+
# @example
|
75
|
+
# ZendeskSupportAPI::Jobs.show_many(client, ['abc123', 'def456'])
|
76
|
+
# #=> {
|
77
|
+
# #=> "job_statuses": [
|
78
|
+
# #=> {
|
79
|
+
# #=> "id": "abc123",
|
80
|
+
# #=> "status": "completed",
|
81
|
+
# #=> ...
|
82
|
+
# #=> },
|
83
|
+
# #=> {
|
84
|
+
# #=> "id": "def456",
|
85
|
+
# #=> "status": "completed",
|
86
|
+
# #=> ...
|
87
|
+
# #=> }
|
88
|
+
# #=> ]
|
89
|
+
# #=> }
|
90
|
+
|
91
|
+
def self.show_many(client, ids)
|
92
|
+
client.request(:get, "job_statuses/show_many.json?ids=#{ids.join(',')}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ZendeskSupportAPI
|
4
|
+
# Organizations class - https://developer.zendesk.com/rest_api/docs/support/organizations
|
5
|
+
class Organizations
|
6
|
+
# Prints out organizations
|
7
|
+
#
|
8
|
+
# @return [String]
|
9
|
+
|
10
|
+
def self.orgs
|
11
|
+
'organizations'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Lists Organizations (first 100)
|
15
|
+
#
|
16
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
17
|
+
# @return [Array]
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# ZendeskSupportAPI::Organizations.list(client)
|
21
|
+
# #=> [
|
22
|
+
# #=> {
|
23
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/1.json",
|
24
|
+
# #=> "id": 1,
|
25
|
+
# #=> "name": "One Organization",
|
26
|
+
# #=> ...
|
27
|
+
# #=> },
|
28
|
+
# #=> ...
|
29
|
+
# #=> {
|
30
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/100.json",
|
31
|
+
# #=> "id: 100,
|
32
|
+
# #=> "name": "Other Organization",
|
33
|
+
# #=> ...
|
34
|
+
# #=> }
|
35
|
+
# #=> ]
|
36
|
+
|
37
|
+
def self.list(client)
|
38
|
+
client.request(:get, "#{orgs}.json")[orgs]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Shows info about an organization
|
42
|
+
#
|
43
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
44
|
+
# @param oid [Integer] The Organization ID to use
|
45
|
+
# @return [Hash]
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# ZendeskSupportAPI::Organizations.show(client, 123)
|
49
|
+
# #=> {
|
50
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/1.json",
|
51
|
+
# #=> "id": 1,
|
52
|
+
# #=> "name": "One Organization",
|
53
|
+
# #=> ...
|
54
|
+
# #=> }
|
55
|
+
|
56
|
+
def self.show(client, oid)
|
57
|
+
client.request(:get, "#{orgs}/#{oid}.json")['organization']
|
58
|
+
end
|
59
|
+
|
60
|
+
# Show several organizations
|
61
|
+
#
|
62
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
63
|
+
# @param oids [Array] An Array of Organization IDs to show
|
64
|
+
# @return [Array]
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# ZendeskSupportAPI::Organizations.show(client, [1,2])
|
68
|
+
# #=> [
|
69
|
+
# #=> {
|
70
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/1.json",
|
71
|
+
# #=> "id": 1,
|
72
|
+
# #=> "name": "One Organization",
|
73
|
+
# #=> ...
|
74
|
+
# #=> },
|
75
|
+
# #=> {
|
76
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/2.json",
|
77
|
+
# #=> "id": 2,
|
78
|
+
# #=> "name": "Two Organization",
|
79
|
+
# #=> ...
|
80
|
+
# #=> }
|
81
|
+
# #=> ]
|
82
|
+
|
83
|
+
def self.show_many(client, oids)
|
84
|
+
ids = "ids=#{oids.join(',')}"
|
85
|
+
client.request(:get, "#{orgs}/show_many.json?#{ids}")[orgs]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Creates an organization
|
89
|
+
#
|
90
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
91
|
+
# @param org [Hash] The organization info to use
|
92
|
+
# @return [Hash|String]
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# org = {
|
96
|
+
# name: 'Test Organization',
|
97
|
+
# }
|
98
|
+
# ZendeskSupportAPI::Organizations.create(client, org)
|
99
|
+
# #=> {
|
100
|
+
# #=> "url": "",
|
101
|
+
# #=> "id": 123,
|
102
|
+
# #=> "name": "Test Organization",
|
103
|
+
# #=> ...
|
104
|
+
# #=> }
|
105
|
+
|
106
|
+
def self.create(client, org)
|
107
|
+
res = client.request(:post, "#{orgs}.json", organization: org)
|
108
|
+
return "Creation failed: #{res['details']}" if res['error']
|
109
|
+
|
110
|
+
res['organization']
|
111
|
+
end
|
112
|
+
|
113
|
+
# Creates many organizations
|
114
|
+
#
|
115
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
116
|
+
# @param orgs [Array] The organizations to create
|
117
|
+
# @return [ZendeskSupportAPI::Client.handle_job]
|
118
|
+
|
119
|
+
def self.create_many(client, orgs)
|
120
|
+
url = "#{orgs}/create_many.json"
|
121
|
+
res = client.request(:post, url, organizations: orgs)
|
122
|
+
client.handle_job(res)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Creates or updates an organization
|
126
|
+
#
|
127
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
128
|
+
# @param org [Hash] The organization info to use
|
129
|
+
# @return [Hash|String]
|
130
|
+
#
|
131
|
+
# @example
|
132
|
+
# org = {
|
133
|
+
# name: 'Test Organization',
|
134
|
+
# }
|
135
|
+
# ZendeskSupportAPI::Organizations.create_or_update(client, org)
|
136
|
+
# #=> {
|
137
|
+
# #=> "url": "",
|
138
|
+
# #=> "id": 123,
|
139
|
+
# #=> "name": "Test Organization",
|
140
|
+
# #=> ...
|
141
|
+
# #=> }
|
142
|
+
|
143
|
+
def self.create_or_update(client, org)
|
144
|
+
url = "#{orgs}/create_or_update.json"
|
145
|
+
res = client.request(:post, url, organization: org)
|
146
|
+
return "Create/Update failed: #{res['description']}" if res['error']
|
147
|
+
|
148
|
+
res['organization']
|
149
|
+
end
|
150
|
+
|
151
|
+
# Updates an organization
|
152
|
+
#
|
153
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
154
|
+
# @param oid [Integer] The Organization ID to use
|
155
|
+
# @param org [Hash] The organization info to use
|
156
|
+
# @return [Hash|String]
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# ZendeskSupportAPI::Organizations.update(client, 123, org)
|
160
|
+
# #=> {organization}
|
161
|
+
|
162
|
+
def self.update(client, oid, org)
|
163
|
+
res = client.request(:post, "#{orgs}/#{oid}.json", organization: org)
|
164
|
+
return "Update of #{uid} failed: #{res['error']}" if res['error']
|
165
|
+
|
166
|
+
res['organization']
|
167
|
+
end
|
168
|
+
|
169
|
+
# Updates many organizations
|
170
|
+
#
|
171
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
172
|
+
# @param orgs [Array] The organizations to update
|
173
|
+
# @return [ZendeskSupportAPI::Client.handle_job]
|
174
|
+
|
175
|
+
def self.update_many(client, orgs)
|
176
|
+
url = "#{orgs}/update_many.json"
|
177
|
+
res = client.request(:put, url, organizations: orgs)
|
178
|
+
client.handle_job(res)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Deletes an organization
|
182
|
+
#
|
183
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
184
|
+
# @param oid [Integer] The Organization ID to delete
|
185
|
+
# @return [String]
|
186
|
+
#
|
187
|
+
# @example
|
188
|
+
# ZendeskSupportAPI::Organizations.delete(client, 123)
|
189
|
+
# #=> Organization 123 has been deleted
|
190
|
+
# ZendeskSupportAPI::Organizations.delete(client, 123)
|
191
|
+
# #=> "Deletion of 123 failed: RecordNotFound"
|
192
|
+
|
193
|
+
def self.delete(client, oid)
|
194
|
+
res = client.request(:delete, "#{orgs}/#{oid}.json")
|
195
|
+
return "Deletion of #{oid} failed: #{res['error']}" if res['error']
|
196
|
+
|
197
|
+
"Organization #{uid} has been deleted"
|
198
|
+
end
|
199
|
+
|
200
|
+
# Deletes many organizations
|
201
|
+
#
|
202
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
203
|
+
# @param ids [Array] The array of Organization IDs to delete
|
204
|
+
# @return [ZendeskSupportAPI::Client.handle_job
|
205
|
+
|
206
|
+
def self.bulk_delete(client, ids)
|
207
|
+
url = "#{orgs}/destroy_many.json?ids=#{ids.join(',')}"
|
208
|
+
res = client.request(:delete, url)
|
209
|
+
client.handle_job(res)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Searches for orgs by their external_id (first 100)
|
213
|
+
#
|
214
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
215
|
+
# @param eid [String] The External ID to use
|
216
|
+
# @return [Array]
|
217
|
+
#
|
218
|
+
# @example
|
219
|
+
# ZendeskSupportAPI::Organizations.search_by_external_id(client, 'abc123')
|
220
|
+
# #=> [
|
221
|
+
# #=> {
|
222
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/1.json",
|
223
|
+
# #=> "id": 1,
|
224
|
+
# #=> "name": "One Organization",
|
225
|
+
# #=> ...
|
226
|
+
# #=> },
|
227
|
+
# #=> ...
|
228
|
+
# #=> {
|
229
|
+
# #=> "url": "https://zendesk.com/api/v2/organizations/100.json",
|
230
|
+
# #=> "id: 100,
|
231
|
+
# #=> "name": "Other Organization",
|
232
|
+
# #=> ...
|
233
|
+
# #=> }
|
234
|
+
# #=> ]
|
235
|
+
|
236
|
+
def self.search_by_external_id(client, eid)
|
237
|
+
client.request(:get, "#{orgs}/search.json?external_id=#{eid}")[orgs]
|
238
|
+
end
|
239
|
+
|
240
|
+
# Get an Organization's members
|
241
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
242
|
+
# @param oid [Integer] The Organization ID to use
|
243
|
+
# @return [Array]
|
244
|
+
#
|
245
|
+
# @example
|
246
|
+
# ZendeskSupportAPI::Organizations.members(client, 123)
|
247
|
+
# #=> [
|
248
|
+
# #=> {
|
249
|
+
# #=> "id": 1,
|
250
|
+
# #=> "name": "Albert",
|
251
|
+
# #=> "email": "albert@example.com",
|
252
|
+
# #=> ...
|
253
|
+
# #=> },
|
254
|
+
# #=> ...
|
255
|
+
# #=> {
|
256
|
+
# #=> "id": 22,
|
257
|
+
# #=> "name": "Victor",
|
258
|
+
# #=> "email": "victor@example.com",
|
259
|
+
# #=> ...
|
260
|
+
# #=> }
|
261
|
+
# #=> ]
|
262
|
+
|
263
|
+
def self.members(client, oid)
|
264
|
+
url = "#{orgs}/#{oid}/organization_memberships.json?include=users"
|
265
|
+
client.request(:get, url)['users']
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ZendeskSupportAPI
|
4
|
+
# Search class - https://developer.zendesk.com/rest_api/docs/support/search
|
5
|
+
class Search
|
6
|
+
# Perform a search and list results (first 100)
|
7
|
+
#
|
8
|
+
# @param client [ZendeskSupportAPI::Client] The client instance to use
|
9
|
+
# @param query [String] The query to use
|
10
|
+
# @param sort [String] The sorting method to use (defaults to revelance)
|
11
|
+
# @param order [String] The order to use (defaults to desc)
|
12
|
+
# @return [Array]
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# ZendeskSupportAPI::Search.list(client, 'bob')
|
16
|
+
# #=> [
|
17
|
+
# #=> {
|
18
|
+
# #=> "name": "Bob McBob",
|
19
|
+
# #=> "created_at": "2009-05-13T00:07:08Z",
|
20
|
+
# #=> "updated_at": "2011-07-22T00:11:12Z",
|
21
|
+
# #=> "id": 211,
|
22
|
+
# #=> "result_type": "user"
|
23
|
+
# #=> "url": "https://zendesk.com/api/v2/users/211.json"
|
24
|
+
# #=> },
|
25
|
+
# #=> {
|
26
|
+
# #=> "name": "Bob's Company",
|
27
|
+
# #=> "created_at": "2009-08-26T00:07:08Z",
|
28
|
+
# #=> "updated_at": "2010-05-13T00:07:08Z",
|
29
|
+
# #=> "id": 122,
|
30
|
+
# #=> "result_type": "group"
|
31
|
+
# #=> "url": "https://zendesk.com/api/v2/groups/122.json"
|
32
|
+
# #=> },
|
33
|
+
# #=> ...
|
34
|
+
# #=> ]
|
35
|
+
|
36
|
+
def self.list(client, query, sort = '', order = 'desc')
|
37
|
+
return bad_search("invalid sort - #{sort}") unless sort_valid?(sort)
|
38
|
+
return bad_search("invalid order - #{order}") unless order_valid?(order)
|
39
|
+
|
40
|
+
sort_order = sort_order_string(sort, order)
|
41
|
+
client.request(:get, "search.json?query=#{query}#{sort_order}")['results']
|
42
|
+
end
|
43
|
+
|
44
|
+
# Determines if a given sort string is valid
|
45
|
+
#
|
46
|
+
# @param sort [String] The sort string to check
|
47
|
+
# @return [Boolean]
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# ZendeskSupportAPI::Search.sort_valid? 'updated_at'
|
51
|
+
# #=> true
|
52
|
+
# ZendeskSupportAPI::Search.sort_valid? 'ticket_type'
|
53
|
+
# #=> true
|
54
|
+
# ZendeskSupportAPI::Search.sort_valid? 'random'
|
55
|
+
# #=> false
|
56
|
+
|
57
|
+
def self.sort_valid?(sort)
|
58
|
+
return true if sort.empty?
|
59
|
+
|
60
|
+
valid = %w[updated_at created_at priority status ticket_type]
|
61
|
+
valid.include? sort
|
62
|
+
end
|
63
|
+
|
64
|
+
# Determines if a given order string is valid
|
65
|
+
#
|
66
|
+
# @param order [String] The order string to check
|
67
|
+
# @return [Boolean]
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# ZendeskSupportAPI::Search.order_valid? 'asc'
|
71
|
+
# #=> true
|
72
|
+
# ZendeskSupportAPI::Search.order_valid? 'desc'
|
73
|
+
# #=> true
|
74
|
+
# ZendeskSupportAPI::Search.order_valid? 'random'
|
75
|
+
# #=> false
|
76
|
+
|
77
|
+
def self.order_valid?(order)
|
78
|
+
valid = %w[asc desc]
|
79
|
+
valid.include? order
|
80
|
+
end
|
81
|
+
|
82
|
+
# Prints out an error message
|
83
|
+
#
|
84
|
+
# @param string [String] The error that occurred
|
85
|
+
# @return [String]
|
86
|
+
#
|
87
|
+
# @example
|
88
|
+
# ZendeskSupportAPI::Search.bad_search('invalid sort - name')
|
89
|
+
# #=> "Search cannot be completed: invalid sort - name"
|
90
|
+
|
91
|
+
def self.bad_search(string)
|
92
|
+
"Search cannot be completed: #{string}"
|
93
|
+
end
|
94
|
+
|
95
|
+
# Determines the sort and order to use in the query
|
96
|
+
#
|
97
|
+
# @param sort [String] The sort string to use
|
98
|
+
# @param order [String] The order string to use
|
99
|
+
# @return [String]
|
100
|
+
#
|
101
|
+
# @example
|
102
|
+
# ZendeskSupportAPI::Search.sort_order_string('', 'asc')
|
103
|
+
# #=> "&order_by=asc"
|
104
|
+
# ZendeskSupportAPI::Search.sort_order_string('priority', 'desc')
|
105
|
+
# #=> "&sort_by=priority"
|
106
|
+
# ZendeskSupportAPI::Search.sort_order_string('updated_at', 'asc')
|
107
|
+
# #=> "&sort_by=updated_at&order_by=asc"
|
108
|
+
|
109
|
+
def self.sort_order_string(sort, order)
|
110
|
+
sort = (sort.empty? ? '' : "&sort_by=#{sort}")
|
111
|
+
order = (order == 'desc' ? '' : '&order_by=asc')
|
112
|
+
"#{sort}#{order}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|