Class: Readiness::Zendesk::Tickets
- Inherits:
-
Client
- Object
- Client
- Readiness::Zendesk::Tickets
show all
- Defined in:
- lib/support_readiness/zendesk/tickets.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.ccs(client, ticket) ⇒ Array
Lists the CCs on a ticket.
-
.collaborators(client, ticket) ⇒ Array
Lists the collaborators on a ticket.
-
.comments(client, ticket, sort = 'created_at') ⇒ Array
Lists the comments on a ticket.
-
.create!(client, ticket) ⇒ Object
-
.create_many!(client, tickets) ⇒ object
Creates multiple tickets via a batch job.
-
.create_satisfaction_score!(client, ticket, score, comment) ⇒ Hash
Add a satisfaction rating to a ticket (must be done using end-user as the config.username).
-
.delete!(client, ticket) ⇒ Boolean
-
.delete_many!(client, tids) ⇒ object
Deletes multiple tickets via a batch job.
-
.delete_many_suspended!(client, sids) ⇒ Boolean
Deletes many suspended tickets within Zendesk.
-
.delete_permanently!(client, tid) ⇒ Object
Deletes a deleted ticket.
-
.delete_suspended!(client, sid) ⇒ Boolean
Deletes a suspended ticket within Zendesk.
-
.find(client, tid) ⇒ Hash
Locates a ticket within Zendesk.
-
.find!(client, tid) ⇒ Hash
Locates a ticket within Zendesk.
-
.find_many(client, tids) ⇒ Array
Locates up to 100 tickets within Zendesk.
-
.followers(client, ticket) ⇒ Array
Lists the followers on a ticket.
-
.incidents(client, ticket) ⇒ Array
Lists the incident tickets connected to a specific ticket.
-
.list(client, sort = 'id') ⇒ Array
Lists the first 100 non-archived tickets.
-
.list_deleted(client, sort = 'id') ⇒ Array
Lists the first 100 deleted tickets.
-
.list_many(client, limit = 0, sort = 'id') ⇒ Array
-
.list_many_deleted(client, limit = 0, sort = 'id') ⇒ Array
Lists many deleted tickets.
-
.list_suspended(client) ⇒ Array
Locates all suspended tickets within Zendesk.
-
.mark_as_spam!(client, ticket) ⇒ Boolean
Marks a ticket as spam and suspends the user.
-
.problems(client) ⇒ Array
Lists all problem tickets.
-
.recover_many_suspended!(client, sids) ⇒ Array
Recover many suspended tickets within Zendesk.
-
.recover_suspended!(client, sid) ⇒ Object
Recovers a suspended ticket within Zendesk.
-
.redact_attachments(client, ticket) ⇒ Boolean
Redacts all attachments (inline and external) within a ticket.
-
.redact_attachments!(client, ticket) ⇒ Boolean
Redacts all attachments (inline and external) within a ticket.
-
.restore!(client, tid) ⇒ Boolean
Restores a deleted ticket.
-
.update!(client, ticket) ⇒ Object
-
.update_many!(client, tickets) ⇒ object
Updates multiple tickets via a batch job.
Instance Method Summary
collapse
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ Tickets
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 24
def initialize(object = {})
@assignee_id = object['assignee_id']
@additional_tags = object['additional_tags']
@brand_id = object['brand_id']
@collaborator_ids = object['collaborator_ids']
@comment = object['comment']
@created_at = object['created_at']
@custom_fields = object['custom_fields']
@custom_status_id = object['custom_status_id']
@description = object['description']
@due_at = object['due_at']
@email_cc_ids = object['email_cc_ids']
@email_ccs = object['email_ccs']
@fields = object['fields']
@follower_ids = object['follower_ids']
@followup_ids = object['followup_ids']
@group_id = object['group_id']
@has_incidents = object['has_incidents']
@id = object['id']
@is_public = object['is_public']
@organization_id = object['organization_id']
@priority = object['priority']
@problem_id = object['problem_id']
@remove_tags = object['remove_tags']
@requester = object['requester']
@requester_id = object['request_id']
@satisfaction_rating = object['satisfaction_rating']
@status = object['status']
@subject = object['subject']
@submitter_id = object['submitter_id']
@tags = object['tags']
@ticket_form_id = object['ticket_form_id']
@type = object['type']
@updated_at = object['updated_at']
@via = object['via']
@via_followup_source_id = object['via_followup_source_id']
end
|
Instance Attribute Details
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def additional_tags
@additional_tags
end
|
#assignee_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def assignee_id
@assignee_id
end
|
#brand_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def brand_id
@brand_id
end
|
#collaborator_ids ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def collaborator_ids
@collaborator_ids
end
|
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def
@comment
end
|
#created_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def created_at
@created_at
end
|
#custom_fields ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def custom_fields
@custom_fields
end
|
#custom_status_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def custom_status_id
@custom_status_id
end
|
#description ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def description
@description
end
|
#due_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def due_at
@due_at
end
|
#email_cc_ids ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def email_cc_ids
@email_cc_ids
end
|
#email_ccs ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def email_ccs
@email_ccs
end
|
#fields ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def fields
@fields
end
|
#follower_ids ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def follower_ids
@follower_ids
end
|
#followup_ids ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def followup_ids
@followup_ids
end
|
#group_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def group_id
@group_id
end
|
#has_incidents ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def has_incidents
@has_incidents
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def id
@id
end
|
#is_public ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def is_public
@is_public
end
|
#organization_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def organization_id
@organization_id
end
|
#priority ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def priority
@priority
end
|
#problem_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def problem_id
@problem_id
end
|
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def remove_tags
@remove_tags
end
|
#requester ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def requester
@requester
end
|
#requester_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def requester_id
@requester_id
end
|
#satisfaction_rating ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def satisfaction_rating
@satisfaction_rating
end
|
#status ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def status
@status
end
|
#subject ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def subject
@subject
end
|
#submitter_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def submitter_id
@submitter_id
end
|
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def tags
@tags
end
|
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def ticket_form_id
@ticket_form_id
end
|
#type ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def type
@type
end
|
#updated_at ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def updated_at
@updated_at
end
|
#via ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def via
@via
end
|
#via_followup_source_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 13
def via_followup_source_id
@via_followup_source_id
end
|
Class Method Details
.ccs(client, ticket) ⇒ Array
Lists the CCs on a ticket. If your system is not using followers, you need to use collaborators
134
135
136
137
138
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 134
def self.ccs(client, ticket)
response = client.connection.get("tickets/#{ticket.id}/email_ccs")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
Oj.load(response.body)['users']
end
|
.collaborators(client, ticket) ⇒ Array
Lists the collaborators on a ticket
82
83
84
85
86
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 82
def self.collaborators(client, ticket)
response = client.connection.get("tickets/#{ticket.id}/collaborators")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
Oj.load(response.body)['users']
end
|
Lists the comments on a ticket
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 253
def self.(client, ticket, sort = 'created_at')
array = []
opts = "page[size]=100&sort=#{sort}"
loop do
response = client.connection.get("tickets/#{ticket.id}/comments?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['comments']
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.create!(client, ticket) ⇒ Object
Creates a ticket. Will exit if unsuccessful
291
292
293
294
295
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 291
def self.create!(client, ticket)
response = client.connection.post 'tickets', to_clean_json_with_key(ticket, 'ticket')
handle_request_error(1, 'Zendesk', response.status, { action: 'Create ticket', message: Oj.load(response.body)}) unless response.status == 201
Tickets.new(Oj.load(response.body)['ticket'])
end
|
.create_many!(client, tickets) ⇒ object
Creates multiple tickets via a batch job
224
225
226
227
228
229
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 224
def self.create_many!(client, tickets)
data = { tickets: tickets.map { |t| to_hash(t).compact } }.to_json
response = client.connection.post('tickets/create_many', data)
handle_request_error(1, 'Zendesk', response.status, { action: 'Create many tickets', message: Oj.load(response.body)}) unless response.status == 200
JobStatuses.new(Oj.load(response.body)['job_status'])
end
|
.create_satisfaction_score!(client, ticket, score, comment) ⇒ Hash
Add a satisfaction rating to a ticket (must be done using end-user as the config.username). Will exit if unsuccessful
975
976
977
978
979
980
981
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 975
def self.create_satisfaction_score!(client, ticket, score, )
data = { satisfaction_rating: { score: score, comment: }}.to_json
response = client.post "tickets/#{ticket.id}/satisfaction_rating", data
pp response.body
handle_request_error(1, 'Zendesk', response.status, { action: 'Add satisfaction rating', message: Oj.load(response.body)}) unless response.status == 200
Oj.load(response.body)['satisfaction_rating']
end
|
.delete!(client, ticket) ⇒ Boolean
Deletes a ticket. Will exit if unsuccessful
372
373
374
375
376
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 372
def self.delete!(client, ticket)
response = client.connection.delete "tickets/#{ticket.id}"
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a ticket', id: ticket.id, message: Oj.load(response.body)}) unless response.status == 204
true
end
|
.delete_many!(client, tids) ⇒ object
Deletes multiple tickets via a batch job
159
160
161
162
163
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 159
def self.delete_many!(client, tids)
response = client.connection.delete("tickets/destroy_many?ids=#{tids.join(',')}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many tickets', message: Oj.load(response.body)}) unless response.status == 200
JobStatuses.new(Oj.load(response.body)['job_status'])
end
|
.delete_many_suspended!(client, sids) ⇒ Boolean
Deletes many suspended tickets within Zendesk.
848
849
850
851
852
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 848
def self.delete_many_suspended!(client, sids)
response = client.connection.delete("suspended_tickets/destroy_many?ids=#{sids.join(',')}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many suspended ticket', id: sids }) unless response.status == 200
true
end
|
.delete_permanently!(client, tid) ⇒ Object
Deletes a deleted ticket. This will exit if unsuccessful
496
497
498
499
500
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 496
def self.delete_permanently!(client, tid)
response = client.connection.delete "deleted_tickets/#{tid}"
handle_request_error(1, 'Zendesk', response.status) unless response.status == 200
JobStatuses.new(Oj.load(response.body)['job_status'])
end
|
.delete_suspended!(client, sid) ⇒ Boolean
Deletes a suspended ticket within Zendesk.
823
824
825
826
827
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 823
def self.delete_suspended!(client, sid)
response = client.connection.delete("suspended_tickets/#{sid}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete suspended ticket', id: sid }) unless response.status == 204
true
end
|
.find(client, tid) ⇒ Hash
Locates a ticket within Zendesk. This will not exit on error (except Authentication errors)
663
664
665
666
667
668
669
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 663
def self.find(client, tid)
response = client.connection.get("tickets/#{tid}")
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: tid }) unless response.status == 200
return Tickets.new(Oj.load(response.body)['ticket']) if response.status == 200
Oj.load(response.body)
end
|
.find!(client, tid) ⇒ Hash
Locates a ticket within Zendesk. This will exit on error
690
691
692
693
694
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 690
def self.find!(client, tid)
response = client.connection.get("tickets/#{tid}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Find ticket', id: tid }) unless response.status == 200
Tickets.new(Oj.load(response.body)['ticket'])
end
|
.find_many(client, tids) ⇒ Array
Locates up to 100 tickets within Zendesk.
715
716
717
718
719
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 715
def self.find_many(client, tids)
response = client.connection.get("tickets/show_many?ids=#{tids.join(',')}")
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: tids }) unless response.status == 200
Oj.load(response.body)['tickets'].map { |t| Tickets.new(t) }
end
|
.followers(client, ticket) ⇒ Array
Lists the followers on a ticket
108
109
110
111
112
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 108
def self.followers(client, ticket)
response = client.connection.get("tickets/#{ticket.id}/followers")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
Oj.load(response.body)['users']
end
|
.incidents(client, ticket) ⇒ Array
Lists the incident tickets connected to a specific ticket.
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 522
def self.incidents(client, ticket)
array = []
opts = "page[size]=100"
loop do
response = client.connection.get("tickets/#{ticket.id}/incidents?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['tickets'].map { |t| Tickets.new(t) }
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.list(client, sort = 'id') ⇒ Array
Lists the first 100 non-archived tickets
595
596
597
598
599
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 595
def self.list(client, sort = 'id')
response = client.connection.get("tickets?page[size]=100&sort=#{sort}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
Oj.load(response.body)['tickets'].map { |t| Tickets.new(t) }
end
|
.list_deleted(client, sort = 'id') ⇒ Array
Lists the first 100 deleted tickets
403
404
405
406
407
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 403
def self.list_deleted(client, sort = 'id')
response = client.connection.get("deleted_tickets?page[size]=100&sort=#{sort}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
Oj.load(response.body)['deleted_tickets']
end
|
.list_many(client, limit = 0, sort = 'id') ⇒ Array
Lists many tickets. Does not stop until it ends or the page limit is hit. This method can take a long time to run depending on the parameters used.
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 628
def self.list_many(client, limit = 0, sort = 'id')
array = []
opts = "page[size]=100&sort=#{sort}"
loop do
response = client.connection.get("tickets?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['tickets'].map { |t| Tickets.new(t) }
break if limit != 0 && array.count >= (limit * 100)
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.list_many_deleted(client, limit = 0, sort = 'id') ⇒ Array
Lists many deleted tickets. Does not stop until it ends or the page limit is hit. This method can take a long time to run depending on the parameters used.
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 436
def self.list_many_deleted(client, limit = 0, sort = 'id')
array = []
opts = "page[size]=100&sort=#{sort}"
loop do
response = client.connection.get("deleted_tickets?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['deleted_tickets']
break if limit != 0 && array.count >= (limit * 100)
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.list_suspended(client) ⇒ Array
Locates all suspended tickets within Zendesk.
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 739
def self.list_suspended(client)
array = []
opts = "page[size]=100"
loop do
response = client.connection.get("suspended_tickets?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['suspended_tickets']
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.mark_as_spam!(client, ticket) ⇒ Boolean
Marks a ticket as spam and suspends the user. Will exit if unsuccessful
346
347
348
349
350
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 346
def self.mark_as_spam!(client, ticket)
response = client.connection.put "tickets/#{ticket.id}/mark_as_spam"
handle_request_error(1, 'Zendesk', response.status, { action: 'Mark ticket as spam', id: ticket.id, message: Oj.load(response.body)}) unless response.status == 200
true
end
|
.problems(client) ⇒ Array
Lists all problem tickets
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 555
def self.problems(client)
array = []
opts = "page[size]=100"
loop do
response = client.connection.get("problems?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['tickets'].map { |t| Tickets.new(t) }
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.recover_many_suspended!(client, sids) ⇒ Array
Recover many suspended tickets within Zendesk
798
799
800
801
802
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 798
def self.recover_many_suspended!(client, sids)
response = client.connection.put("suspended_tickets/recover_many?ids=#{sids.join(',')}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Recover many suspended ticket', id: sids }) unless response.status == 200
Oj.load(response.body)['tickets'].map { |t| Tickets.new(t) }
end
|
.recover_suspended!(client, sid) ⇒ Object
Recovers a suspended ticket within Zendesk.
773
774
775
776
777
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 773
def self.recover_suspended!(client, sid)
response = client.connection.put("suspended_tickets/#{sid}/recover")
handle_request_error(1, 'Zendesk', response.status, { action: 'Recover suspended ticket', id: sid }) unless response.status == 200
Tickets.new(Oj.load(response.body)['ticket'])
end
|
.redact_attachments(client, ticket) ⇒ Boolean
Redacts all attachments (inline and external) within a ticket. This will not exit on error (except Authentication errors)
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 874
def self.redact_attachments(client, ticket)
redactions = []
Tickets.(client, ticket).each do |c|
object = {
id: c['id'],
redaction: { ticket_id: ticket.id }
}
object[:redaction][:external_attachment_urls] = c['attachments'].map { |a| a['content_url'] } unless c['attachments'].count.zero?
object[:redaction][:html_body] = c['html_body'].gsub('<img', '<img redact') if c['html_body'] =~ /<img/
redactions.push(object) unless object[:redaction][:external_attachment_urls].nil? && object[:redaction][:html_body].nil?
end
redactions.each do |r|
response = client.connection.put "comment_redactions/#{r[:id]}", r[:redaction].to_json
handle_request_error(0, 'Zendesk', response.status, { action: 'Redact attachments', id: "tickets/#{ticket.id}/comments/#{r[:id]}" }) unless response.status == 200
return false
end
true
end
|
.redact_attachments!(client, ticket) ⇒ Boolean
Redacts all attachments (inline and external) within a ticket. This will exit on error
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 913
def self.redact_attachments!(client, ticket)
redactions = []
Tickets.(client, ticket).each do |c|
object = {
id: c['id'],
redaction: { ticket_id: ticket.id }
}
object[:redaction][:external_attachment_urls] = c['attachments'].map { |a| a['content_url'] } unless c['attachments'].count.zero?
object[:redaction][:html_body] = c['html_body'].gsub('<img', '<img redact') if c['html_body'] =~ /<img/
redactions.push(object) unless object[:redaction][:external_attachment_urls].nil? && object[:redaction][:html_body].nil?
end
redactions.each do |r|
response = client.connection.put "comment_redactions/#{r[:id]}", r[:redaction].to_json
handle_request_error(1, 'Zendesk', response.status, { action: 'Redact attachments', id: "tickets/#{ticket.id}/comments/#{r[:id]}" }) unless response.status == 200
end
true
end
|
.restore!(client, tid) ⇒ Boolean
Restores a deleted ticket. This will exit if unsuccessful
471
472
473
474
475
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 471
def self.restore!(client, tid)
response = client.connection.put "deleted_tickets/#{tid}/restore"
handle_request_error(1, 'Zendesk', response.status) unless response.status == 200
true
end
|
.update!(client, ticket) ⇒ Object
Updates a ticket. Will exit if unsuccessful
320
321
322
323
324
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 320
def self.update!(client, ticket)
response = client.connection.put "tickets/#{ticket.id}", to_clean_json_with_key(ticket, 'ticket')
handle_request_error(1, 'Zendesk', response.status, { action: 'Update ticket', id: ticket.id, message: Oj.load(response.body)}) unless response.status == 200
Tickets.new(Oj.load(response.body)['ticket'])
end
|
.update_many!(client, tickets) ⇒ object
Updates multiple tickets via a batch job
189
190
191
192
193
194
|
# File 'lib/support_readiness/zendesk/tickets.rb', line 189
def self.update_many!(client, tickets)
data = { tickets: tickets.map { |t| to_hash(t).compact } }.to_json
response = client.connection.put('tickets/update_many', data)
handle_request_error(1, 'Zendesk', response.status, { action: 'Update many tickets', message: Oj.load(response.body)}) unless response.status == 200
JobStatuses.new(Oj.load(response.body)['job_status'])
end
|