gitlab_support_readiness 1.0.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/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,515 @@
|
|
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 Organizations within the module {Readiness::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @todo Merge org
|
13
|
+
# @todo Show merge
|
14
|
+
# @todo List merges
|
15
|
+
class Organizations < Readiness::Client
|
16
|
+
attr_accessor :details, :domain_names, :external_id, :group_id, :id, :name, :notes, :organization_fields, :shared_comments, :shared_tickets, :tags
|
17
|
+
|
18
|
+
##
|
19
|
+
# Creates a new {Readiness::Zendesk::Organizations} instance
|
20
|
+
#
|
21
|
+
# @author Jason Colyer
|
22
|
+
# @since 1.0.0
|
23
|
+
# @param object [Object] An instance of {Readiness::Zendesk::Organizations}
|
24
|
+
# @example
|
25
|
+
# require 'support_readiness'
|
26
|
+
# Readiness::Zendesk::Organizations.new
|
27
|
+
def initialize(object = {})
|
28
|
+
@details = object['details']
|
29
|
+
@domain_names = object['domain_names']
|
30
|
+
@external_id = object['external_id']
|
31
|
+
@group_id = object['group_id']
|
32
|
+
@id = object['id']
|
33
|
+
@name = object['name']
|
34
|
+
@notes = object['notes']
|
35
|
+
@organization_fields = object['organization_fields']
|
36
|
+
@shared_comments = object['shared_comments']
|
37
|
+
@shared_tickets = object['shared_tickets']
|
38
|
+
@tags = object['tags']
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Lists the first 100 organizations
|
43
|
+
#
|
44
|
+
# @author Jason Colyer
|
45
|
+
# @since 1.0.0
|
46
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
47
|
+
# @return [Array]
|
48
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations Zendesk API > Organizations > List Organizations
|
49
|
+
# @example
|
50
|
+
# require 'support_readiness'
|
51
|
+
# config = Readiness::Zendesk::Configuration.new
|
52
|
+
# config.username = 'alice@example.com'
|
53
|
+
# config.token = 'test123abc'
|
54
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
55
|
+
# client = Readiness::Zendesk::Client.new(config)
|
56
|
+
# orgs = Readiness::Zendesk::Organizations.list(client)
|
57
|
+
# pp orgs.first.id
|
58
|
+
# # => 4112492
|
59
|
+
def self.list(client)
|
60
|
+
response = client.connection.get("organizations?page[size]=100")
|
61
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
62
|
+
Oj.load(response.body)['organizations'].map { |o| Organizations.new(o) }
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Lists many organizations. Does not stop until it ends or the page limit is hit.
|
67
|
+
# This method can take a long time to run depending on the parameters used.
|
68
|
+
#
|
69
|
+
# @author Jason Colyer
|
70
|
+
# @since 1.0.0
|
71
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
72
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
73
|
+
# @return [Array]
|
74
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations Zendesk API > Organizations > List Organizations
|
75
|
+
# @example
|
76
|
+
# require 'support_readiness'
|
77
|
+
# config = Readiness::Zendesk::Configuration.new
|
78
|
+
# config.username = 'alice@example.com'
|
79
|
+
# config.token = 'test123abc'
|
80
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
81
|
+
# client = Readiness::Zendesk::Client.new(config)
|
82
|
+
# orgs = Readiness::Zendesk::Organizations.list_many(client, 4)
|
83
|
+
# pp orgs.count
|
84
|
+
# # => 400
|
85
|
+
def self.list_many(client, limit = 0, sort = 'id')
|
86
|
+
array = []
|
87
|
+
opts = "page[size]=100"
|
88
|
+
loop do
|
89
|
+
response = client.connection.get("organizations?#{opts}")
|
90
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
91
|
+
body = Oj.load(response.body)
|
92
|
+
array += body['organizations'].map { |o| Organizations.new(o) }
|
93
|
+
break if limit != 0 && array.count >= (limit * 100)
|
94
|
+
break unless body['meta']['has_more']
|
95
|
+
|
96
|
+
opts = body['links'] ['next'].split('?').last
|
97
|
+
end
|
98
|
+
array
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Show information on the approximate count of organizations.
|
103
|
+
#
|
104
|
+
# @author Jason Colyer
|
105
|
+
# @since 1.0.0
|
106
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
107
|
+
# @return [Hash]
|
108
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#count-organizations Zendesk API > Organizations > Count Organizations
|
109
|
+
# @example
|
110
|
+
# require 'support_readiness'
|
111
|
+
# config = Readiness::Zendesk::Configuration.new
|
112
|
+
# config.username = 'alice@example.com'
|
113
|
+
# config.token = 'test123abc'
|
114
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
115
|
+
# client = Readiness::Zendesk::Client.new(config)
|
116
|
+
# count = Readiness::Zendesk::Organizations.count(client)
|
117
|
+
# pp count.value
|
118
|
+
# # => 54590
|
119
|
+
def self.count(client)
|
120
|
+
response = client.connection.get('organizations/count')
|
121
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
122
|
+
Oj.load(response.body)['count']
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Locates an organization within Zendesk. This will not exit on error (except Authentication errors)
|
127
|
+
#
|
128
|
+
# @author Jason Colyer
|
129
|
+
# @since 1.0.0
|
130
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
131
|
+
# @param oid [Integer] The organization ID to find
|
132
|
+
# @return [Hash]
|
133
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization Zendesk API > ORganizations > Show Organization
|
134
|
+
# @example
|
135
|
+
# require 'support_readiness'
|
136
|
+
# config = Readiness::Zendesk::Configuration.new
|
137
|
+
# config.username = 'alice@example.com'
|
138
|
+
# config.token = 'test123abc'
|
139
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
140
|
+
# client = Readiness::Zendesk::Client.new(config)
|
141
|
+
# org = Readiness::Zendesk::Organizations.find(client, 4112492)
|
142
|
+
# pp org.name
|
143
|
+
# # => "Groablet Enterprises"
|
144
|
+
def self.find(client, oid)
|
145
|
+
response = client.connection.get("organizations/#{oid}")
|
146
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: oid }) unless response.status == 200
|
147
|
+
return Organizations.new(Oj.load(response.body)['organization']) if response.status == 200
|
148
|
+
|
149
|
+
Oj.load(response.body)
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# Locates an organization within Zendesk. This will exit on error
|
154
|
+
#
|
155
|
+
# @author Jason Colyer
|
156
|
+
# @since 1.0.0
|
157
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
158
|
+
# @param oid [Integer] The organization ID to find
|
159
|
+
# @return [Object] An instance of {Readiness::Zendesk::Organizations}
|
160
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization Zendesk API > Organizations > Show Organization
|
161
|
+
# @example
|
162
|
+
# require 'support_readiness'
|
163
|
+
# config = Readiness::Zendesk::Configuration.new
|
164
|
+
# config.username = 'alice@example.com'
|
165
|
+
# config.token = 'test123abc'
|
166
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
167
|
+
# client = Readiness::Zendesk::Client.new(config)
|
168
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 4112492)
|
169
|
+
# pp org.name
|
170
|
+
# # => "Groablet Enterprises"
|
171
|
+
def self.find!(client, oid)
|
172
|
+
response = client.connection.get("organizations/#{oid}")
|
173
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Find organization', id: oid }) unless response.status == 200
|
174
|
+
Organizations.new(Oj.load(response.body)['organization'])
|
175
|
+
end
|
176
|
+
|
177
|
+
##
|
178
|
+
# Locates up to 100 organizations within Zendesk.
|
179
|
+
#
|
180
|
+
# @author Jason Colyer
|
181
|
+
# @since 1.0.0
|
182
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
183
|
+
# @param oids [Array] The organization IDs to find
|
184
|
+
# @return [Array]
|
185
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations Zendesk API > Organizations > Show Many Organizations
|
186
|
+
# @example
|
187
|
+
# require 'support_readiness'
|
188
|
+
# config = Readiness::Zendesk::Configuration.new
|
189
|
+
# config.username = 'alice@example.com'
|
190
|
+
# config.token = 'test123abc'
|
191
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
192
|
+
# client = Readiness::Zendesk::Client.new(config)
|
193
|
+
# orgs = Readiness::Zendesk::Organizations.find_many(client, [35436, 20057623])
|
194
|
+
# pp orgs.map { |o| o.name }
|
195
|
+
# # => ["Important Customers", "Imperial College"]
|
196
|
+
def self.find_many(client, oids)
|
197
|
+
response = client.connection.get("organizations/show_many?ids=#{oids.join(',')}")
|
198
|
+
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: oids }) unless response.status == 200
|
199
|
+
Oj.load(response.body)['organizations'].map { |o| Organizations.new(o) }
|
200
|
+
end
|
201
|
+
|
202
|
+
##
|
203
|
+
# Creates an organization. Will exit if unsuccessful
|
204
|
+
#
|
205
|
+
# @author Jason Colyer
|
206
|
+
# @since 1.0.0
|
207
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
208
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
209
|
+
# @return [Object] An instance of {Readiness::Zendesk::Organizations}
|
210
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization Zendesk API > Organizations > Create Organization
|
211
|
+
# @example
|
212
|
+
# require 'support_readiness'
|
213
|
+
# config = Readiness::Zendesk::Configuration.new
|
214
|
+
# config.username = 'alice@example.com'
|
215
|
+
# config.token = 'test123abc'
|
216
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
217
|
+
# client = Readiness::Zendesk::Client.new(config)
|
218
|
+
# org = Readiness::Zendesk::Organizations.new
|
219
|
+
# org.name = 'My Organization'
|
220
|
+
# create = Readiness::Zendesk::Organizations.create!(client, org)
|
221
|
+
# pp create.id
|
222
|
+
# # => 23409462
|
223
|
+
def self.create!(client, organization)
|
224
|
+
response = client.connection.post 'organizations', to_clean_json_with_key(organization, 'organization')
|
225
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create organization', message: Oj.load(response.body)}) unless response.status == 201
|
226
|
+
Organizations.new(Oj.load(response.body)['organization'])
|
227
|
+
end
|
228
|
+
|
229
|
+
##
|
230
|
+
# Creates or updates an organization. Will exit if unsuccessful
|
231
|
+
#
|
232
|
+
# @author Jason Colyer
|
233
|
+
# @since 1.0.0
|
234
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
235
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
236
|
+
# @return [Object] An instance of {Readiness::Zendesk::Organizations}
|
237
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization Zendesk API > Organizations > Create Or Update Organization
|
238
|
+
# @example
|
239
|
+
# require 'support_readiness'
|
240
|
+
# config = Readiness::Zendesk::Configuration.new
|
241
|
+
# config.username = 'alice@example.com'
|
242
|
+
# config.token = 'test123abc'
|
243
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
244
|
+
# client = Readiness::Zendesk::Client.new(config)
|
245
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 123)
|
246
|
+
# org.name = 'My Organization'
|
247
|
+
# create = Readiness::Zendesk::Organizations.create_or_update!(client, org)
|
248
|
+
# pp create.name
|
249
|
+
# # => 'My Organization'
|
250
|
+
# @example
|
251
|
+
# require 'support_readiness'
|
252
|
+
# config = Readiness::Zendesk::Configuration.new
|
253
|
+
# config.username = 'alice@example.com'
|
254
|
+
# config.token = 'test123abc'
|
255
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
256
|
+
# client = Readiness::Zendesk::Client.new(config)
|
257
|
+
# org = Readiness::Zendesk::Organizations.new
|
258
|
+
# org.name = 'My Organization'
|
259
|
+
# create = Readiness::Zendesk::Organizations.create_or_update!(client, org)
|
260
|
+
# pp create.id
|
261
|
+
# # => 23409462
|
262
|
+
def self.create_or_update!(client, organization)
|
263
|
+
response = client.connection.post 'organizations/create_or_update', to_clean_json_with_key(organization, 'organization')
|
264
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create or update organization', id: organization.name, message: Oj.load(response.body)}) unless [200, 201].include?(response.status)
|
265
|
+
Organizations.new(Oj.load(response.body)['organization'])
|
266
|
+
end
|
267
|
+
|
268
|
+
##
|
269
|
+
# Updates an organization. Will exit if unsuccessful
|
270
|
+
#
|
271
|
+
# @author Jason Colyer
|
272
|
+
# @since 1.0.0
|
273
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
274
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
275
|
+
# @return [Object] An instance of {Readiness::Zendesk::Organizations}
|
276
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization Zendesk API > Organizations > Update Organization
|
277
|
+
# @example
|
278
|
+
# require 'support_readiness'
|
279
|
+
# config = Readiness::Zendesk::Configuration.new
|
280
|
+
# config.username = 'alice@example.com'
|
281
|
+
# config.token = 'test123abc'
|
282
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
283
|
+
# client = Readiness::Zendesk::Client.new(config)
|
284
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 4112492)
|
285
|
+
# org.notes = 'Something interesting'
|
286
|
+
# update = Readiness::Zendesk::Organizations.update!(client, org)
|
287
|
+
# pp update.notes
|
288
|
+
# # => "Something interesting"
|
289
|
+
def self.update!(client, organization)
|
290
|
+
response = client.connection.put "organizations/#{organization.id}", to_clean_json_with_key(organization, 'organization')
|
291
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Update organization', id: organization.id, message: Oj.load(response.body)}) unless response.status == 200
|
292
|
+
Organizations.new(Oj.load(response.body)['organization'])
|
293
|
+
end
|
294
|
+
|
295
|
+
##
|
296
|
+
# Deletes an organization. Will exit if unsuccessful
|
297
|
+
#
|
298
|
+
# @author Jason Colyer
|
299
|
+
# @since 1.0.0
|
300
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
301
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
302
|
+
# @return [Boolean]
|
303
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#delete-organization Zendesk API > Organizations > Delete Organization
|
304
|
+
# @example
|
305
|
+
# require 'support_readiness'
|
306
|
+
# config = Readiness::Zendesk::Configuration.new
|
307
|
+
# config.username = 'alice@example.com'
|
308
|
+
# config.token = 'test123abc'
|
309
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
310
|
+
# client = Readiness::Zendesk::Client.new(config)
|
311
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 16)
|
312
|
+
# delete = Readiness::Zendesk::Organizations.delete!(client, org)
|
313
|
+
# pp delete
|
314
|
+
# # => true
|
315
|
+
def self.delete!(client, organization)
|
316
|
+
response = client.connection.delete "organizations/#{organization.id}"
|
317
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete an organization', id: organization.id, message: Oj.load(response.body)}) unless response.status == 204
|
318
|
+
true
|
319
|
+
end
|
320
|
+
|
321
|
+
##
|
322
|
+
# Lists tickets for an organization.
|
323
|
+
#
|
324
|
+
# @author Jason Colyer
|
325
|
+
# @since 1.0.0
|
326
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
327
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
328
|
+
# @return [Array]
|
329
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#list-tickets Zendesk API > Tickets > List Tickets
|
330
|
+
# @example
|
331
|
+
# require 'support_readiness'
|
332
|
+
# config = Readiness::Zendesk::Configuration.new
|
333
|
+
# config.username = 'alice@example.com'
|
334
|
+
# config.token = 'test123abc'
|
335
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
336
|
+
# client = Readiness::Zendesk::Client.new(config)
|
337
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 16)
|
338
|
+
# tickets = Readiness::Zendesk::Organizations.tickets(client, org)
|
339
|
+
# pp tickets.first.status
|
340
|
+
# # => "pending"
|
341
|
+
def self.tickets(client, organization)
|
342
|
+
array = []
|
343
|
+
opts = "page[size]=100"
|
344
|
+
loop do
|
345
|
+
response = client.connection.get("organizations/#{organization.id}/tickets?#{opts}")
|
346
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
347
|
+
body = Oj.load(response.body)
|
348
|
+
array += body['tickets'].map { |t| Tickets.new(t) }
|
349
|
+
break unless body['meta']['has_more']
|
350
|
+
|
351
|
+
opts = body['links'] ['next'].split('?').last
|
352
|
+
end
|
353
|
+
array
|
354
|
+
end
|
355
|
+
|
356
|
+
##
|
357
|
+
# Lists users for an organization.
|
358
|
+
#
|
359
|
+
# @author Jason Colyer
|
360
|
+
# @since 1.0.0
|
361
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
362
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
363
|
+
# @return [Array]
|
364
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/users/users/#list-users Zendesk API > USers > List Users
|
365
|
+
# @example
|
366
|
+
# require 'support_readiness'
|
367
|
+
# config = Readiness::Zendesk::Configuration.new
|
368
|
+
# config.username = 'alice@example.com'
|
369
|
+
# config.token = 'test123abc'
|
370
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
371
|
+
# client = Readiness::Zendesk::Client.new(config)
|
372
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 16)
|
373
|
+
# users = Readiness::Zendesk::Organizations.users(client, org)
|
374
|
+
# pp users.count
|
375
|
+
# # => 28
|
376
|
+
def self.users(client, organization)
|
377
|
+
array = []
|
378
|
+
opts = "page[size]=100"
|
379
|
+
loop do
|
380
|
+
response = client.connection.get("organizations/#{organization.id}/users?#{opts}")
|
381
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
382
|
+
body = Oj.load(response.body)
|
383
|
+
array += body['users'].map { |u| Users.new(u) }
|
384
|
+
break unless body['meta']['has_more']
|
385
|
+
|
386
|
+
opts = body['links'] ['next'].split('?').last
|
387
|
+
end
|
388
|
+
array
|
389
|
+
end
|
390
|
+
|
391
|
+
##
|
392
|
+
# Creates multiple organizations via a batch job
|
393
|
+
#
|
394
|
+
# @author Jason Colyer
|
395
|
+
# @since 1.0.0
|
396
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
397
|
+
# @param organizations [Array] An array of {Readiness::Zendesk::Organizations} instances
|
398
|
+
# @return [object] A {Readiness::Zendesk::JobStatuses} instance
|
399
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-many-organizations Zendesk API > ORganizations > Create Many Organizations
|
400
|
+
# @example
|
401
|
+
# require 'support_readiness'
|
402
|
+
# config = Readiness::Zendesk::Configuration.new
|
403
|
+
# config.username = 'alice@example.com'
|
404
|
+
# config.token = 'test123abc'
|
405
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
406
|
+
# client = Readiness::Zendesk::Client.new(config)
|
407
|
+
# org1 = Readiness::Zendesk::Organizations.new
|
408
|
+
# org1.name = 'Org 1'
|
409
|
+
# org2 = Readiness::Zendesk::Organizations.new
|
410
|
+
# org2.name = 'Org 2'
|
411
|
+
# orgs = [org1, org2]
|
412
|
+
# creates = Readiness::Zendesk::Organizations.create_many!(client, orgs)
|
413
|
+
# pp creates.id
|
414
|
+
# # => "8b726e606741012ffc2d782bcb7848fe"
|
415
|
+
def self.create_many!(client, organizations)
|
416
|
+
data = { organizations: organizations.map { |o| to_hash(o).compact } }.to_json
|
417
|
+
response = client.connection.post('organizations/create_many', data)
|
418
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create many organizations', message: Oj.load(response.body)}) unless response.status == 200
|
419
|
+
JobStatuses.new(Oj.load(response.body)['job_status'])
|
420
|
+
end
|
421
|
+
|
422
|
+
##
|
423
|
+
# Updates multiple organizations via a batch job
|
424
|
+
#
|
425
|
+
# @author Jason Colyer
|
426
|
+
# @since 1.0.0
|
427
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
428
|
+
# @param organizations [Array] An array of {Readiness::Zendesk::Organizations} instances
|
429
|
+
# @return [object] A {Readiness::Zendesk::JobStatuses} instance
|
430
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-many-organizations Zendesk API > ORganizations > Update Many Organizations
|
431
|
+
# @example
|
432
|
+
# require 'support_readiness'
|
433
|
+
# config = Readiness::Zendesk::Configuration.new
|
434
|
+
# config.username = 'alice@example.com'
|
435
|
+
# config.token = 'test123abc'
|
436
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
437
|
+
# client = Readiness::Zendesk::Client.new(config)
|
438
|
+
# org1 = Readiness::Zendesk::Organizations.find!(client, 123)
|
439
|
+
# org1.notes = 'Escalated customer, please use due diligence'
|
440
|
+
# org2 = Readiness::Zendesk::Organizations.find!(client, 456)
|
441
|
+
# org2.notes = 'Escalated customer, please use due diligence'
|
442
|
+
# orgs = [org1, org2]
|
443
|
+
# updates = Readiness::Zendesk::Organizations.update_many!(client, orgs)
|
444
|
+
# pp updates.id
|
445
|
+
# # => "8b726e606741012ffc2d782bcb7848fe"
|
446
|
+
def self.update_many!(client, organizations)
|
447
|
+
data = { organizations: organizations.map { |o| to_hash(o).compact } }.to_json
|
448
|
+
response = client.connection.put('organizations/update_many', data)
|
449
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Update many organizations', message: Oj.load(response.body)}) unless response.status == 200
|
450
|
+
JobStatuses.new(Oj.load(response.body)['job_status'])
|
451
|
+
end
|
452
|
+
|
453
|
+
##
|
454
|
+
# Deletes multiple organizations via a batch job
|
455
|
+
#
|
456
|
+
# @author Jason Colyer
|
457
|
+
# @since 1.0.0
|
458
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
459
|
+
# @param oids [Array] An array of organization IDs to delete
|
460
|
+
# @return [object] A {Readiness::Zendesk::JobStatuses} instance
|
461
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#bulk-delete-organizations Zendesk API > ORganizations > Bulk Delete Organizations
|
462
|
+
# @example
|
463
|
+
# require 'support_readiness'
|
464
|
+
# config = Readiness::Zendesk::Configuration.new
|
465
|
+
# config.username = 'alice@example.com'
|
466
|
+
# config.token = 'test123abc'
|
467
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
468
|
+
# client = Readiness::Zendesk::Client.new(config)
|
469
|
+
# deletes = Readiness::Zendesk::Organizations.delete_many!(client, [123, 456])
|
470
|
+
# pp deletes.id
|
471
|
+
# # => "8b726e606741012ffc2d782bcb7848fe"
|
472
|
+
def self.delete_many!(client, oids)
|
473
|
+
response = client.connection.delete "organizations/destroy_many?ids=#{oids.join(',')}"
|
474
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many organizations', message: Oj.load(response.body)}) unless response.status == 200
|
475
|
+
JobStatuses.new(Oj.load(response.body)['job_status'])
|
476
|
+
end
|
477
|
+
|
478
|
+
##
|
479
|
+
# Lists members of an organization
|
480
|
+
#
|
481
|
+
# @author Jason Colyer
|
482
|
+
# @since 1.0.0
|
483
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
484
|
+
# @param organization [Object] An instance of {Readiness::Zendesk::Organizations}
|
485
|
+
# @return [Array]
|
486
|
+
# @see https://developer.zendesk.com/api-reference/ticketing/organizations/organization_memberships/#list-memberships Zendesk API > Organization Memberships > List Memberships
|
487
|
+
# @example
|
488
|
+
# require 'support_readiness'
|
489
|
+
# config = Readiness::Zendesk::Configuration.new
|
490
|
+
# config.username = 'alice@example.com'
|
491
|
+
# config.token = 'test123abc'
|
492
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
493
|
+
# client = Readiness::Zendesk::Client.new(config)
|
494
|
+
# org = Readiness::Zendesk::Organizations.find!(client, 123)
|
495
|
+
# members = Readiness::Zendesk::Organizations.memberships(client, org)
|
496
|
+
# pp members.first.user_id
|
497
|
+
# # => 29
|
498
|
+
def self.memberships(client, organization)
|
499
|
+
array = []
|
500
|
+
opts = "page[size]=100"
|
501
|
+
loop do
|
502
|
+
response = client.connection.get("organizations/#{organization.id}/organization_memberships?#{opts}")
|
503
|
+
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
|
504
|
+
body = Oj.load(response.body)
|
505
|
+
array += body['organization_memberships'].map { |o| OrganizationMemberships.new(o) }
|
506
|
+
break if limit != 0 && array.count >= (limit * 100)
|
507
|
+
break unless body['meta']['has_more']
|
508
|
+
|
509
|
+
opts = body['links'] ['next'].split('?').last
|
510
|
+
end
|
511
|
+
array
|
512
|
+
end
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|