Class: Readiness::Zendesk::ThemeJobStatuses

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/zendesk/theme_job_statuses.rb

Overview

Defines the class ThemeJobStatuses within the module Readiness::Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.12

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = {}) ⇒ ThemeJobStatuses

Creates a new Readiness::Zendesk::ThemeJobStatuses instance

Examples:

require 'support_readiness'
Readiness::Zendesk::ThemeJobStatuses.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.12



24
25
26
27
28
29
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 24

def initialize(object = {})
  @data = object['data']
  @id = object['id']
  @errors = object['errors']
  @status = object['status']
end

Instance Attribute Details

#dataObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 13

def data
  @data
end

#errorsObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 13

def errors
  @errors
end

#idObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 13

def id
  @id
end

#statusObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 13

def status
  @status
end

Class Method Details

.find(client, jid) ⇒ Hash

Locates an theme job status within Zendesk. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::ThemeJobStatuses.find(client, '8b726e606741012ffc2d782bcb7848fe')
pp job.status
# => "completed"

Parameters:

  • client (Object)

    An instance of Client

  • jid (String)

    The job status ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



50
51
52
53
54
55
56
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 50

def self.find(client, jid)
  response = client.connection.get("guide/theming/jobs/#{jid}")
  handle_request_error(0, 'Zendesk', response.status,  { action: 'get', id: jid }) unless response.status == 200
  return ThemeJobStatuses.new(Oj.load(response.body)) if response.status == 200

  Oj.load(response.body)
end

.find!(client, jid) ⇒ Object

Locates a theme job status within Zendesk. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::ThemeJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
pp job.status
# => "completed"

Parameters:

  • client (Object)

    An instance of Client

  • jid (String)

    The job status ID to find

Returns:

  • (Object)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



77
78
79
80
81
82
83
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 77

def self.find!(client, jid)
  response = client.connection.get("guide/theming/jobs/#{jid}")
  handle_request_error(1, 'Zendesk', response.status, { action: 'Find theme job status', id: jid }) unless response.status == 200
  status = ThemeJobStatuses.new(Oj.load(response.body)['job'])
  status.id = jid if status.id.nil?
  status
end

.wait_for_completetion(client, job, interval = 5, verbose = true) ⇒ Object

Waits for a job to complete. Be mindful of API limits when setting the wait interval

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::ThemeJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
completed_job = Readiness::Zendesk::ThemeJobStatuses.wait_for_completetion(client, job, 10, true)
# => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
# => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is queued
# => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
# => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is working
# => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
# => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is completed
# => Job is finished with status of completed
pp completed_job.status
# => "completed"
require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
job = Readiness::Zendesk::ThemeJobStatuses.find!(client, '8b726e606741012ffc2d782bcb7848fe')
completed_job = Readiness::Zendesk::ThemeJobStatuses.wait_for_completetion(client, job, 5, false)
pp completed_job.status
# => "completed"

Parameters:

  • client (Object)

    An instance of Client

  • job (Object)
  • interval (Integer) (defaults to: 5)

    The time (in seconds) between checks

  • verbose (Boolean) (defaults to: true)

    Whether or not to output messages

Returns:

Author:

  • Jason Colyer

Since:

  • 1.0.12



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/support_readiness/zendesk/theme_job_statuses.rb', line 124

def self.wait_for_completetion(client, job, interval = 5, verbose = true)
  loop do
    puts "Waiting #{interval} seconds before checking #{job.id}" if verbose
    sleep interval
    print "Rechecking status of #{job.id}..." if verbose
    job = ThemeJobStatuses.find!(client, job.id)
    puts "status is #{job.status}" if verbose
    break if %w[failed completed].include? job.status
  end
  puts "Job is finished with status of #{job.status}" if verbose
  job
end