Class: Readiness::Zendesk::Macros
- Defined in:
- lib/support_readiness/zendesk/macros.rb
Overview
Defines the class Macros within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #actions ⇒ Object
- #active ⇒ Object
- #description ⇒ Object
- #id ⇒ Object
- #restriction ⇒ Object
- #title ⇒ Object
Class Method Summary collapse
-
.create!(client, macro) ⇒ Object
Creates a macro.
-
.delete!(client, macro) ⇒ Boolean
Deletes a macro.
-
.delete_many!(client, mids) ⇒ Boolean
Deletes multiple macros.
-
.find(client, mid) ⇒ Hash
Locates a macro within Zendesk.
-
.find!(client, mid) ⇒ Object
Locates a macro within Zendesk.
-
.list(client) ⇒ Array
Lists macros.
-
.update!(client, macro) ⇒ Object
Updates a macro.
-
.update_many!(client, macros) ⇒ array
Updates multiple macros.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ Macros
constructor
Creates a new Macros 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 = {}) ⇒ Macros
Creates a new Readiness::Zendesk::Macros instance
24 25 26 27 28 29 30 31 |
# File 'lib/support_readiness/zendesk/macros.rb', line 24 def initialize(object = {}) @actions = object['actions'] @active = object['active'] @description = object['description'] @id = object['id'] @restriction = object['restriction'] @title = object['title'] end |
Instance Attribute Details
#actions ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/macros.rb', line 13 def actions @actions end |
#active ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/macros.rb', line 13 def active @active end |
#description ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/macros.rb', line 13 def description @description end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/macros.rb', line 13 def id @id end |
#restriction ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/macros.rb', line 13 def restriction @restriction end |
#title ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/macros.rb', line 13 def title @title end |
Class Method Details
.create!(client, macro) ⇒ Object
Creates a macro. Will exit if unsuccessful
140 141 142 143 144 |
# File 'lib/support_readiness/zendesk/macros.rb', line 140 def self.create!(client, macro) response = client.connection.post 'macros', to_clean_json_with_key(macro, 'macro') handle_request_error(1, 'Zendesk', response.status, { action: 'Create macro', message: Oj.load(response.body)}) unless response.status == 201 Macros.new(Oj.load(response.body)['macro']) end |
.delete!(client, macro) ⇒ Boolean
Deletes a macro. Will exit if unsuccessful
224 225 226 227 228 |
# File 'lib/support_readiness/zendesk/macros.rb', line 224 def self.delete!(client, macro) response = client.connection.delete "macros/#{macro.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a macro', id: macro.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.delete_many!(client, mids) ⇒ Boolean
Deletes multiple macros
249 250 251 252 253 |
# File 'lib/support_readiness/zendesk/macros.rb', line 249 def self.delete_many!(client, mids) response = client.connection.delete("macros/destroy_many?ids=#{mids.join(',')}") handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many macros', message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, mid) ⇒ Hash
Locates a macro within Zendesk. This will not exit on error (except Authentication errors)
85 86 87 88 89 90 91 |
# File 'lib/support_readiness/zendesk/macros.rb', line 85 def self.find(client, mid) response = client.connection.get("macros/#{mid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: mid }) unless response.status == 200 return Macros.new(Oj.load(response.body)['macro']) if response.status == 200 Oj.load(response.body) end |
.find!(client, mid) ⇒ Object
Locates a macro within Zendesk. This will exit on error
112 113 114 115 116 |
# File 'lib/support_readiness/zendesk/macros.rb', line 112 def self.find!(client, mid) response = client.connection.get("macros/#{mid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find macro', id: mid }) unless response.status == 200 Macros.new(Oj.load(response.body)['macro']) end |
.list(client) ⇒ Array
Lists macros
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/support_readiness/zendesk/macros.rb', line 51 def self.list(client) array = [] opts = "page[size]=100" loop do response = client.connection.get("macros?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['macros'].map { |t| Macros.new(t) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.update!(client, macro) ⇒ Object
Updates a macro. Will exit if unsuccessful
167 168 169 170 171 |
# File 'lib/support_readiness/zendesk/macros.rb', line 167 def self.update!(client, macro) response = client.connection.put "macros/#{macro.id}", to_clean_json_with_key(macro, 'macro') handle_request_error(1, 'Zendesk', response.status, { action: 'Update macro', id: macro.id, message: Oj.load(response.body)}) unless response.status == 200 Macros.new(Oj.load(response.body)['macro']) end |
.update_many!(client, macros) ⇒ array
Updates multiple macros. Can only update position and active values.
197 198 199 200 201 202 |
# File 'lib/support_readiness/zendesk/macros.rb', line 197 def self.update_many!(client, macros) data = { macros: macros.map { |m| to_hash(m).compact } }.to_json response = client.connection.put('macros/update_many', data) handle_request_error(1, 'Zendesk', response.status, { action: 'Update many macros', message: Oj.load(response.body)}) unless response.status == 200 Oj.load(response.body)['macros'].map { |m| Macros.new(m) } end |