Class: Readiness::Zendesk::Automations
- Defined in:
- lib/support_readiness/zendesk/automations.rb
Overview
Defines the class Automations within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #actions ⇒ Object
- #active ⇒ Object
- #conditions ⇒ Object
- #id ⇒ Object
- #position ⇒ Object
- #title ⇒ Object
Class Method Summary collapse
-
.create!(client, automation) ⇒ Object
Creates an automation.
-
.delete!(client, automation) ⇒ Boolean
Deletes an automation.
-
.delete_many!(client, aids) ⇒ Boolean
Deletes multiple automations via a batch job.
-
.find(client, aid) ⇒ Hash
Locates an automation within Zendesk.
-
.find!(client, aid) ⇒ Object
Locates an automation within Zendesk.
-
.list(client) ⇒ Array
Lists automations.
-
.update!(client, automation) ⇒ Object
Updates an automation.
-
.update_many!(client, automations) ⇒ Array
Updates multiple automations.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ Automations
constructor
Creates a new Automations 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 = {}) ⇒ Automations
Creates a new Readiness::Zendesk::Automations instance
24 25 26 27 28 29 30 31 |
# File 'lib/support_readiness/zendesk/automations.rb', line 24 def initialize(object = {}) @actions = object['actions'] @active = object['active'] @conditions = object['conditions'] @id = object['id'] @position = object['position'] @title = object['title'] end |
Instance Attribute Details
#actions ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/automations.rb', line 13 def actions @actions end |
#active ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/automations.rb', line 13 def active @active end |
#conditions ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/automations.rb', line 13 def conditions @conditions end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/automations.rb', line 13 def id @id end |
#position ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/automations.rb', line 13 def position @position end |
#title ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/automations.rb', line 13 def title @title end |
Class Method Details
.create!(client, automation) ⇒ Object
Creates an automation. Will exit if unsuccessful
160 161 162 163 164 |
# File 'lib/support_readiness/zendesk/automations.rb', line 160 def self.create!(client, automation) response = client.connection.post 'automations', to_clean_json_with_key(automation, 'automation') handle_request_error(1, 'Zendesk', response.status, { action: 'Create automation', message: Oj.load(response.body)}) unless response.status == 201 Automations.new(Oj.load(response.body)['automation']) end |
.delete!(client, automation) ⇒ Boolean
Deletes an automation. Will exit if unsuccessful
267 268 269 270 271 |
# File 'lib/support_readiness/zendesk/automations.rb', line 267 def self.delete!(client, automation) response = client.connection.delete "automations/#{automation.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete an automation', id: automation.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.delete_many!(client, aids) ⇒ Boolean
Deletes multiple automations via a batch job
292 293 294 295 296 |
# File 'lib/support_readiness/zendesk/automations.rb', line 292 def self.delete_many!(client, aids) response = client.connection.delete("automations/destroy_many?ids=#{aids.join(',')}") handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many automations', message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, aid) ⇒ Hash
Locates an automation within Zendesk. This will not exit on error (except Authentication errors)
85 86 87 88 89 90 91 |
# File 'lib/support_readiness/zendesk/automations.rb', line 85 def self.find(client, aid) response = client.connection.get("automations/#{aid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: aid }) unless response.status == 200 return Automations.new(Oj.load(response.body)['automation']) if response.status == 200 Oj.load(response.body) end |
.find!(client, aid) ⇒ Object
Locates an automation within Zendesk. This will exit on error
112 113 114 115 116 |
# File 'lib/support_readiness/zendesk/automations.rb', line 112 def self.find!(client, aid) response = client.connection.get("automations/#{aid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find automation', id: aid }) unless response.status == 200 Automations.new(Oj.load(response.body)['automation']) end |
.list(client) ⇒ Array
Lists automations.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/support_readiness/zendesk/automations.rb', line 51 def self.list(client) array = [] opts = "page[size]=100" loop do response = client.connection.get("automations?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['automations'].map { |a| Automations.new(a) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.update!(client, automation) ⇒ Object
Updates an automation. Will exit if unsuccessful
208 209 210 211 212 |
# File 'lib/support_readiness/zendesk/automations.rb', line 208 def self.update!(client, automation) response = client.connection.put "automations/#{automation.id}", to_clean_json_with_key(automation, 'automation') handle_request_error(1, 'Zendesk', response.status, { action: 'Update automation', id: automation.id, message: Oj.load(response.body)}) unless response.status == 200 Automations.new(Oj.load(response.body)['automation']) end |
.update_many!(client, automations) ⇒ Array
Updates multiple automations. Can only update position and active values.
240 241 242 243 244 245 |
# File 'lib/support_readiness/zendesk/automations.rb', line 240 def self.update_many!(client, automations) data = { automations: automations.map { |t| to_hash(t).compact } }.to_json response = client.connection.put('automations/update_many', data) handle_request_error(1, 'Zendesk', response.status, { action: 'Update many automations', message: Oj.load(response.body)}) unless response.status == 200 Oj.load(response.body)['automations'].map { |a| Automations.new(a) } end |