Class: Readiness::Zendesk::DynamicContent
- Defined in:
- lib/support_readiness/zendesk/dynamic_content.rb
Overview
Defines the class DynamicContent within the module Readiness::Zendesk.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.create!(client, dynamic_content, variants) ⇒ Object
Creates a dynamic content item within Zendesk.
-
.delete!(client, dynamic_content) ⇒ Boolean
Deletes a dynamic content item within Zendesk.
-
.find(client, did) ⇒ Hash
Locates a dynamic content item within Zendesk.
-
.find!(client, did) ⇒ Hash
Locates a dynamic content item within Zendesk.
-
.list(client) ⇒ Array
Lists dynamic content.
-
.update!(client, dynamic_content) ⇒ Object
Updates a dynamic content item within Zendesk.
-
.variants(client, dynamic_content) ⇒ Array
Lists variants for a dynamic content.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ DynamicContent
constructor
Creates a new DyanmicContent 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 = {}) ⇒ DynamicContent
Creates a new Readiness::Zendesk::DyanmicContent instance
24 25 26 27 28 29 30 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 24 def initialize(object = {}) @default_locale_id = object['default_locale_id'] @id = object['id'] @name = object['name'] @outdated = object['outdated'] @placeholder = object['placeholder'] end |
Instance Attribute Details
#default_locale_id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 13 def default_locale_id @default_locale_id end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 13 def id @id end |
#name ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 13 def name @name end |
#outdated ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 13 def outdated @outdated end |
#placeholder ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 13 def placeholder @placeholder end |
Class Method Details
.create!(client, dynamic_content, variants) ⇒ Object
Creates a dynamic content item within Zendesk. Will exit if unsuccessful
168 169 170 171 172 173 174 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 168 def self.create!(client, dynamic_content, variants) object = to_hash(dynamic_content).compact object['variants'] = variants.map { |t| to_hash(t).compact } response = client.connection.post 'dynamic_content/items', { item: object }.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Create dynamic content', message: Oj.load(response.body)}) unless response.status == 201 DynamicContent.new(Oj.load(response.body)['item']) end |
.delete!(client, dynamic_content) ⇒ Boolean
Deletes a dynamic content item within Zendesk. Will exit if unsuccessful
223 224 225 226 227 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 223 def self.delete!(client, dynamic_content) response = client.connection.delete "dynamic_content/items/#{dynamic_content.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a dynamic content', id: dynamic_content.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, did) ⇒ Hash
Locates a dynamic content item within Zendesk. This will not exit on error (except Authentication errors)
108 109 110 111 112 113 114 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 108 def self.find(client, did) response = client.connection.get("dynamic_content/items/#{did}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: did }) unless response.status == 200 return DynamicContent.new(Oj.load(response.body)['item']) if response.status == 200 Oj.load(response.body) end |
.find!(client, did) ⇒ Hash
Locates a dynamic content item within Zendesk. This will exit on error
135 136 137 138 139 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 135 def self.find!(client, did) response = client.connection.get("dynamic_content/items/#{did}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find dynamic content', id: did }) unless response.status == 200 DynamicContent.new(Oj.load(response.body)['item']) end |
.list(client) ⇒ Array
Lists dynamic content.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 50 def self.list(client) array = [] page = 1 loop do response = client.connection.get("dynamic_content/items?page=#{page}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['items'].map { |i| DynamicContent.new(i) } break if body['items'].count < 100 page += 1 end array end |
.update!(client, dynamic_content) ⇒ Object
Updates a dynamic content item within Zendesk. Will exit if unsuccessful
197 198 199 200 201 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 197 def self.update!(client, dynamic_content) response = client.connection.put "dynamic_content/items/#{dynamic_content.id}", to_clean_json_with_key(dynamic_content, 'item') handle_request_error(1, 'Zendesk', response.status, { action: 'Update dynamic content', id: dynamic_content.id, message: Oj.load(response.body)}) unless response.status == 200 DynamicContent.new(Oj.load(response.body)['item']) end |
.variants(client, dynamic_content) ⇒ Array
Lists variants for a dynamic content.
85 86 87 |
# File 'lib/support_readiness/zendesk/dynamic_content.rb', line 85 def self.variants(client, dynamic_content) DynamicContentVariants.list(client, dynamic_content) end |