Class: Readiness::Zendesk::Themes
- Defined in:
- lib/support_readiness/zendesk/themes.rb
Overview
Defines the class Themes within the module Readiness::Zendesk.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.create!(client, theme, location = './') ⇒ Object
Creates a theme.
-
.delete!(client, theme) ⇒ Boolean
Deletes a theme.
-
.find(client, tid) ⇒ Object
Locates a theme within Zendesk.
-
.find!(client, tid) ⇒ Object
Locates a theme within Zendesk.
-
.find_by_name(client, name) ⇒ Object
Locates a theme within Zendesk by its name.
-
.generate_import_job!(client, theme) ⇒ Hash
Creates an import job for creating a Zendesk theme.
-
.generate_update_job!(client, theme) ⇒ Object
Creates an update job for creating a Zendesk theme.
-
.list(client) ⇒ Array
Lists themes within Zendesk.
-
.live_theme(client, brand = nil) ⇒ Object
Returns the live theme for the Zendesk instance.
-
.package!(location = './') ⇒ String
Creates a zip file from the given directory for a Zendesk app.
-
.update!(client, theme, location = './') ⇒ Object
Creates a theme.
-
.upload!(client, job, file) ⇒ Object
Uploads a zip file to an import or update job.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ Themes
constructor
Creates a new Themes instance.
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 = {}) ⇒ Themes
Creates a new Readiness::Zendesk::Themes instance
24 25 26 27 28 29 30 31 |
# File 'lib/support_readiness/zendesk/themes.rb', line 24 def initialize(object = {}) @author = object['author'] @brand_id = object['brand_id'] @id = object['id'] @live = object['live'] @name = object['name'] @version = object['version'] end |
Instance Attribute Details
#author ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/themes.rb', line 13 def @author end |
#brand_id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/themes.rb', line 13 def brand_id @brand_id end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/themes.rb', line 13 def id @id end |
#live ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/themes.rb', line 13 def live @live end |
#name ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/themes.rb', line 13 def name @name end |
#version ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/themes.rb', line 13 def version @version end |
Class Method Details
.create!(client, theme, location = './') ⇒ Object
Creates a theme. This will exit on error
339 340 341 342 343 |
# File 'lib/support_readiness/zendesk/themes.rb', line 339 def self.create!(client, theme, location = './') file = Themes.package!(location) job = generate_import_job!(client, theme) upload!(client, job, file) end |
.delete!(client, theme) ⇒ Boolean
Deletes a theme. Will exit if unsuccessful
365 366 367 368 369 |
# File 'lib/support_readiness/zendesk/themes.rb', line 365 def self.delete!(client, theme) response = client.connection.delete "guide/theming/themes/#{theme.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a theme', id: theme.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, tid) ⇒ Object
Locates a theme within Zendesk. This will not exit on error (except Authentication errors)
103 104 105 106 107 108 109 |
# File 'lib/support_readiness/zendesk/themes.rb', line 103 def self.find(client, tid) response = client.connection.get "guide/theming/themes/#{tid}" handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: tid }) unless response.status == 200 return Themes.new(Oj.load(response.body)['theme']) if response.status == 200 Oj.load(response.body) end |
.find!(client, tid) ⇒ Object
Locates a theme within Zendesk. This will exit on error
130 131 132 133 134 |
# File 'lib/support_readiness/zendesk/themes.rb', line 130 def self.find!(client, tid) response = client.connection.get "guide/theming/themes/#{tid}" handle_request_error(1, 'Zendesk', response.status, { action: 'Find theme', id: tid }) unless response.status == 200 Themes.new(Oj.load(response.body)['theme']) end |
.find_by_name(client, name) ⇒ Object
Locates a theme within Zendesk by its name.
154 155 156 157 |
# File 'lib/support_readiness/zendesk/themes.rb', line 154 def self.find_by_name(client, name) themes = Themes.list(client) themes.detect { |t| t.name == name } end |
.generate_import_job!(client, theme) ⇒ Hash
Creates an import job for creating a Zendesk theme. This will exit on error
230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/support_readiness/zendesk/themes.rb', line 230 def self.generate_import_job!(client, theme) object = { job: { attributes: { brand_id: theme.brand_id, format: 'zip' } } } response = client.connection.post 'guide/theming/jobs/themes/imports', object.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Create theme import job', id: theme.name }) unless response.status == 202 Oj.load(response.body)['job'] end |
.generate_update_job!(client, theme) ⇒ Object
Creates an update job for creating a Zendesk theme. This will exit on error
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/support_readiness/zendesk/themes.rb', line 195 def self.generate_update_job!(client, theme) object = { job: { attributes: { theme_id: theme.id, replace_settings: true, format: 'zip' } } } response = client.connection.post 'guide/theming/jobs/themes/updates', object.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Upload theme', id: theme.id }) unless response.status == 200 ThemeJobStatuses.new(Oj.load(response.body)['job']) end |
.list(client) ⇒ Array
Lists themes within Zendesk
51 52 53 54 55 |
# File 'lib/support_readiness/zendesk/themes.rb', line 51 def self.list(client) response = client.connection.get 'guide/theming/themes' handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 Oj.load(response.body)['themes'].map { |t| Themes.new(t) } end |
.live_theme(client, brand = nil) ⇒ Object
Returns the live theme for the Zendesk instance
75 76 77 78 79 80 81 82 |
# File 'lib/support_readiness/zendesk/themes.rb', line 75 def self.live_theme(client, brand = nil) themes = Themes.list(client) if brand themes.detect { |t| t.live && t.brand_id.to_i == brand.id.to_i } else themes.detect { |t| t.live } end end |
.package!(location = './') ⇒ String
Creates a zip file from the given directory for a Zendesk app. This will exit on error
171 172 173 174 |
# File 'lib/support_readiness/zendesk/themes.rb', line 171 def self.package!(location = './') item_list = %w[ assets manifest.json script.js settings style.css templates thumbnail.png translations ] create_package!(item_list, location) end |
.update!(client, theme, location = './') ⇒ Object
Creates a theme. This will exit on error
312 313 314 315 316 |
# File 'lib/support_readiness/zendesk/themes.rb', line 312 def self.update!(client, theme, location = './') file = Themes.package!(location) job = generate_update_job!(client, theme) upload!(client, job, file) end |
.upload!(client, job, file) ⇒ Object
Uploads a zip file to an import or update job. This will exit on error
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/support_readiness/zendesk/themes.rb', line 266 def self.upload!(client, job, file) url = if job.is_a?(Hash) job['data']['upload']['url'] else job.data['upload']['url'] end params = if job.is_a?(Hash) job['data']['upload']['parameters'] else job.data['upload']['parameters'] end job_id = if job.is_a?(Hash) job['id'] else job.id end object = params.merge( file: ::Faraday::UploadIO.new(file, 'application/zip') ) response = client.upload_connection.post url, object ThemeJobStatuses.find!(client, job_id) end |