zendesk_support_api 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c78cf01ac68e20c32f2e1d3ac3d47a9b4574012200718e33d06f3f92d75d9a68
4
- data.tar.gz: f066e3f7c5fbfd5008a8a2d8b3fff4ba416c8d9e5a3373a7f8b8d586126c5fb9
3
+ metadata.gz: bcf45ecf6e738bc42b2b2843be87308fd0ac25eec6bdc6f7f05f63dbd2e382a7
4
+ data.tar.gz: 7649928f9e3b6701d14aa93252dab9c641b71935d7461142f5e1d5130612971d
5
5
  SHA512:
6
- metadata.gz: f55d3a02c043022f70047bfe080d1227a9f1ea4dd9355f6e670ddb33187fd7bd6b79fbf207a99c671616ab0f370e56d4f9b8a510b966d50947a7c6e9ccf5c46e
7
- data.tar.gz: 4eeb5abd58621fc511552e686859e68e95cbec5b8cca8363b93c1b9a57cdb2e1f01860b21158351a5290e44b3c929307b231bfd3f65917d7e8fc3a6451211492
6
+ metadata.gz: 3b6057b660110d703092126a67180c69d989c67078cfc50b0edf6b2543f2efc26b209687fbd162257bc7f9cdd89e2b3174f92d3dadeae1cfc9146704f063ff9d
7
+ data.tar.gz: 987270880751bad257469be25b4ddf975f622a4a438533d04b89a66bbd093f7db54b291be4b22df02855d39be05b3b47b614622fd11d9ad7c2e23d0c39004d68
@@ -1,8 +1,10 @@
1
1
  lib/zendesk_support_api.rb fee89f019b11ec8feb844644e000cec6cad6a695
2
2
  lib/zendesk_support_api/jobs.rb 15e3db660bb16f1a2bc580ce17a9368f81fc9d0e
3
3
  lib/zendesk_support_api/users.rb eb4f8d81f6f9ccf779679f7bfe354c0cc6be8d0c
4
- lib/zendesk_support_api/client.rb 19147ca149a521a068e8a8818ad9b26091df0542
4
+ lib/zendesk_support_api/client.rb a9aedf0641e4160b66414e76854e40dd245df1a7
5
5
  lib/zendesk_support_api/groups.rb bcc2a0b1af5bf3552c7838d80f339efbf8636e53
6
6
  lib/zendesk_support_api/search.rb e741717c61809c578afbcd44f9b8e8f18a8c0363
7
- lib/zendesk_support_api/version.rb b95930e804ad2f9d4718efe8b3c740f79304913f
8
- lib/zendesk_support_api/organizations.rb 684c74525f26697a7a6e5fca921a1a937b0d20c8
7
+ lib/zendesk_support_api/tickets.rb 938c32872eeb5459d8d8dae5bb5a9361cb5968d8
8
+ lib/zendesk_support_api/version.rb 4a0944e207874b5ca81f14ae285d645d6d562928
9
+ lib/zendesk_support_api/organizations.rb 9e677997416275c0bbccd5aafc1e1f0b7f0bb4c3
10
+ lib/zendesk_support_api/deleted_tickets.rb 1c58c500e8adf19a910cc02bc7e18650e9751080
Binary file
Binary file
data/README.md CHANGED
@@ -47,13 +47,13 @@ Soon to come
47
47
  * v0.2.0 - Added Search functions, Fixed some yard syntax/formatting, Changed version number
48
48
  * v0.3.0 - Changed version number, Added Group functions, Added User.groups function
49
49
  * v0.4.0 - Added Organization functions, Changed version number
50
+ * v0.5.0 - Added DeletedTickets functions, Added Tickets functions, Yard synx fixes, updated version number
50
51
 
51
52
  ## Upcoming changes
52
53
 
53
- * v0.5.0 - Requests
54
- * v0.6.0 - Tickets
54
+ * v0.6.0 - Satisfaction
55
55
  * v0.7.0 - Attachments?
56
- * v0.8.0 - Satisfaction
56
+ * v0.8.0 - Requests
57
57
  * v0.9.0 - Sessions
58
58
  * v0.10.0 - Tags
59
59
  * v0.11.0 - Views
@@ -3,10 +3,12 @@
3
3
  module ZendeskSupportAPI
4
4
  # Client class - https://developer.zendesk.com/rest_api/docs/support/introduction#security-and-authentication
5
5
  class Client
6
+ require 'zendesk_support_api/deleted_tickets'
6
7
  require 'zendesk_support_api/groups'
7
8
  require 'zendesk_support_api/jobs'
8
9
  require 'zendesk_support_api/organizations'
9
10
  require 'zendesk_support_api/search'
11
+ require 'zendesk_support_api/tickets'
10
12
  require 'zendesk_support_api/users'
11
13
 
12
14
  # Create a new instance of Client
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Tickets class - https://developer.zendesk.com/rest_api/docs/support/tickets
5
+ class DeletedTickets
6
+ # Determines if given string is a valid order function
7
+ #
8
+ # @param order [String] The order string to use
9
+ # @return [Boolean]
10
+ #
11
+ # @example
12
+ # ZendeskSupportAPI::DeletedTickets.order_valid? 'desc' #=> true
13
+ # ZendeskSupportAPI::DeletedTickets.order_valid? 'random' #=> false
14
+
15
+ def self.order_valid?(order)
16
+ %w[desc asc].include? order
17
+ end
18
+
19
+ # Prints out the sort_by and order_by string for the url
20
+ #
21
+ # @param sort [String] The sort string to use
22
+ # @param order [String] The order string to use
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # ZendeskSupportAPI::DeletedTickets.sort_order('id', 'desc')
27
+ # #=> '&sort_by=id&order_by=desc'
28
+
29
+ def self.sort_order(sort, order)
30
+ "&sort_by=#{sort}&order_by=#{order}"
31
+ end
32
+
33
+ # Returns the string of the next_page for pagination
34
+ #
35
+ # @param res [Hash] The Hash containing the response from a request
36
+ # @return [nil|String]
37
+
38
+ def self.next_page(res)
39
+ (res['next_page'].nil? ? nil : res['next_page'].split('/').last)
40
+ end
41
+
42
+ # Prints out organization_id
43
+ #
44
+ # @return [String]
45
+ #
46
+ # @example
47
+ # ZendeskSupportAPI::DeletedTickets.org_id #=> 'organization_id'
48
+
49
+ def self.org_id
50
+ 'organization_id'
51
+ end
52
+
53
+ # Selects an object from an array based on a user ID
54
+ #
55
+ # @param array [Array] An array of to look in
56
+ # @param id [Integer] The ID to use
57
+ # @return [Hash]
58
+
59
+ def self.select_obj(array, id)
60
+ array.select { |a| a['id'] == id }.first
61
+ end
62
+
63
+ # Determines if sort value is valid for delete requests
64
+ #
65
+ # @param sort [String] The string to check
66
+ # @return [Boolean]
67
+
68
+ def self.deleted_sort_valid?(sort)
69
+ %w[id subject deleted_at].includes?(sort)
70
+ end
71
+
72
+ # Lists deleted tickets (first 100)
73
+ #
74
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
75
+ # @param sort [String] The sort string to use
76
+ # @param order [String] The order string to use
77
+ # @return [Array]
78
+
79
+ def self.list_deleted(client, sort = 'id', order = 'asc')
80
+ return "Invalid sort '#{sort}'" unless delete_sort_valid?(sort)
81
+ return "Invalid order '#{order}'" unless order_valid?(order)
82
+
83
+ url = "deleted_tickets.json?#{sort_order(sort, order)}"
84
+ client.request(:get, url)['deleted_tickets']
85
+ end
86
+
87
+ # Lists all deleted tickets
88
+ #
89
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
90
+ # @return [Array]
91
+
92
+ def self.list_all_deleted(client)
93
+ tickets = []
94
+ page = 'deleted_tickets.json?page=1'
95
+ until page.nil?
96
+ res = client.request(:get, page)
97
+ client.spinner("tickets (total: #{res['count']})", page.split('=').last)
98
+ tickets += res['tickets']
99
+ page = next_page(res)
100
+ end
101
+ puts ' ...done'
102
+ tickets
103
+ end
104
+
105
+ # Restores a deleted ticket
106
+ #
107
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
108
+ # @param tid [Integer] The ticket ID to use
109
+ # @return [nil|String]
110
+
111
+ def self.restore(client, tid)
112
+ res = client.request(:put, "deleted_tickets/#{tid}/restore.json")
113
+ return "Restore of #{tid} failed: #{res['error']}" if res['error']
114
+
115
+ res
116
+ end
117
+
118
+ # Restores several deleted tickets
119
+ #
120
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
121
+ # @param tids [Array] Array of ticket IDs to use
122
+ # @return [ZendeskSupportAPI::Client.handle_job]
123
+
124
+ def self.restore_many(client, tids)
125
+ url = "deleted_tickets/restore_many?ids=#{tids.join(',')}"
126
+ res = client.request(:put, url)
127
+ client.handle_job(res)
128
+ end
129
+ end
130
+ end
@@ -113,7 +113,7 @@ module ZendeskSupportAPI
113
113
  # Creates many organizations
114
114
  #
115
115
  # @param client [ZendeskSupportAPI::Client] The client instance to use
116
- # @param users [Array] The organizations to create
116
+ # @param orgs [Array] The organizations to create
117
117
  # @return [ZendeskSupportAPI::Client.handle_job]
118
118
 
119
119
  def self.create_many(client, orgs)
@@ -0,0 +1,335 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZendeskSupportAPI
4
+ # Tickets class - https://developer.zendesk.com/rest_api/docs/support/tickets
5
+ class Tickets
6
+ # Determines if given string is a valid sort function
7
+ #
8
+ # @param sort [String] The sort string to use
9
+ # @return [Boolean]
10
+ #
11
+ # @example
12
+ # ZendeskSupportAPI::Tickets.sort_valid? 'assignee' #=> true
13
+ # ZendeskSupportAPI::Tickets.sort_valid? 'blah' #=> false
14
+
15
+ def self.sort_valid?(sort)
16
+ valid = %w[assignee assignee_name created_at group id locale requester
17
+ requester.name status subject updated_at]
18
+ valid.include?(sort)
19
+ end
20
+
21
+ # Prints out the include string
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # ZendeskSupportAPI::Tickets.includes
27
+ # #=> '?include=users,organizations,ticket_forms,comment_count'
28
+
29
+ def self.includes
30
+ '?include=users,organizations,ticket_forms,comment_count'
31
+ end
32
+
33
+ # Prints out the sort_by and order_by string for the url
34
+ #
35
+ # @param sort [String] The sort string to use
36
+ # @param order [String] The order string to use
37
+ # @return [String]
38
+ #
39
+ # @example
40
+ # ZendeskSupportAPI::Tickets.sort_order('id', 'desc')
41
+ # #=> '&sort_by=id&order_by=desc'
42
+
43
+ def self.sort_order(sort, order)
44
+ "&sort_by=#{sort}&order_by=#{order}"
45
+ end
46
+
47
+ # Maps users into user_objects
48
+ #
49
+ # @param tickets [Array] The Array of tickets to map
50
+ # @param res [Hash] The has containing the response from a request
51
+ # @return [Hash]
52
+
53
+ def self.ticket_map(tickets, res)
54
+ tickets.map { |t| ticket_object(t, res) }
55
+ end
56
+
57
+ # Returns the string of the next_page for pagination
58
+ #
59
+ # @param res [Hash] The Hash containing the response from a request
60
+ # @return [nil|String]
61
+
62
+ def self.next_page(res)
63
+ (res['next_page'].nil? ? nil : res['next_page'].split('/').last)
64
+ end
65
+
66
+ # Prints out organization_id
67
+ #
68
+ # @return [String]
69
+ #
70
+ # @example
71
+ # ZendeskSupportAPI::Tickets.org_id #=> 'organization_id'
72
+
73
+ def self.org_id
74
+ 'organization_id'
75
+ end
76
+
77
+ # Creates a ticket object
78
+ #
79
+ # @param ticket [Hash] The ticket Hash to use
80
+ # @param res [Array] The response to use for mapping
81
+ # @return [Hash]
82
+
83
+ def self.ticket_object(ticket, res)
84
+ ticket.merge(
85
+ organization: select_obj(res['organizations'], ticket[org_id]),
86
+ form: select_obj(res['ticket_forms'], ticket['form_id']),
87
+ requester: select_obj(res['users'], ticket['requester_id']),
88
+ assignee: select_obj(res['users'], ticket['assignee_id'])
89
+ )
90
+ end
91
+
92
+ # Selects an object from an array based on a user ID
93
+ #
94
+ # @param array [Array] An array of to look in
95
+ # @param id [Integer] The ID to use
96
+ # @return [Hash]
97
+
98
+ def self.select_obj(array, id)
99
+ array.select { |a| a['id'] == id }.first
100
+ end
101
+
102
+ # List out tickets (first 100)
103
+ #
104
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
105
+ # @param sort [String] The sort method to use
106
+ # @param order [String] The order method to use
107
+ # @return [Array]
108
+ #
109
+ # @example
110
+ # ZendeskSupportAPI::Tickets.list(client)
111
+ # #=> [
112
+ # #=> {
113
+ # #=> "id": 35436,
114
+ # #=> "subject": "Help I need somebody!",
115
+ # #=> ...
116
+ # #=> },
117
+ # #=> {
118
+ # #=> "id": 20057623,
119
+ # #=> "subject": "Not just anybody!",
120
+ # #=> ...
121
+ # #=> },
122
+ # #=> ...
123
+ # #=> ]
124
+
125
+ def self.list(client, sort = 'id', order = 'asc')
126
+ return "Invalid sort '#{sort}'" unless sort_valid?(sort)
127
+ return "Invalid order '#{order}'" unless %w[asc desc].include?(order)
128
+
129
+ url = "tickets.json#{includes}#{sort_order(sort, order)}"
130
+ res = client.request(:get, url)
131
+ res['tickets'].map { |t| ticket_object(t, res) }
132
+ end
133
+
134
+ # Lists out all tickets (paginates over every page)
135
+ #
136
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
137
+ # @return [Array]
138
+ #
139
+ # @example
140
+ # ZendeskSupportAPI::Tickets.all(client)
141
+ # #=> Grabbing tickets (total: 215336)... / ...done
142
+ # #=> [{ticket1},{ticket2}...{ticket215336}]
143
+
144
+ def self.all(client)
145
+ tickets = []
146
+ page = "tickets.json#{includes}&page=1"
147
+ until page.nil?
148
+ res = client.request(:get, page)
149
+ client.spinner("tickets (total: #{res['count']})", page.split('=').last)
150
+ tickets += ticket_map(res['tickets'], res)
151
+ page = next_page(res)
152
+ end
153
+ puts ' ...done'
154
+ tickets
155
+ end
156
+
157
+ # Shows details about a specific ticket
158
+ #
159
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
160
+ # @param tid [Integer] The Ticket ID to use
161
+ # @return [Hash]
162
+ #
163
+ # @example
164
+ # ZendeskSupportAPI::Tickets.show(client, 35436)
165
+ # #=> {
166
+ # #=> "id": 35436,
167
+ # #=> "subject": "My printer is on fire!",
168
+ # #=> ...
169
+ # #=> }
170
+
171
+ def self.show(client, tid)
172
+ url = "tickets/#{tid}.json#{includes}"
173
+ res = client.request(:get, url)
174
+ res['ticket'].map { |t| ticket_object(t, res) }
175
+ end
176
+
177
+ # Show details about many tickets
178
+ #
179
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
180
+ # @param tids [Array] An array of ticket IDs
181
+ # @return [Array]
182
+
183
+ def self.show_many(client, tids)
184
+ url = "tickets/show_many.json#{includes}&ids=#{tids.join(',')}"
185
+ res = client.request(:get, url)
186
+ res['tickets'].map { |t| ticket_object(t, res) }
187
+ end
188
+
189
+ # Create a ticket
190
+ #
191
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
192
+ # @param ticket [Hash] The ticket hash to use for creation
193
+ # @return [Hash|String]
194
+ #
195
+ # @example
196
+ # ticket = {
197
+ # subject: "This is a test ticket",
198
+ # followers: [
199
+ # { user_email: 'albert@example.com', action: 'put' },
200
+ # { user_id: 123, action: 'put' }
201
+ # ],
202
+ # comment: {
203
+ # body: "This goes into the test ticket body!"
204
+ # },
205
+ # tags: ["free_user", "ignore"]
206
+ # }
207
+ # ZendeskSupportAPI::Tickets.create(client, ticket)
208
+ # #=> {
209
+ # #=> "id": 1,
210
+ # #=> "subject": "This is a test ticket",
211
+ # #=> ...
212
+ # #=> }
213
+
214
+ def self.create(client, ticket)
215
+ res = client.request(:post, 'tickets.json', ticket: ticket)
216
+ return "Creation failed: #{res['details']}" if res['error']
217
+
218
+ res
219
+ end
220
+
221
+ # Creates many tickets
222
+ #
223
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
224
+ # @param tickets [Array] The array of ticket hashes to use for creation
225
+ # @return [ZendeskSupportAPI::Client.handle_job]
226
+
227
+ def self.create_many(client, tickets)
228
+ res = client.request(:post, 'tickets/create_many.json', tickets: tickets)
229
+ client.handle_job(res)
230
+ end
231
+
232
+ # Updates a ticket
233
+ #
234
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
235
+ # @param tid [Integer] The ticket ID to update
236
+ # @param ticket [Hash] The ticket hash to use
237
+ # @return [Hash|String]
238
+
239
+ def self.update(client, tid, ticket)
240
+ res = client.request(:put, "tickets/#{tid}.json", ticket: ticket)
241
+ return "Update of #{tid} failed: #{res['error']}" if res['error']
242
+
243
+ res
244
+ end
245
+
246
+ # Updates many tickets
247
+ #
248
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
249
+ # @param tickets [Array] The array of ticket hashes to use for updates
250
+ # @return [ZendeskSupportAPI::Client.handle_job]
251
+ #
252
+ # @example
253
+ # tickets = [
254
+ # {
255
+ # id: 123,
256
+ # tags: ['ultimate', 'urgent']
257
+ # },
258
+ # {
259
+ # id: 124,
260
+ # followers: [
261
+ # { user_id: 123, action: 'delete' }
262
+ # ]
263
+ # },
264
+ # {
265
+ # id: 125,
266
+ # subject: 'Staging Instance having issues'
267
+ # }
268
+ # ]
269
+ # ZendeskSupportAPI::Tickets.update_many(client, tickets)
270
+
271
+ def self.update_many(client, tickets)
272
+ res = client.request(:put, 'tickets/update_many.json', tickets: tickets)
273
+ client.handle_job(res)
274
+ end
275
+
276
+ # Mark a ticket as spam and suspend the user
277
+ #
278
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
279
+ # @param tid [Integer] The ticket ID to use
280
+ # @return [String]
281
+
282
+ def self.mark_as_spam(client, tid)
283
+ res = client.request(:put, "tickets/#{tid}/mark_as_spam.json")
284
+ return "Unable to mark ticket as spam: #{res['error']}" if res['error']
285
+
286
+ "Ticket #{tid} marked as spam"
287
+ end
288
+
289
+ # Mark many tickets as spam and suspend their users
290
+ #
291
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
292
+ # @param tids [Array] The ticket IDs to use
293
+ # @return [ZendeskSupportAPI::Client.handle_job]
294
+
295
+ def self.mark_many_as_spam(client, tids)
296
+ url = "tickets/mark_many_as_spam.json?ids=#{tids.join(',')}"
297
+ res = client.request(:put, url)
298
+ client.handle_job(res)
299
+ end
300
+
301
+ # Merge Tickets into Target Ticket
302
+ #
303
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
304
+ # @param tid [Integer] The Ticket ID to merge into
305
+ # @param hash [Hash] The Hash to use for the merge (see example)
306
+ # @return [ZendeskSupportAPI::Client.handle_job]
307
+ #
308
+ # @example
309
+ # merge_hash = {
310
+ # ids: [112, 113, 114],
311
+ # source_comment: "Closing in favor of #111",
312
+ # target_comment: "Merging #112, #113, and #114 into this ticket"
313
+ # }
314
+ # ZendeskSupportAPI::Tickets.merge(client, 111, merge_hash)
315
+
316
+ def self.merge(client, tid, hash)
317
+ res = client.request(:post, "tickets/#{tid}/merge.json", hash)
318
+ client.handle_job(res)
319
+ end
320
+
321
+ # List followers of a ticket
322
+ #
323
+ # @param client [ZendeskSupportAPI::Client] The client instance to use
324
+ # @param tid [Integer] The Ticket ID to use
325
+ # @return [Array]
326
+
327
+ def self.list_followers(client, tid)
328
+ res = client.request(:get, "tickets/#{tid}/followers")['users']
329
+ res['users'].each do |user|
330
+ user['organization'] = select_obj(res['organizations'], user[org_id])
331
+ end
332
+ res['users']
333
+ end
334
+ end
335
+ end
@@ -3,5 +3,5 @@
3
3
  module ZendeskSupportAPI
4
4
  # Outputs the gem version
5
5
 
6
- VERSION = '0.4.0'
6
+ VERSION = '0.5.0'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_support_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Colyer
@@ -53,10 +53,12 @@ files:
53
53
  - README.md
54
54
  - lib/zendesk_support_api.rb
55
55
  - lib/zendesk_support_api/client.rb
56
+ - lib/zendesk_support_api/deleted_tickets.rb
56
57
  - lib/zendesk_support_api/groups.rb
57
58
  - lib/zendesk_support_api/jobs.rb
58
59
  - lib/zendesk_support_api/organizations.rb
59
60
  - lib/zendesk_support_api/search.rb
61
+ - lib/zendesk_support_api/tickets.rb
60
62
  - lib/zendesk_support_api/users.rb
61
63
  - lib/zendesk_support_api/version.rb
62
64
  - zendesk_support_api.gemspec