Class: Readiness::Zendesk::Articles
- Inherits:
-
Client
- Object
- Client
- Readiness::Zendesk::Articles
show all
- Defined in:
- lib/support_readiness/zendesk/articles.rb
Overview
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
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_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def author_id
@author_id
end
|
#body ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def body
@body
end
|
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def
@comments_disabled
end
|
#draft ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def draft
@draft
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def id
@id
end
|
#label_names ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def label_names
@label_names
end
|
#locale ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def locale
@locale
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def name
@name
end
|
#permission_group_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def permission_group_id
@permission_group_id
end
|
#position ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def position
@position
end
|
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def promoted
@promoted
end
|
#section_id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def section_id
@section_id
end
|
#title ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/articles.rb', line 13
def title
@title
end
|
#user_segment_id ⇒ Object
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
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
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)
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
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
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
179
180
181
182
183
|
# File 'lib/support_readiness/zendesk/articles.rb', line 179
def self.update!(client, article)
update_article_metadata!(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
206
207
208
209
210
|
# File 'lib/support_readiness/zendesk/articles.rb', line 206
def self.update_article_metadata!(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
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
|