Class: Readiness::Zendesk::Articles

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

Overview

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

Author:

  • Jason Colyer

Since:

  • 1.0.0

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

Creates a new Readiness::Zendesk::Articles instance

Examples:

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

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.0



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/support_readiness/zendesk/articles.rb', line 24

def initialize(object = {})
  @author_id = object['author_id']
  @body = object['body']
  @comments_disabled = object['comments_disabled']
  @draft = object['draft']
  @id = object['id']
  @label_names = object['label_names']
  @locale = object['locale']
  @name = object['name']
  @permission_group_id = object['permission_group_id']
  @position = object['position']
  @promoted = object['promoted']
  @section_id = object['section_id']
  @title = object['title']
  @user_segment_id = object['user_segment_id']
end

Instance Attribute Details

#author_idObject

Since:

  • 1.0.0



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

def author_id
  @author_id
end

#bodyObject

Since:

  • 1.0.0



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

def body
  @body
end

#comments_disabledObject

Since:

  • 1.0.0



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

def comments_disabled
  @comments_disabled
end

#draftObject

Since:

  • 1.0.0



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

def draft
  @draft
end

#idObject

Since:

  • 1.0.0



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

def id
  @id
end

#label_namesObject

Since:

  • 1.0.0



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

def label_names
  @label_names
end

#localeObject

Since:

  • 1.0.0



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

def locale
  @locale
end

#nameObject

Since:

  • 1.0.0



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

def name
  @name
end

#permission_group_idObject

Since:

  • 1.0.0



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

def permission_group_id
  @permission_group_id
end

#positionObject

Since:

  • 1.0.0



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

def position
  @position
end

Since:

  • 1.0.0



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

def promoted
  @promoted
end

#section_idObject

Since:

  • 1.0.0



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

def section_id
  @section_id
end

#titleObject

Since:

  • 1.0.0



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

def title
  @title
end

#user_segment_idObject

Since:

  • 1.0.0



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

def user_segment_id
  @user_segment_id
end

Class Method Details

.archive!(client, article) ⇒ Boolean

Archives an article. Will exit if unsuccessful

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)
article = Readiness::Zendesk::Articles.find!(client, 35468)
archive = Readiness::Zendesk::Articles.archive!(client, article)
pp archive
# => true

Parameters:

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



259
260
261
262
263
# File 'lib/support_readiness/zendesk/articles.rb', line 259

def self.archive!(client, article)
  response = client.connection.delete "help_center/articles/#{article.id}"
  handle_request_error(1, 'Zendesk', response.status, { action: 'Archive article', id: article.id, message: Oj.load(response.body)}) unless response.status == 204
  true
end

.create!(client, article) ⇒ Object

Creates an article. Will exit if unsuccessful

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)
article = Readiness::Zendesk::Articles.new
article.title = 'Taking photos in low light'
article.body = 'Use a tripod'
article.section_id = 123
article.locale = 'en-us'
article.user_segment_id = nil
article.permission_group_id = 12528735509276
create = Readiness::Zendesk::Articles.create!(client, article)
pp create.id
# => 35468

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



152
153
154
155
156
# File 'lib/support_readiness/zendesk/articles.rb', line 152

def self.create!(client, article)
  response = client.connection.post "help_center/sections/#{article.section_id}/articles", to_nearly_clean_json_with_key(article, 'article', ['user_segment_id'])
  handle_request_error(1, 'Zendesk', response.status, { action: 'Create article', message: Oj.load(response.body)}) unless response.status == 201
  Articles.new(Oj.load(response.body)['article'])
end

.find(client, aid) ⇒ Hash

Locates an article 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)
article = Readiness::Zendesk::Articles.find(client, 35467)
pp article.title
# => "Article title"

Parameters:

  • client (Object)

    An instance of Client

  • aid (Integer)

    The article ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



93
94
95
96
97
98
99
# File 'lib/support_readiness/zendesk/articles.rb', line 93

def self.find(client, aid)
  response = client.connection.get("help_center/articles/#{aid}")
  handle_request_error(0, 'Zendesk', response.status,  { action: 'get', id: aid }) unless response.status == 200
  return Articles.new(Oj.load(response.body)['article']) if response.status == 200

  Oj.load(response.body)
end

.find!(client, aid) ⇒ Object

Locates an article 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)
article = Readiness::Zendesk::Articles.find!(client, 35467)
pp article.title
# => "Article title"

Parameters:

  • client (Object)

    An instance of Client

  • aid (Integer)

    The article ID to find

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



120
121
122
123
124
# File 'lib/support_readiness/zendesk/articles.rb', line 120

def self.find!(client, aid)
  response = client.connection.get("help_center/articles/#{aid}")
  handle_request_error(1, 'Zendesk', response.status, { action: 'Find article', id: aid }) unless response.status == 200
  Articles.new(Oj.load(response.body)['article'])
end

.list(client) ⇒ Array

Lists articles

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)
articles = Readiness::Zendesk::Articles.list(client)
pp articles.first.id
# => 35467

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/support_readiness/zendesk/articles.rb', line 59

def self.list(client)
  array = []
  opts = "page[size]=100"
  loop do
    response = client.connection.get("help_center/articles?#{opts}")
    handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body['articles'].map { |a| Articles.new(a) }
    break unless body['meta']['has_more']

    opts = body['links'] ['next'].split('?').last
  end
  array
end

.update!(client, article) ⇒ Object

Updates an article (both metadata and translation). Will exit if unsuccessful

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)
article = Readiness::Zendesk::Articles.find!(client, 35468)
artricle.body = 'Use a tripod and low light approved camera'
update = Readiness::Zendesk::Articles.update!(client, article)
pp update.body
# => "Use a tripod and low light approved camera"

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



179
180
181
182
183
# File 'lib/support_readiness/zendesk/articles.rb', line 179

def self.update!(client, article)
  (client, article)
  update_article_translation!(client, article)
  Articles.find!(client, article.id)
end

.update_article_metadata!(client, article) ⇒ Object

Updates an article’s metadata. Will exit if unsuccessful

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)
article = Readiness::Zendesk::Articles.find!(client, 35468)
artricle.promoted = true
update = Readiness::Zendesk::Articles.(client, article)
pp update.promoted
# => true

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.10



206
207
208
209
210
# File 'lib/support_readiness/zendesk/articles.rb', line 206

def self.(client, article)
  response = client.connection.put "help_center/articles/#{article.id}", to_nearly_clean_json_with_key(article, 'article', ['user_segment_id'])
  handle_request_error(1, 'Zendesk', response.status, { action: 'Update article metadata', id: article.id, message: Oj.load(response.body)}) unless response.status == 200
  Articles.new(Oj.load(response.body)['article'])
end

.update_article_translation!(client, article) ⇒ Object

Updates an article’s translation. Will exit if unsuccessful

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)
article = Readiness::Zendesk::Articles.find!(client, 35468)
artricle.body = 'Contact support'
update = Readiness::Zendesk::Articles.update_article_translation!(client, article)
pp update.body
# => "Contact support"

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.10



233
234
235
236
237
# File 'lib/support_readiness/zendesk/articles.rb', line 233

def self.update_article_translation!(client, article)
  response = client.connection.put "help_center/articles/#{article.id}/translations/#{article.locale}", to_nearly_clean_json_with_key(article, 'translation', ['user_segment_id'])
  handle_request_error(1, 'Zendesk', response.status, { action: 'Update article translation', id: article.id, message: Oj.load(response.body)}) unless response.status == 200
  Oj.load(response.body)['translation']
end