gitlab_support_readiness 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/support_readiness/client.rb +108 -0
- data/lib/support_readiness/gitlab/client.rb +64 -0
- data/lib/support_readiness/gitlab/configuration.rb +46 -0
- data/lib/support_readiness/gitlab/groups.rb +180 -0
- data/lib/support_readiness/gitlab/issues.rb +410 -0
- data/lib/support_readiness/gitlab/namespaces.rb +190 -0
- data/lib/support_readiness/gitlab/projects.rb +510 -0
- data/lib/support_readiness/gitlab/repositories.rb +267 -0
- data/lib/support_readiness/gitlab/users.rb +488 -0
- data/lib/support_readiness/gitlab.rb +19 -0
- data/lib/support_readiness/pagerduty/client.rb +66 -0
- data/lib/support_readiness/pagerduty/configuration.rb +43 -0
- data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
- data/lib/support_readiness/pagerduty/schedules.rb +223 -0
- data/lib/support_readiness/pagerduty/services.rb +132 -0
- data/lib/support_readiness/pagerduty.rb +16 -0
- data/lib/support_readiness/redis.rb +90 -0
- data/lib/support_readiness/zendesk/articles.rb +210 -0
- data/lib/support_readiness/zendesk/automations.rb +304 -0
- data/lib/support_readiness/zendesk/client.rb +84 -0
- data/lib/support_readiness/zendesk/configuration.rb +49 -0
- data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
- data/lib/support_readiness/zendesk/groups.rb +249 -0
- data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
- data/lib/support_readiness/zendesk/macros.rb +267 -0
- data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
- data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
- data/lib/support_readiness/zendesk/organizations.rb +515 -0
- data/lib/support_readiness/zendesk/roles.rb +194 -0
- data/lib/support_readiness/zendesk/search.rb +159 -0
- data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
- data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
- data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
- data/lib/support_readiness/zendesk/tickets.rb +854 -0
- data/lib/support_readiness/zendesk/triggers.rb +269 -0
- data/lib/support_readiness/zendesk/users.rb +946 -0
- data/lib/support_readiness/zendesk/views.rb +469 -0
- data/lib/support_readiness/zendesk.rb +31 -0
- data/lib/support_readiness.rb +29 -0
- metadata +215 -0
@@ -0,0 +1,188 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Zendesk
|
6
|
+
module Zendesk
|
7
|
+
##
|
8
|
+
# Defines the class JobStatuses within the module {Readiness::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
class JobStatuses < Readiness::Client
|
13
|
+
attr_accessor :id, :job_type, :message, :progress, :results, :status, :total
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Zendesk::JobStatuses} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.0
|
20
|
+
# @param object [Object] An instance of {Readiness::Zendesk::JobStatuses}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::Zendesk::JobStatuses.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@id = object['id']
|
26
|
+
@job_type = object['job_type']
|
27
|
+
@message = object['message']
|
28
|
+
@progress = object['progress']
|
29
|
+
@results = object['results']
|
30
|
+
@status = object['status']
|
31
|
+
@total = object['total']
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Lists the first 100 job statuses
|
36
|
+
#
|
37
|
+
# @author Jason Colyer
|
38
|
+
# @since 1.0.0
|
39
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
40
|
+
# @return [Array]
|
41
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#list-job-statuses Zendesk API > Job Statuses > List Job Statuses
|
42
|
+
# @example
|
43
|
+
# require 'support_readiness'
|
44
|
+
# config = Readiness::Zendesk::Configuration.new
|
45
|
+
# config.username = 'alice@example.com'
|
46
|
+
# config.token = 'test123abc'
|
47
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
48
|
+
# client = Readiness::Zendesk::Client.new(config)
|
49
|
+
# jobs = Readiness::Zendesk::JobStatuses.list(client)
|
50
|
+
# pp jobs.first.id
|
51
|
+
# # => "8b726e606741012ffc2d782bcb7848fe"
|
52
|
+
def self.list(client)
|
53
|
+
response = client.connection.get("job_statuses?page[size]=100")
|
54
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
55
|
+
Oj.load(response.body)['job_statuses'].map { |j| JobStatuses.new(j) }
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Locates a job status within Zendesk. This will not exit on error (except Authentication errors)
|
60
|
+
#
|
61
|
+
# @author Jason Colyer
|
62
|
+
# @since 1.0.0
|
63
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
64
|
+
# @param jid [String] The job status ID to find
|
65
|
+
# @return [Hash]
|
66
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#show-job-status Zendesk API > Job Statuses > Show Job Status
|
67
|
+
# @example
|
68
|
+
# require 'support_readiness'
|
69
|
+
# config = Readiness::Zendesk::Configuration.new
|
70
|
+
# config.username = 'alice@example.com'
|
71
|
+
# config.token = 'test123abc'
|
72
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
73
|
+
# client = Readiness::Zendesk::Client.new(config)
|
74
|
+
# job = Readiness::Zendesk::JobStatuses.find(client, '8b726e606741012ffc2d782bcb7848fe')
|
75
|
+
# pp job.first.status
|
76
|
+
# # => "completed"
|
77
|
+
def self.find(client, jid)
|
78
|
+
response = client.connection.get("job_statuses/#{jid}")
|
79
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: jid }) unless response.status == 200
|
80
|
+
return JobStatuses.new(Oj.load(response.body)['job_status']) if response.status == 200
|
81
|
+
|
82
|
+
Oj.load(response.body)
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Locates a job status within Zendesk. This will exit on error
|
87
|
+
#
|
88
|
+
# @author Jason Colyer
|
89
|
+
# @since 1.0.0
|
90
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
91
|
+
# @param jid [String] The job status ID to find
|
92
|
+
# @return [Hash]
|
93
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#show-job-status Zendesk API > Job Statuses > Show Job Status
|
94
|
+
# @example
|
95
|
+
# require 'support_readiness'
|
96
|
+
# config = Readiness::Zendesk::Configuration.new
|
97
|
+
# config.username = 'alice@example.com'
|
98
|
+
# config.token = 'test123abc'
|
99
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
100
|
+
# client = Readiness::Zendesk::Client.new(config)
|
101
|
+
# job = Readiness::Zendesk::JobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
|
102
|
+
# pp job.first.status
|
103
|
+
# # => "completed"
|
104
|
+
def self.find!(client, jid)
|
105
|
+
response = client.connection.get("job_statuses/#{jid}")
|
106
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Find job status', id: jid }) unless response.status == 200
|
107
|
+
JobStatuses.new(Oj.load(response.body)['job_status'])
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Locates up to 100 job statuses within Zendesk.
|
112
|
+
#
|
113
|
+
# @author Jason Colyer
|
114
|
+
# @since 1.0.0
|
115
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
116
|
+
# @param jids [Array] The job statuses IDs to find
|
117
|
+
# @return [Array]
|
118
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#show-many-job-statuses Zendesk API > Job Statuses > Show Many Job Statuses
|
119
|
+
# @example
|
120
|
+
# require 'support_readiness'
|
121
|
+
# config = Readiness::Zendesk::Configuration.new
|
122
|
+
# config.username = 'alice@example.com'
|
123
|
+
# config.token = 'test123abc'
|
124
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
125
|
+
# client = Readiness::Zendesk::Client.new(config)
|
126
|
+
# jobs = Readiness::Zendesk::JobStatuses.find_many(client, ['8b726e606741012ffc2d782bcb7848fe', 'e7665094164c498781ebe4c8db6d2af5'])
|
127
|
+
# pp jobs.map { |j| j.status }
|
128
|
+
# # => ["completed", "completed"]
|
129
|
+
def self.find_many(client, jids)
|
130
|
+
response = client.connection.get("job_statuses/show_many?ids=#{jids.join(',')}")
|
131
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: jids }) unless response.status == 200
|
132
|
+
Oj.load(response.body)['job_statuses'].map { |o| JobStatuses.new(o) }
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Waits for a job to complete. Be mindful of API limits when setting the wait interval
|
137
|
+
#
|
138
|
+
# @author Jason Colyer
|
139
|
+
# @since 1.0.0
|
140
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
141
|
+
# @param job [Object] An instance of {Readiness::Zendesk::JobStatuses}
|
142
|
+
# @param interval [Integer] The time (in seconds) between checks
|
143
|
+
# @param verbose [Boolean] Whether or not to output messages
|
144
|
+
# @return [Object] An instance of {Readiness::Zendesk::JobStatuses}
|
145
|
+
# @example
|
146
|
+
# require 'support_readiness'
|
147
|
+
# config = Readiness::Zendesk::Configuration.new
|
148
|
+
# config.username = 'alice@example.com'
|
149
|
+
# config.token = 'test123abc'
|
150
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
151
|
+
# client = Readiness::Zendesk::Client.new(config)
|
152
|
+
# job = Readiness::Zendesk::JobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
|
153
|
+
# completed_job = Readiness::Zendesk::JobStatuses.wait_for_completetion(client, job, 10, true)
|
154
|
+
# # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
155
|
+
# # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is queued
|
156
|
+
# # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
157
|
+
# # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is working
|
158
|
+
# # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
159
|
+
# # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is completed
|
160
|
+
# # => Job is finished with status of completed
|
161
|
+
# pp completed_job.status
|
162
|
+
# # => "completed"
|
163
|
+
# @example
|
164
|
+
# require 'support_readiness'
|
165
|
+
# config = Readiness::Zendesk::Configuration.new
|
166
|
+
# config.username = 'alice@example.com'
|
167
|
+
# config.token = 'test123abc'
|
168
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
169
|
+
# client = Readiness::Zendesk::Client.new(config)
|
170
|
+
# job = Readiness::Zendesk::JobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
|
171
|
+
# completed_job = Readiness::Zendesk::JobStatuses.wait_for_completetion(client, job, 5, false)
|
172
|
+
# pp completed_job.status
|
173
|
+
# # => "completed"
|
174
|
+
def self.wait_for_completetion(client, job, interval = 5, verbose = true)
|
175
|
+
loop do
|
176
|
+
puts "Waiting #{interval} seconds before checking #{job.id}" if verbose
|
177
|
+
sleep interval
|
178
|
+
print "Rechecking status of #{job.id}..." if verbose
|
179
|
+
job = JobStatuses.find!(client, job.id)
|
180
|
+
puts "status is #{job.status}" if verbose
|
181
|
+
break if %w[failed completed].include? job.status
|
182
|
+
end
|
183
|
+
puts "Job is finished with status of #{job.status}" if verbose
|
184
|
+
job
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Zendesk
|
6
|
+
module Zendesk
|
7
|
+
##
|
8
|
+
# Defines the class Macros within the module {Readiness::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
class Macros < Readiness::Client
|
13
|
+
attr_accessor :actions, :active, :default, :description, :id, :position, :restriction, :title
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Zendesk::Macros} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.0
|
20
|
+
# @param object [Object] An instance of {Readiness::Zendesk::Macros}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::Zendesk::Macros.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@actions = object['actions']
|
26
|
+
@active = object['active']
|
27
|
+
@default = object['default']
|
28
|
+
@description = object['description']
|
29
|
+
@id = object['id']
|
30
|
+
@position = object['position']
|
31
|
+
@restriction = object['restriction']
|
32
|
+
@title = object['title']
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Lists macros
|
37
|
+
#
|
38
|
+
# @author Jason Colyer
|
39
|
+
# @since 1.0.0
|
40
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
41
|
+
# @return [Array]
|
42
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-macros Zendesk API > Macros > List Macros
|
43
|
+
# @example
|
44
|
+
# require 'support_readiness'
|
45
|
+
# config = Readiness::Zendesk::Configuration.new
|
46
|
+
# config.username = 'alice@example.com'
|
47
|
+
# config.token = 'test123abc'
|
48
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
49
|
+
# client = Readiness::Zendesk::Client.new(config)
|
50
|
+
# macros = Readiness::Zendesk::Macros.list(client)
|
51
|
+
# pp macros.first.id
|
52
|
+
# # => 25
|
53
|
+
def self.list(client)
|
54
|
+
array = []
|
55
|
+
opts = "page[size]=100"
|
56
|
+
loop do
|
57
|
+
response = client.connection.get("macros?#{opts}")
|
58
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
59
|
+
body = Oj.load(response.body)
|
60
|
+
array += body['macros'].map { |t| Macros.new(t) }
|
61
|
+
break unless body['meta']['has_more']
|
62
|
+
|
63
|
+
opts = body['links'] ['next'].split('?').last
|
64
|
+
end
|
65
|
+
array
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Locates a macro within Zendesk. This will not exit on error (except Authentication errors)
|
70
|
+
#
|
71
|
+
# @author Jason Colyer
|
72
|
+
# @since 1.0.0
|
73
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
74
|
+
# @param mid [Integer] The macro ID to find
|
75
|
+
# @return [Hash]
|
76
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#show-macro Zendesk API > Macros > Show Macro
|
77
|
+
# @example
|
78
|
+
# require 'support_readiness'
|
79
|
+
# config = Readiness::Zendesk::Configuration.new
|
80
|
+
# config.username = 'alice@example.com'
|
81
|
+
# config.token = 'test123abc'
|
82
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
83
|
+
# client = Readiness::Zendesk::Client.new(config)
|
84
|
+
# macro = Readiness::Zendesk::Macros.find(client, 25)
|
85
|
+
# pp macro.title
|
86
|
+
# # => "Assign priority tag"
|
87
|
+
def self.find(client, mid)
|
88
|
+
response = client.connection.get("macros/#{mid}")
|
89
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: mid }) unless response.status == 200
|
90
|
+
return Macros.new(Oj.load(response.body)['macro']) if response.status == 200
|
91
|
+
|
92
|
+
Oj.load(response.body)
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Locates a macro within Zendesk. This will exit on error
|
97
|
+
#
|
98
|
+
# @author Jason Colyer
|
99
|
+
# @since 1.0.0
|
100
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
101
|
+
# @param mid [Integer] The macro ID to find
|
102
|
+
# @return [Object] An instance of {Readiness::Zendesk::Macros}
|
103
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#show-macro Zendesk API > Macros > Show Macro
|
104
|
+
# @example
|
105
|
+
# require 'support_readiness'
|
106
|
+
# config = Readiness::Zendesk::Configuration.new
|
107
|
+
# config.username = 'alice@example.com'
|
108
|
+
# config.token = 'test123abc'
|
109
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
110
|
+
# client = Readiness::Zendesk::Client.new(config)
|
111
|
+
# macro = Readiness::Zendesk::Macros.find!(client, 25)
|
112
|
+
# pp macro.title
|
113
|
+
# # => "Assign priority tag"
|
114
|
+
def self.find!(client, mid)
|
115
|
+
response = client.connection.get("macros/#{mid}")
|
116
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Find macro', id: mid }) unless response.status == 200
|
117
|
+
Macros.new(Oj.load(response.body)['macro'])
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Creates a macro. Will exit if unsuccessful
|
122
|
+
#
|
123
|
+
# @author Jason Colyer
|
124
|
+
# @since 1.0.0
|
125
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
126
|
+
# @param macro [Object] An instance of {Readiness::Zendesk::Macros}
|
127
|
+
# @return [Object] An instance of {Readiness::Zendesk::Triggers}
|
128
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#create-macro Zendesk API > Macros > Create Macro
|
129
|
+
# @example
|
130
|
+
# require 'support_readiness'
|
131
|
+
# config = Readiness::Zendesk::Configuration.new
|
132
|
+
# config.username = 'alice@example.com'
|
133
|
+
# config.token = 'test123abc'
|
134
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
135
|
+
# client = Readiness::Zendesk::Client.new(config)
|
136
|
+
# macro = Readiness::Zendesk::Macros.new
|
137
|
+
# macro.title = 'Roger Wilco'
|
138
|
+
# macro.actions = [{ field: 'status', value: 'solved' }]
|
139
|
+
# create = Readiness::Zendesk::Macros.create!(client, macro)
|
140
|
+
# pp create.id
|
141
|
+
# # => 26
|
142
|
+
def self.create!(client, macro)
|
143
|
+
response = client.connection.post 'macros', to_clean_json_with_key(macro, 'macro')
|
144
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create macro', message: Oj.load(response.body)}) unless response.status == 201
|
145
|
+
Macros.new(Oj.load(response.body)['macro'])
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Updates a macro. Will exit if unsuccessful
|
150
|
+
#
|
151
|
+
# @author Jason Colyer
|
152
|
+
# @since 1.0.0
|
153
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
154
|
+
# @param macro [Object] An instance of {Readiness::Zendesk::Macros}
|
155
|
+
# @return [Object] An instance of {Readiness::Zendesk::Triggers}
|
156
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#update-macro Zendesk API > Macros > Update Macro
|
157
|
+
# @example
|
158
|
+
# require 'support_readiness'
|
159
|
+
# config = Readiness::Zendesk::Configuration.new
|
160
|
+
# config.username = 'alice@example.com'
|
161
|
+
# config.token = 'test123abc'
|
162
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
163
|
+
# client = Readiness::Zendesk::Client.new(config)
|
164
|
+
# macro = Readiness::Zendesk::Macros.find!(client, 26)
|
165
|
+
# macro.title = 'Solve ticket'
|
166
|
+
# update = Readiness::Zendesk::Macros.update!(client, macro)
|
167
|
+
# pp update.title
|
168
|
+
# # => "Solve ticket"
|
169
|
+
def self.update!(client, macro)
|
170
|
+
response = client.connection.put "macros/#{macro.id}", to_clean_json_with_key(macro, 'macro')
|
171
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Update macro', id: macro.id, message: Oj.load(response.body)}) unless response.status == 200
|
172
|
+
Macros.new(Oj.load(response.body)['macro'])
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Updates multiple macros via a batch job
|
177
|
+
#
|
178
|
+
# @author Jason Colyer
|
179
|
+
# @since 1.0.0
|
180
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
181
|
+
# @param macros [Array] An array of {Readiness::Zendesk::Macros} instances
|
182
|
+
# @return [array] An array of {Readiness::Zendesk::Macros} instances
|
183
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#update-many-macros Zendesk API > Macros > Update Many Macros
|
184
|
+
# @example
|
185
|
+
# require 'support_readiness'
|
186
|
+
# config = Readiness::Zendesk::Configuration.new
|
187
|
+
# config.username = 'alice@example.com'
|
188
|
+
# config.token = 'test123abc'
|
189
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
190
|
+
# client = Readiness::Zendesk::Client.new(config)
|
191
|
+
# macro1 = Readiness::Zendesk::Macros.find!(client, 25)
|
192
|
+
# macro1.title = 'Solve ticket'
|
193
|
+
# macro2 = Readiness::Zendesk::Macros.find!(client, 25)
|
194
|
+
# macro2.title = 'Solve ticket and add done tag'
|
195
|
+
# macros = [macro1, macro2]
|
196
|
+
# updates = Readiness::Zendesk::Macros.update_many!(client, macros)
|
197
|
+
# pp updates.last.title
|
198
|
+
# # => "Solve ticket and add done tag"
|
199
|
+
def self.update_many!(client, macros)
|
200
|
+
data = { macros: macros.map { |m| to_hash(m).compact } }.to_json
|
201
|
+
response = client.connection.put('macros/update_many', data)
|
202
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Update many macros', message: Oj.load(response.body)}) unless response.status == 200
|
203
|
+
Oj.load(response.body)['macros'].map { |m| Macros.new(m) }
|
204
|
+
end
|
205
|
+
|
206
|
+
##
|
207
|
+
# Deletes a macro. Will exit if unsuccessful
|
208
|
+
#
|
209
|
+
# @author Jason Colyer
|
210
|
+
# @since 1.0.0
|
211
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
212
|
+
# @param macro [Object] An instance of {Readiness::Zendesk::Macros}
|
213
|
+
# @return [Boolean]
|
214
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#delete-macro Zendesk API > Macros > Delete Macro
|
215
|
+
# @example
|
216
|
+
# require 'support_readiness'
|
217
|
+
# config = Readiness::Zendesk::Configuration.new
|
218
|
+
# config.username = 'alice@example.com'
|
219
|
+
# config.token = 'test123abc'
|
220
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
221
|
+
# client = Readiness::Zendesk::Client.new(config)
|
222
|
+
# macro = Readiness::Zendesk::Macros.find!(client, 26)
|
223
|
+
# delete = Readiness::Zendesk::Macros.delete!(client, macro)
|
224
|
+
# pp delete
|
225
|
+
# # => true
|
226
|
+
def self.delete!(client, macro)
|
227
|
+
response = client.connection.delete "macros/#{macro.id}"
|
228
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a macro', id: macro.id, message: Oj.load(response.body)}) unless response.status == 204
|
229
|
+
true
|
230
|
+
end
|
231
|
+
|
232
|
+
##
|
233
|
+
# Deletes multiple macros via a batch job
|
234
|
+
#
|
235
|
+
# @author Jason Colyer
|
236
|
+
# @since 1.0.0
|
237
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
238
|
+
# @param mids [Array] An array of macro IDs
|
239
|
+
# @return [Boolean]
|
240
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#bulk-delete-macros Zendesk API > Macros > Bulk Delete Macros
|
241
|
+
# @example
|
242
|
+
# require 'support_readiness'
|
243
|
+
# config = Readiness::Zendesk::Configuration.new
|
244
|
+
# config.username = 'alice@example.com'
|
245
|
+
# config.token = 'test123abc'
|
246
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
247
|
+
# client = Readiness::Zendesk::Client.new(config)
|
248
|
+
# deletes = Readiness::Zendesk::Macros.delete_many!(client, [25, 26])
|
249
|
+
# pp deletes
|
250
|
+
# # => true
|
251
|
+
def self.delete_many(client, mids)
|
252
|
+
response = client.connection.delete("macros/destroy_many?ids=#{mids.join(',')}")
|
253
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many macros', message: Oj.load(response.body)}) unless response.status == 204
|
254
|
+
true
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|