Class: Readiness::Zendesk::Views
- Defined in:
- lib/support_readiness/zendesk/views.rb
Overview
Defines the class Views within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #active ⇒ Object
- #conditions ⇒ Object
- #description ⇒ Object
- #execution ⇒ Object
- #id ⇒ Object
- #position ⇒ Object
- #restriction ⇒ Object
- #title ⇒ Object
Class Method Summary collapse
-
.count_tickets(client, view) ⇒ Hash
Display count information for a view.
-
.count_tickets_in_many(client, vids) ⇒ Array
Display count information for multiple views.
-
.create!(client, view) ⇒ Object
Creates a view.
-
.create_or_update_object(view) ⇒ Hash
Returns a Hash used in creating/updating views, as the formatting does not match the Zendesk list functions.
-
.delete!(client, view) ⇒ Boolean
Deletes a view.
-
.delete_many!(client, vids) ⇒ Boolean
Deletes multiple views.
-
.find(client, vid) ⇒ Hash
Locates a view within Zendesk.
-
.find!(client, vid) ⇒ Object
Locates a view within Zendesk.
-
.find_by_name(client, name) ⇒ Object
Locates a view within Zendesk by name.
-
.find_by_name!(client, name) ⇒ Object
Locates a view within Zendesk by name.
-
.find_many(client, vids) ⇒ Array
Locates up to 100 views within Zendesk.
-
.list(client) ⇒ Array
Lists views.
-
.preview!(client, view) ⇒ Hash
Previews what a view would look like.
-
.tickets(client, view) ⇒ Array
Get the tickets in a view.
-
.update!(client, view) ⇒ Object
Updates a view.
-
.update_many!(client, views) ⇒ object
Updates multiple views via a batch job.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ Views
constructor
Creates a new Views 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 = {}) ⇒ Views
Creates a new Readiness::Zendesk::Views instance
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/support_readiness/zendesk/views.rb', line 24 def initialize(object = {}) @active = object['active'] @conditions = object['conditions'] @description = object['description'] @execution = object['execution'] @id = object['id'] @position = object['position'] @restriction = object['restriction'] @title = object['title'] end |
Instance Attribute Details
#active ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def active @active end |
#conditions ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def conditions @conditions end |
#description ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def description @description end |
#execution ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def execution @execution end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def id @id end |
#position ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def position @position end |
#restriction ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def restriction @restriction end |
#title ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/views.rb', line 13 def title @title end |
Class Method Details
.count_tickets(client, view) ⇒ Hash
Display count information for a view
441 442 443 444 445 |
# File 'lib/support_readiness/zendesk/views.rb', line 441 def self.count_tickets(client, view) response = client.connection.get "views/#{view.id}/count" handle_request_error(1, 'Zendesk', response.status, { action: 'Count tickets in a view', message: Oj.load(response.body)}) unless response.status == 200 Oj.load(response.body)['view_count'] end |
.count_tickets_in_many(client, vids) ⇒ Array
Display count information for multiple views
466 467 468 469 470 |
# File 'lib/support_readiness/zendesk/views.rb', line 466 def self.count_tickets_in_many(client, vids) response = client.connection.get "views/count_many?ids=#{vids.join(',')}" handle_request_error(1, 'Zendesk', response.status, { action: 'Count tickets in views', message: Oj.load(response.body)}) unless response.status == 200 Oj.load(response.body)['view_counts'] end |
.create!(client, view) ⇒ Object
Creates a view. Will exit if unsuccessful
248 249 250 251 252 |
# File 'lib/support_readiness/zendesk/views.rb', line 248 def self.create!(client, view) response = client.connection.post 'views', { view: create_or_update_object(view) }.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Create view', message: Oj.load(response.body)}) unless response.status == 201 Views.new(Oj.load(response.body)['view']) end |
.create_or_update_object(view) ⇒ Hash
Returns a Hash used in creating/updating views, as the formatting does not match the Zendesk list functions
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/support_readiness/zendesk/views.rb', line 490 def self.create_or_update_object(view) { id: view.id, title: view.title, description: view.description, active: view.active, position: view.position, restriction: view.restriction, all: view.conditions['all'], any: view.conditions['any'], output: { columns: view.execution['columns'].map { |c| c['id'] }, group_by: view.execution['group_by'], group_order: view.execution['group_order'], sort_by: view.execution['sort_by'], sort_order: view.execution['sort_order'] } }.compact end |
.delete!(client, view) ⇒ Boolean
Deletes a view. Will exit if unsuccessful
332 333 334 335 336 |
# File 'lib/support_readiness/zendesk/views.rb', line 332 def self.delete!(client, view) response = client.connection.delete "views/#{view.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a view', id: view.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.delete_many!(client, vids) ⇒ Boolean
Deletes multiple views
357 358 359 360 361 |
# File 'lib/support_readiness/zendesk/views.rb', line 357 def self.delete_many!(client, vids) response = client.connection.delete("views/destroy_many?ids=#{vids.join(',')}") handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many views', message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, vid) ⇒ Hash
Locates a view within Zendesk. This will not exit on error (except Authentication errors)
87 88 89 90 91 92 93 |
# File 'lib/support_readiness/zendesk/views.rb', line 87 def self.find(client, vid) response = client.connection.get("views/#{vid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: vid }) unless response.status == 200 return Views.new(Oj.load(response.body)['view']) if response.status == 200 Oj.load(response.body) end |
.find!(client, vid) ⇒ Object
Locates a view within Zendesk. This will exit on error
114 115 116 117 118 |
# File 'lib/support_readiness/zendesk/views.rb', line 114 def self.find!(client, vid) response = client.connection.get("views/#{vid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find view', id: vid }) unless response.status == 200 Views.new(Oj.load(response.body)['view']) end |
.find_by_name(client, name) ⇒ Object
Locates a view within Zendesk by name. This will not exit on error (except Authentication errors)
163 164 165 166 |
# File 'lib/support_readiness/zendesk/views.rb', line 163 def self.find_by_name(client, name) views = Views.list(client) views.detect { |v| v.title == name } end |
.find_by_name!(client, name) ⇒ Object
Locates a view within Zendesk by name. This will exit on error
186 187 188 189 190 191 |
# File 'lib/support_readiness/zendesk/views.rb', line 186 def self.find_by_name!(client, name) views = Views.list(client) view = views.detect { |v| v.title == name } handle_request_error(1, 'Zendesk', 404, { action: 'Find view', id: name }) if view.nil? view end |
.find_many(client, vids) ⇒ Array
Locates up to 100 views within Zendesk.
139 140 141 142 143 |
# File 'lib/support_readiness/zendesk/views.rb', line 139 def self.find_many(client, vids) response = client.connection.get("views/show_many?ids=#{vids.join(',')}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: vids }) unless response.status == 200 Oj.load(response.body)['views'].map { |o| Views.new(o) } end |
.list(client) ⇒ Array
Lists views
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/support_readiness/zendesk/views.rb', line 53 def self.list(client) array = [] opts = "page[size]=100" loop do response = client.connection.get("views?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['views'].map { |t| Views.new(t) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.preview!(client, view) ⇒ Hash
Previews what a view would look like
383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/support_readiness/zendesk/views.rb', line 383 def self.preview!(client, view) converted = create_or_update_object(view) data = { all: converted[:all], any: converted[:any], output: converted[:output] }.compact response = client.connection.post 'views/preview', { view: data }.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Preview a view', message: Oj.load(response.body)}) unless response.status == 200 Oj.load(response.body) end |
.tickets(client, view) ⇒ Array
Get the tickets in a view
415 416 417 418 419 |
# File 'lib/support_readiness/zendesk/views.rb', line 415 def self.tickets(client, view) response = client.connection.get "views/#{view.id}/tickets" handle_request_error(1, 'Zendesk', response.status, { action: 'Get tickets from a view', message: Oj.load(response.body)}) unless response.status == 200 Oj.load(response.body)['tickets'] end |
.update!(client, view) ⇒ Object
Updates a view. Will exit if unsuccessful
275 276 277 278 279 |
# File 'lib/support_readiness/zendesk/views.rb', line 275 def self.update!(client, view) response = client.connection.put "views/#{view.id}", { view: create_or_update_object(view) }.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Update view', id: view.id, message: Oj.load(response.body)}) unless response.status == 200 Views.new(Oj.load(response.body)['view']) end |
.update_many!(client, views) ⇒ object
Updates multiple views via a batch job
305 306 307 308 309 310 |
# File 'lib/support_readiness/zendesk/views.rb', line 305 def self.update_many!(client, views) data = { views: views.map { |v| create_or_update_object(v) } }.to_json response = client.connection.put('views/update_many', data) handle_request_error(1, 'Zendesk', response.status, { action: 'Update many views', message: Oj.load(response.body)}) unless response.status == 200 JobStatuses.new(Oj.load(response.body)['job_status']) end |