gitlab-customer-support-operations_zendesk 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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_zendesk/packages.rb +89 -0
  3. data/lib/support_ops_zendesk/zendesk/app_installations.rb +62 -0
  4. data/lib/support_ops_zendesk/zendesk/app_job_statuses.rb +157 -0
  5. data/lib/support_ops_zendesk/zendesk/apps.rb +476 -0
  6. data/lib/support_ops_zendesk/zendesk/articles.rb +362 -0
  7. data/lib/support_ops_zendesk/zendesk/audit_logs.rb +166 -0
  8. data/lib/support_ops_zendesk/zendesk/automations.rb +390 -0
  9. data/lib/support_ops_zendesk/zendesk/base.rb +472 -0
  10. data/lib/support_ops_zendesk/zendesk/brands.rb +172 -0
  11. data/lib/support_ops_zendesk/zendesk/client.rb +91 -0
  12. data/lib/support_ops_zendesk/zendesk/comments.rb +37 -0
  13. data/lib/support_ops_zendesk/zendesk/configuration.rb +138 -0
  14. data/lib/support_ops_zendesk/zendesk/custom_roles.rb +224 -0
  15. data/lib/support_ops_zendesk/zendesk/dynamic_content.rb +297 -0
  16. data/lib/support_ops_zendesk/zendesk/dynamic_content_variants.rb +309 -0
  17. data/lib/support_ops_zendesk/zendesk/group_memberships.rb +337 -0
  18. data/lib/support_ops_zendesk/zendesk/groups.rb +385 -0
  19. data/lib/support_ops_zendesk/zendesk/help_center_categories.rb +332 -0
  20. data/lib/support_ops_zendesk/zendesk/help_center_content_tags.rb +237 -0
  21. data/lib/support_ops_zendesk/zendesk/help_center_management_permission_groups.rb +271 -0
  22. data/lib/support_ops_zendesk/zendesk/help_center_sections.rb +378 -0
  23. data/lib/support_ops_zendesk/zendesk/help_center_topics.rb +274 -0
  24. data/lib/support_ops_zendesk/zendesk/help_center_user_segments.rb +279 -0
  25. data/lib/support_ops_zendesk/zendesk/job_statuses.rb +231 -0
  26. data/lib/support_ops_zendesk/zendesk/locales.rb +326 -0
  27. data/lib/support_ops_zendesk/zendesk/macros.rb +407 -0
  28. data/lib/support_ops_zendesk/zendesk/oauth_clients.rb +186 -0
  29. data/lib/support_ops_zendesk/zendesk/oauth_tokens.rb +114 -0
  30. data/lib/support_ops_zendesk/zendesk/organization_fields.rb +282 -0
  31. data/lib/support_ops_zendesk/zendesk/organization_memberships.rb +336 -0
  32. data/lib/support_ops_zendesk/zendesk/organizations.rb +568 -0
  33. data/lib/support_ops_zendesk/zendesk/requester_roles.rb +58 -0
  34. data/lib/support_ops_zendesk/zendesk/satisfaction_reasons.rb +161 -0
  35. data/lib/support_ops_zendesk/zendesk/schedule_holidays.rb +27 -0
  36. data/lib/support_ops_zendesk/zendesk/schedules.rb +192 -0
  37. data/lib/support_ops_zendesk/zendesk/search.rb +185 -0
  38. data/lib/support_ops_zendesk/zendesk/sla_policies.rb +302 -0
  39. data/lib/support_ops_zendesk/zendesk/targets.rb +96 -0
  40. data/lib/support_ops_zendesk/zendesk/theme_job_statuses.rb +154 -0
  41. data/lib/support_ops_zendesk/zendesk/themes.rb +328 -0
  42. data/lib/support_ops_zendesk/zendesk/ticket_field_options.rb +154 -0
  43. data/lib/support_ops_zendesk/zendesk/ticket_fields.rb +357 -0
  44. data/lib/support_ops_zendesk/zendesk/ticket_forms.rb +370 -0
  45. data/lib/support_ops_zendesk/zendesk/ticket_user_types.rb +67 -0
  46. data/lib/support_ops_zendesk/zendesk/tickets.rb +837 -0
  47. data/lib/support_ops_zendesk/zendesk/translations.rb +310 -0
  48. data/lib/support_ops_zendesk/zendesk/trigger_categories.rb +275 -0
  49. data/lib/support_ops_zendesk/zendesk/triggers.rb +427 -0
  50. data/lib/support_ops_zendesk/zendesk/user_field_options.rb +153 -0
  51. data/lib/support_ops_zendesk/zendesk/user_fields.rb +312 -0
  52. data/lib/support_ops_zendesk/zendesk/users.rb +889 -0
  53. data/lib/support_ops_zendesk/zendesk/via_types.rb +137 -0
  54. data/lib/support_ops_zendesk/zendesk/views.rb +636 -0
  55. data/lib/support_ops_zendesk/zendesk/webhooks.rb +206 -0
  56. data/lib/support_ops_zendesk/zendesk.rb +66 -0
  57. data/lib/support_ops_zendesk.rb +29 -0
  58. metadata +274 -0
@@ -0,0 +1,231 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class JobStatuses within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] id Automatically assigned when the job is queued
13
+ # @attr [String] job_type The type of the job
14
+ # @attr [String] message Message from the job worker, if any
15
+ # @attr [Integer] progress Number of tasks that have already been completed
16
+ # @attr [Hash] results esult data from processed tasks
17
+ # @attr [String] status The current status. One of the following: "queued", "working", "failed", "completed"
18
+ # @attr [Integer] total The total number of tasks this job is batching through
19
+ class JobStatuses < SupportOps::Zendesk::Base
20
+ # @!parse
21
+ # # Waits for a job to complete. Be mindful of API limits when setting the wait interval
22
+ # #
23
+ # # @author Jason Colyer
24
+ # # @since 1.0.0
25
+ # # @overload wait_for_completetion(key: value)
26
+ # # @param interval [Integer optional] The time to wait between checks. Defaults to 5
27
+ # # @param verbose [Boolean optional] If you want info lines output. Defaults to false
28
+ # # @return [Object] Instance of {SupportOps::Zendesk::JobStatuses}
29
+ # # @note This is inherited from {SupportOps::Zendesk::Base#wait_for_completetion}
30
+ # # @example
31
+ # # require 'support_ops_zendesk'
32
+ # #
33
+ # # SupportOps::Zendesk::Configuration.configure do |config|
34
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
35
+ # # config.username = 'jason@example.com'
36
+ # # config.token = 'abc123'
37
+ # # end
38
+ # #
39
+ # # job = SupportOps::Zendesk::JobStatuses.get!('8b726e606741012ffc2d782bcb7848fe')
40
+ # # job.wait_for_completetion(interval: 10, verbose: true)
41
+ # # # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
42
+ # # # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is queued
43
+ # # # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
44
+ # # # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is working
45
+ # # # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
46
+ # # # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is completed
47
+ # # # => Job is finished with status of completed
48
+ # # pp job.status
49
+ # # # => "completed"
50
+ # # @example
51
+ # # require 'support_ops_zendesk'
52
+ # #
53
+ # # SupportOps::Zendesk::Configuration.configure do |config|
54
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
55
+ # # config.username = 'jason@example.com'
56
+ # # config.token = 'abc123'
57
+ # # end
58
+ # #
59
+ # # job = SupportOps::Zendesk::JobStatuses.get!('8b726e606741012ffc2d782bcb7848fe')
60
+ # # job.wait_for_completetion(interval: 5, verbose: false)
61
+ # # pp job.status
62
+ # # # => "completed"
63
+ # def wait_for_completetion; end
64
+ define_attributes :id, :job_type, :message, :progress, :results, :status,
65
+ :total
66
+ readonly_attributes :id
67
+
68
+ ##
69
+ # Lists job statuses in the Zendesk system
70
+ #
71
+ # @author Jason Colyer
72
+ # @since 1.0.0
73
+ # @overload list(key: value)
74
+ # @param limit [Integer optional] The limit to the number of job
75
+ # statuses memberships returned. Default to 0 (i.e. no limit)
76
+ # @return [Array]
77
+ # @see
78
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#list-job-statuses
79
+ # Zendesk API > Job Statuses > List Job Statuses
80
+ # @see SupportOps::Zendesk::Configuration Setting up a client
81
+ # @example
82
+ # require 'support_ops_zendesk'
83
+ #
84
+ # SupportOps::Zendesk::Configuration.configure do |config|
85
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
86
+ # config.username = 'jason@example.com'
87
+ # config.token = 'abc123'
88
+ # end
89
+ #
90
+ # job_statuses = SupportOps::Zendesk::JobStatuses.list(limit: 25)
91
+ # pp job_statuses.count
92
+ # # => 25
93
+ # pp job_statuses.last.status
94
+ # # => "completed"
95
+ def self.list(**args)
96
+ args[:limit] = 0 unless args[:limit]
97
+ items = []
98
+ opts = 'page[size]=100'
99
+ loop do
100
+ response = client.connection.get("job_statuses?#{opts}")
101
+ body = Oj.load(response.body)
102
+ items += body['job_statuses'].map { |j| JobStatuses.new(j) }
103
+ break if args[:limit].to_i.positive? && items.count >= args[:limit].to_i
104
+ break unless body['meta']['has_more']
105
+
106
+ opts = body['links']['next'].split('?').last
107
+ end
108
+ return items if args[:limit].to_i.zero?
109
+
110
+ items.first(args[:limit].to_i)
111
+ end
112
+
113
+
114
+ ##
115
+ # Locates a specific job status in the Zendesk system
116
+ #
117
+ # @author Jason Colyer
118
+ # @since 1.0.0
119
+ # @see
120
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#show-job-status
121
+ # Zendesk API > Job Statuses > Show Job Status
122
+ # @see SupportOps::Zendesk::Configuration Setting up a client
123
+ # @example
124
+ # require 'support_ops_zendesk'
125
+ #
126
+ # SupportOps::Zendesk::Configuration.configure do |config|
127
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
128
+ # config.username = 'jason@example.com'
129
+ # config.token = 'abc123'
130
+ # end
131
+ #
132
+ # job_status = SupportOps::Zendesk::JobStatuses.get('82de0b044094f0c67893ac9fe64f1a99')
133
+ # pp job_status.status
134
+ # # => "pending"
135
+ def self.get(object)
136
+ if object.is_a? JobStatuses
137
+ JobStatuses.new(id: id).find
138
+ else
139
+ JobStatuses.new(id: object).find
140
+ end
141
+ end
142
+
143
+ ##
144
+ # Locates a specific job status in the Zendesk system
145
+ #
146
+ # @author Jason Colyer
147
+ # @since 1.0.0
148
+ # @see
149
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#show-job-status
150
+ # Zendesk API > Job Statuses > Show Job Status
151
+ # @see SupportOps::Zendesk::Configuration Setting up a client
152
+ # @example
153
+ # require 'support_ops_zendesk'
154
+ #
155
+ # SupportOps::Zendesk::Configuration.configure do |config|
156
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
157
+ # config.username = 'jason@example.com'
158
+ # config.token = 'abc123'
159
+ # end
160
+ #
161
+ # job_status = SupportOps::Zendesk::JobStatuses.get!('82de0b044094f0c67893ac9fe64f1a99')
162
+ # pp job_status.status
163
+ # # => "pending"
164
+ def self.get!(object)
165
+ if object.is_a? JobStatuses
166
+ JobStatuses.new(id: id).find!
167
+ else
168
+ JobStatuses.new(id: object).find!
169
+ end
170
+ end
171
+
172
+ ##
173
+ # Locates up to 100 job statuses within Zendesk.
174
+ #
175
+ # @author Jason Colyer
176
+ # @since 1.0.0
177
+ # @param job_status_ids [Array] The job status IDs to find
178
+ # @return [Array]
179
+ # @see
180
+ # https://developer.zendesk.com/api-reference/ticketing/ticket-management/job_statuses/#show-many-job-statuses
181
+ # Zendesk API > Job Statuses > Show Many Job Statuses
182
+ # @example
183
+ # require 'support_ops_zendesk'
184
+ #
185
+ # SupportOps::Zendesk::Configuration.configure do |config|
186
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
187
+ # config.username = 'jason@example.com'
188
+ # config.token = 'abc123'
189
+ # end
190
+ #
191
+ # jobs = SupportOps::Zendesk::JobStatuses.get_many(['8b726e606741012ffc2d782bcb7848fe', 'e7665094164c498781ebe4c8db6d2af5'])
192
+ # pp jobs.map { |j| j.status }
193
+ # # => ["completed", "completed"]
194
+ def self.get_many(job_status_ids)
195
+ raise 'The parameter must be an Array' unless job_status_ids.is_a? Array
196
+ raise 'You can only get a maximum of 100 job statuses at a time' if job_status_ids.count > 100
197
+
198
+ response = client.connection.get("job_statuses/show_many?ids=#{job_status_ids.join(',')}")
199
+ Oj.load(response.body)['job_statuses'].map { |j| JobStatuses.new(j) }
200
+ end
201
+
202
+ private
203
+
204
+ ##
205
+ # @private
206
+ def get_record
207
+ response = self.client.connection.get("job_statuses/#{self.id}")
208
+ return nil if response.status != 200
209
+
210
+ Oj.load(response.body)['job_status']
211
+ end
212
+
213
+ ##
214
+ # @private
215
+ def wait_for_completetion_record(**args)
216
+ job_to_check = JobStatuses.get!(self.id)
217
+ verbose = (args[:verbose] ? true : false)
218
+ interval = (args[:interval].to_i.zero? ? 5 : args[:interval].to_i)
219
+ loop do
220
+ puts "Waiting #{interval} seconds before checking #{job_to_check.id}" if verbose
221
+ sleep interval
222
+ job_to_check = JobStatuses.get!(job_to_check.id)
223
+ puts "status is #{job_to_check.status}" if verbose
224
+ break if %w[failed completed].include? job_to_check.status
225
+ end
226
+ puts "Job is finished with status of #{job_to_check.status}" if verbose
227
+ job_to_check
228
+ end
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,326 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Locales within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at The ISO 8601 formatted date-time the locale was created
13
+ # @attr [Integer] id The unique ID of the locale
14
+ # @attr [String] locale The name of the locale
15
+ # @attr [String] name The name of the language
16
+ # @attr [String] updated_at The ISO 8601 formatted date-time when the locale was last updated
17
+ # @todo get
18
+ # @todo get!
19
+ # @todo Detect Best Language for User => https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#detect-best-language-for-user
20
+ class Locales < SupportOps::Zendesk::Base
21
+ define_attributes :created_at, :id, :locale, :name, :updated_at
22
+ readonly_attributes :created_at, :id, :locale, :name, :updated_at
23
+
24
+ ##
25
+ # Lists all locales in the Zendesk system
26
+ #
27
+ # @author Jason Colyer
28
+ # @since 1.0.0
29
+ # @return [Array]
30
+ # @see
31
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#list-locales
32
+ # Zendesk API > Locales > List locales
33
+ # @see SupportOps::Zendesk::Configuration Setting up a client
34
+ # @example
35
+ # require 'support_ops_zendesk'
36
+ #
37
+ # SupportOps::Zendesk::Configuration.configure do |config|
38
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
39
+ # config.username = 'jason@example.com'
40
+ # config.token = 'abc123'
41
+ # end
42
+ #
43
+ # locales = SupportOps::Zendesk::Locales.list
44
+ # pp locales.first.name
45
+ # # => "English"
46
+ def self.list
47
+ response = client.connection.get('locales')
48
+ Oj.load(response.body)['locales'].map { |l| Locales.new(l) }
49
+ end
50
+
51
+ ##
52
+ # Lists all enabled locales in the Zendesk Help Center system
53
+ #
54
+ # @author Jason Colyer
55
+ # @since 1.0.0
56
+ # @return [Array]
57
+ # @see
58
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-enabled-locales-and-default-locale
59
+ # Zendesk API > Translations > List Enabled Locales and Default Locale
60
+ # @see SupportOps::Zendesk::Configuration Setting up a client
61
+ # @example
62
+ # require 'support_ops_zendesk'
63
+ #
64
+ # SupportOps::Zendesk::Configuration.configure do |config|
65
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
66
+ # config.username = 'jason@example.com'
67
+ # config.token = 'abc123'
68
+ # end
69
+ #
70
+ # locales = SupportOps::Zendesk::Locales.list_help_center
71
+ # pp locales.first
72
+ # # => "en-us"
73
+ def self.list_help_center
74
+ response = client.connection.get('help_center/locales')
75
+ Oj.load(response.body)['locales']
76
+ end
77
+
78
+ ##
79
+ # Lists the default locale in the Zendesk Help Center system
80
+ #
81
+ # @author Jason Colyer
82
+ # @since 1.0.0
83
+ # @return [Array]
84
+ # @see
85
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-enabled-locales-and-default-locale
86
+ # Zendesk API > Translations > List Enabled Locales and Default Locale
87
+ # @see SupportOps::Zendesk::Configuration Setting up a client
88
+ # @example
89
+ # require 'support_ops_zendesk'
90
+ #
91
+ # SupportOps::Zendesk::Configuration.configure do |config|
92
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
93
+ # config.username = 'jason@example.com'
94
+ # config.token = 'abc123'
95
+ # end
96
+ #
97
+ # locale = SupportOps::Zendesk::Locales.list_help_center_default
98
+ # pp locale
99
+ # # => "en-us"
100
+ def self.list_help_center_default
101
+ response = client.connection.get('help_center/locales')
102
+ Oj.load(response.body)['default_locale']
103
+ end
104
+
105
+ ##
106
+ # Lists all locales for an agent in the Zendesk system
107
+ #
108
+ # @author Jason Colyer
109
+ # @since 1.0.0
110
+ # @return [Array]
111
+ # @see
112
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#list-locales-for-agent
113
+ # Zendesk API > Locales > List Locales for Agent
114
+ # @see SupportOps::Zendesk::Configuration Setting up a client
115
+ # @example
116
+ # require 'support_ops_zendesk'
117
+ #
118
+ # SupportOps::Zendesk::Configuration.configure do |config|
119
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
120
+ # config.username = 'jason@example.com'
121
+ # config.token = 'abc123'
122
+ # end
123
+ #
124
+ # locales = SupportOps::Zendesk::Locales.list_for_agent
125
+ # pp locales.first.name
126
+ # # => "English"
127
+ def self.list_for_agent
128
+ response = client.connection.get('locales/agent')
129
+ Oj.load(response.body)['locales'].map { |l| Locales.new(l) }
130
+ end
131
+
132
+ ##
133
+ # Lists all available public locales in the Zendesk system
134
+ #
135
+ # @author Jason Colyer
136
+ # @since 1.0.0
137
+ # @return [Array]
138
+ # @see
139
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#list-available-public-locales
140
+ # Zendesk API > Locales > List Available Public Locales
141
+ # @see SupportOps::Zendesk::Configuration Setting up a client
142
+ # @example
143
+ # require 'support_ops_zendesk'
144
+ #
145
+ # SupportOps::Zendesk::Configuration.configure do |config|
146
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
147
+ # config.username = 'jason@example.com'
148
+ # config.token = 'abc123'
149
+ # end
150
+ #
151
+ # locales = SupportOps::Zendesk::Locales.list_available
152
+ # pp locales.first.name
153
+ # # => "English"
154
+ def self.list_available
155
+ response = client.connection.get('locales/public')
156
+ Oj.load(response.body)['locales'].map { |l| Locales.new(l) }
157
+ end
158
+
159
+ ##
160
+ # Get the locale of the current agent in the Zendesk system
161
+ #
162
+ # @author Jason Colyer
163
+ # @since 1.0.0
164
+ # @return [Array]
165
+ # @see
166
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#show-current-locale
167
+ # Zendesk API > Locales > Show Current Locale
168
+ # @see SupportOps::Zendesk::Configuration Setting up a client
169
+ # @example
170
+ # require 'support_ops_zendesk'
171
+ #
172
+ # SupportOps::Zendesk::Configuration.configure do |config|
173
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
174
+ # config.username = 'jason@example.com'
175
+ # config.token = 'abc123'
176
+ # end
177
+ #
178
+ # locale = SupportOps::Zendesk::Locales.current
179
+ # pp locale.name
180
+ # # => "English"
181
+ def self.current
182
+ response = client.connection.get('locales/current')
183
+ Oj.load(response.body)['locale'].map { |l| Locales.new(l) }
184
+ end
185
+
186
+ ##
187
+ # Locates a locale within Zendesk by name. Can utilize a cache for quicker results
188
+ #
189
+ # @author Jason Colyer
190
+ # @since 1.0.0
191
+ # @overload find_by_name(key: value)
192
+ # @param name [String required] The name to search for
193
+ # @param cache [Array] An Array of SupportOps::Zendesk::Locales to use as a cache
194
+ # @return [Object] An instance of {SupportOps::Zendesk::Locales}
195
+ # @example
196
+ # require 'support_ops_zendesk'
197
+ #
198
+ # SupportOps::Zendesk::Configuration.configure do |config|
199
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
200
+ # config.username = 'jason@example.com'
201
+ # config.token = 'abc123'
202
+ # end
203
+ #
204
+ # locales = SupportOps::Zendesk::Locales.list
205
+ # locale = SupportOps::Zendesk::Locales.find_by_name(name: 'English', cache: locales)
206
+ # pp locale.name
207
+ # # => "English"
208
+ # pp locale.id
209
+ # # => 1
210
+ def self.find_by_name(**args)
211
+ raise 'You have to provide a name' unless args[:name]
212
+ if args[:cache]
213
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
214
+ locales = args[:cache]
215
+ else
216
+ locales = list
217
+ end
218
+ locales.detect { |c| c.name.downcase == args[:name].to_s.downcase }
219
+ end
220
+
221
+ ##
222
+ # Locates a locale within Zendesk by locale code. Can utilize a cache for quicker results
223
+ #
224
+ # @author Jason Colyer
225
+ # @since 1.0.0
226
+ # @overload find_by_name(key: value)
227
+ # @param code [String required] The locale code to search for
228
+ # @param cache [Array] An Array of SupportOps::Zendesk::Locales to use as a cache
229
+ # @return [Object] An instance of {SupportOps::Zendesk::Locales}
230
+ # @example
231
+ # require 'support_ops_zendesk'
232
+ #
233
+ # SupportOps::Zendesk::Configuration.configure do |config|
234
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
235
+ # config.username = 'jason@example.com'
236
+ # config.token = 'abc123'
237
+ # end
238
+ #
239
+ # locales = SupportOps::Zendesk::Locales.list
240
+ # locale = SupportOps::Zendesk::Locales.find_by_code(code: 'en-us', cache: locales)
241
+ # pp locale.name
242
+ # # => "English"
243
+ # pp locale.id
244
+ # # => 1
245
+ def self.find_by_code(**args)
246
+ raise 'You have to provide a name' unless args[:code]
247
+ if args[:cache]
248
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
249
+ locales = args[:cache]
250
+ else
251
+ locales = list
252
+ end
253
+ locales.detect { |c| c.locale.downcase == args[:code].to_s.downcase }
254
+ end
255
+
256
+ ##
257
+ # Locates a specific locale in the Zendesk system
258
+ #
259
+ # @author Jason Colyer
260
+ # @since 1.0.0
261
+ # @see
262
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#show-locale
263
+ # Zendesk API > Locales > Show Locale
264
+ # @see SupportOps::Zendesk::Configuration Setting up a client
265
+ # @example
266
+ # require 'support_ops_zendesk'
267
+ #
268
+ # SupportOps::Zendesk::Configuration.configure do |config|
269
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
270
+ # config.username = 'jason@example.com'
271
+ # config.token = 'abc123'
272
+ # end
273
+ #
274
+ # locale = SupportOps::Zendesk::Locales.get(1)
275
+ # pp locale.name
276
+ # # => "English"
277
+ def self.get(object)
278
+ if object.is_a? Locales
279
+ Locales.new(id: id).find
280
+ else
281
+ Locales.new(id: object).find
282
+ end
283
+ end
284
+
285
+ ##
286
+ # Locates a specific locale in the Zendesk system
287
+ #
288
+ # @author Jason Colyer
289
+ # @since 1.0.0
290
+ # @see
291
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/#show-locale
292
+ # Zendesk API > Locales > Show Locale
293
+ # @see SupportOps::Zendesk::Configuration Setting up a client
294
+ # @example
295
+ # require 'support_ops_zendesk'
296
+ #
297
+ # SupportOps::Zendesk::Configuration.configure do |config|
298
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
299
+ # config.username = 'jason@example.com'
300
+ # config.token = 'abc123'
301
+ # end
302
+ #
303
+ # locale = SupportOps::Zendesk::Locales.get!(1)
304
+ # pp locale.name
305
+ # # => "English"
306
+ def self.get!(object)
307
+ if object.is_a? Locales
308
+ Locales.new(id: id).find!
309
+ else
310
+ Locales.new(id: object).find!
311
+ end
312
+ end
313
+
314
+ private
315
+
316
+ ##
317
+ # @private
318
+ def get_record
319
+ response = self.client.connection.get("locales/#{self.id}")
320
+ return nil if response.status != 200
321
+
322
+ Oj.load(response.body)['locale']
323
+ end
324
+ end
325
+ end
326
+ end