guidepost 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/generators/guidepost/templates/zendesk_guide_article_attachment.rb +1 -1
- data/lib/guidepost.rb +2 -2
- data/lib/guidepost/provider/zendesk.rb +141 -44
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f751016d58b199dc4f795e66092ef5b541a4a26e58d2620e1828013796a4e8b
|
|
4
|
+
data.tar.gz: d0362d142673a44382cede84737194c4ee0c68d6f89054794fee6a6ce83c4af5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dddd913919db07e788a0dc969df5eefa0cf2e36c91c9c163b1dece16285c9b3a81c126382852cd59db94adeb67ac0d8f700a42b21e518995fd2cda5c56172f66
|
|
7
|
+
data.tar.gz: 276fc86844018b06092130749d0fb7936e348b79573c7b56414130a3473b974c4e6324153042ddf730e57b75be485b8c5e724ef769c6f8b6014e0ee22bde567e
|
data/README.md
CHANGED
|
@@ -60,7 +60,7 @@ Make sure to have certain environmental variables set, preferrably in your `.bas
|
|
|
60
60
|
ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_ZENDESK_EMAIL"]
|
|
61
61
|
|
|
62
62
|
# The password token associated with your Zendesk subdomain
|
|
63
|
-
ENV["#{YOUR_PROJECT_NAME}
|
|
63
|
+
ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_ZENDESK_PASSWORD_TOKEN"]
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
#### S3
|
|
@@ -37,7 +37,7 @@ class ZendeskGuideArticleAttachment < ActiveRecord::Base
|
|
|
37
37
|
article_objects.each do |a|
|
|
38
38
|
is_correct_article = (article_attachment.article_id == a.article_id)
|
|
39
39
|
if is_correct_article
|
|
40
|
-
article_attachment.zendesk_guide_article =
|
|
40
|
+
article_attachment.zendesk_guide_article = a
|
|
41
41
|
article_attachment.save
|
|
42
42
|
break
|
|
43
43
|
end
|
data/lib/guidepost.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module Guidepost
|
|
2
2
|
module Provider
|
|
3
3
|
class Zendesk
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
4
6
|
attr_reader :subdomain
|
|
5
7
|
attr_reader :project_name
|
|
6
8
|
|
|
@@ -21,7 +23,8 @@ module Guidepost
|
|
|
21
23
|
query = options.fetch(:query, "")
|
|
22
24
|
return [] if query.empty?
|
|
23
25
|
|
|
24
|
-
url = "#{self.base_api_url}/help_center/articles/search.json?query=#{query}&per_page=10"
|
|
26
|
+
url = "#{self.base_api_url}/help_center/articles/search.json?query=#{URI::encode(query)}&per_page=10"
|
|
27
|
+
url += "&locale=#{options[:locale]}" if !options[:locale].nil? && !options[:locale].empty?
|
|
25
28
|
uri = URI.parse(url)
|
|
26
29
|
|
|
27
30
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
@@ -52,33 +55,45 @@ module Guidepost
|
|
|
52
55
|
def backup_all_articles(options={})
|
|
53
56
|
# Get all articles (with pagination)
|
|
54
57
|
sideload = options[:sideload] || false
|
|
55
|
-
|
|
58
|
+
all_locales = options[:all_locales] || true
|
|
59
|
+
articles = self.retrieve_all_articles(sideload: sideload, all_locales: all_locales)
|
|
56
60
|
|
|
57
61
|
# Upload to S3
|
|
58
62
|
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
|
59
63
|
|
|
60
64
|
filename = "#{timestamp}"
|
|
61
65
|
filename += "_with_sideload" if sideload
|
|
62
|
-
@storage.upload_file(path: "zendesk/article_backups/#{filename}.json", string_content: articles.to_json)
|
|
66
|
+
@storage.upload_file(path: "zendesk/#{@subdomain}/article_backups/#{filename}.json", string_content: articles.to_json)
|
|
63
67
|
|
|
64
68
|
articles.count
|
|
65
69
|
end
|
|
66
70
|
|
|
67
71
|
def retrieve_all_articles(options={})
|
|
68
72
|
sideload = options[:sideload] || false
|
|
73
|
+
all_locales = options[:all_locales] || true
|
|
74
|
+
|
|
69
75
|
page_next = nil
|
|
70
76
|
articles = []
|
|
71
77
|
article_attachments = nil
|
|
72
78
|
|
|
79
|
+
locales = (self.retrieve_all_locales || []).map{|locale_json| locale_json['locale'] } if all_locales
|
|
80
|
+
locales = [''] if locales.nil? || locales.empty?
|
|
81
|
+
|
|
73
82
|
if !sideload
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
article_attachments = []
|
|
84
|
+
locales.each do |locale|
|
|
85
|
+
page_next = nil
|
|
86
|
+
locale_articles = []
|
|
87
|
+
while true
|
|
88
|
+
page_articles, page_next = self.retrieve_articles(url: page_next, locale: locale)
|
|
89
|
+
break if page_articles.nil? || page_articles.empty?
|
|
90
|
+
locale_articles += page_articles
|
|
91
|
+
break if page_next.nil?
|
|
92
|
+
end
|
|
93
|
+
articles += locale_articles
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
article_attachments += self.retrieve_all_article_attachments(articles: locale_articles, locale: locale)
|
|
96
|
+
end
|
|
82
97
|
|
|
83
98
|
return {
|
|
84
99
|
articles: articles,
|
|
@@ -89,50 +104,57 @@ module Guidepost
|
|
|
89
104
|
else
|
|
90
105
|
sections = []
|
|
91
106
|
categories = []
|
|
107
|
+
article_attachments = []
|
|
92
108
|
|
|
93
109
|
section_urls = Hash.new
|
|
94
110
|
category_urls = Hash.new
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
locales.each do |locale|
|
|
113
|
+
page_next = nil
|
|
114
|
+
locales_articles = []
|
|
115
|
+
|
|
116
|
+
while true
|
|
117
|
+
page, page_next = self.retrieve_articles(url: page_next, sideload: true, locale: locale)
|
|
98
118
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
119
|
+
articles_from_page = page["articles"]
|
|
120
|
+
sections_from_page = page["sections"]
|
|
121
|
+
categories_from_page = page["categories"]
|
|
102
122
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
no_more_articles = articles_from_page.nil? || articles_from_page.empty?
|
|
124
|
+
no_more_sections = sections_from_page.nil? || sections_from_page.empty?
|
|
125
|
+
no_more_categories = categories_from_page.nil? || categories_from_page.empty?
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
break if no_more_articles && no_more_sections && no_more_categories
|
|
108
128
|
|
|
109
|
-
|
|
129
|
+
locales_articles += articles_from_page
|
|
110
130
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
sections_from_page.each do |s|
|
|
132
|
+
url = s["url"]
|
|
133
|
+
if !section_urls.has_key?(url)
|
|
134
|
+
section_urls[url] = 1
|
|
135
|
+
else
|
|
136
|
+
section_urls[url] += 1
|
|
137
|
+
end
|
|
138
|
+
sections << s if section_urls[url] == 1
|
|
117
139
|
end
|
|
118
|
-
sections << s if section_urls[url] == 1
|
|
119
|
-
end
|
|
120
140
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
categories_from_page.each do |c|
|
|
142
|
+
url = c["url"]
|
|
143
|
+
if !category_urls.has_key?(url)
|
|
144
|
+
category_urls[url] = 1
|
|
145
|
+
else
|
|
146
|
+
category_urls[url] += 1
|
|
147
|
+
end
|
|
148
|
+
categories << c if category_urls[url] == 1
|
|
127
149
|
end
|
|
128
|
-
categories << c if category_urls[url] == 1
|
|
129
|
-
end
|
|
130
150
|
|
|
131
|
-
|
|
151
|
+
break if page_next.nil?
|
|
152
|
+
end
|
|
153
|
+
articles += locales_articles
|
|
154
|
+
|
|
155
|
+
article_attachments += self.retrieve_all_article_attachments(articles: locales_articles, locale: locale)
|
|
132
156
|
end
|
|
133
157
|
|
|
134
|
-
article_attachments = self.retrieve_all_article_attachments(articles: articles)
|
|
135
|
-
|
|
136
158
|
return {
|
|
137
159
|
categories: categories,
|
|
138
160
|
category_count: categories.count,
|
|
@@ -148,12 +170,13 @@ module Guidepost
|
|
|
148
170
|
|
|
149
171
|
def retrieve_articles(options={})
|
|
150
172
|
url = options[:url]
|
|
173
|
+
locale = (options[:locale] || "").downcase
|
|
151
174
|
sideload = options[:sideload] || false
|
|
152
175
|
|
|
153
176
|
if !sideload
|
|
154
|
-
url = "#{self.base_api_url}/help_center/articles.json?per_page=25&page=1" if url.nil?
|
|
177
|
+
url = "#{self.base_api_url}/help_center/#{locale}/articles.json?per_page=25&page=1" if url.nil?
|
|
155
178
|
else
|
|
156
|
-
url = "#{self.base_api_url}/help_center/articles.json?include=sections,categories&per_page=25&page=1" if url.nil?
|
|
179
|
+
url = "#{self.base_api_url}/help_center/#{locale}/articles.json?include=sections,categories&per_page=25&page=1" if url.nil?
|
|
157
180
|
end
|
|
158
181
|
|
|
159
182
|
uri = URI.parse(url)
|
|
@@ -252,7 +275,7 @@ module Guidepost
|
|
|
252
275
|
articles = options[:articles]
|
|
253
276
|
articles.each do |article|
|
|
254
277
|
while true
|
|
255
|
-
attachments, next_page = self.retrieve_article_attachments(for_article: article)
|
|
278
|
+
attachments, next_page = self.retrieve_article_attachments(for_article: article, url: next_page, locale: options[:locale])
|
|
256
279
|
break if attachments.nil? || attachments.empty?
|
|
257
280
|
article_attachments += attachments
|
|
258
281
|
break if next_page.nil?
|
|
@@ -263,9 +286,11 @@ module Guidepost
|
|
|
263
286
|
end
|
|
264
287
|
|
|
265
288
|
def retrieve_article_attachments(options={})
|
|
289
|
+
url = options[:url]
|
|
266
290
|
article = options[:for_article]
|
|
291
|
+
locale = (options[:locale] || "").downcase
|
|
267
292
|
|
|
268
|
-
url = "#{self.base_api_url}/help_center/articles/#{article["id"]}/attachments.json?per_page=25&page=1" if url.nil?
|
|
293
|
+
url = "#{self.base_api_url}/help_center/#{locale}/articles/#{article["id"]}/attachments.json?per_page=25&page=1" if url.nil?
|
|
269
294
|
uri = URI.parse(url)
|
|
270
295
|
|
|
271
296
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
@@ -283,9 +308,81 @@ module Guidepost
|
|
|
283
308
|
return j_body["article_attachments"], j_body["next_page"]
|
|
284
309
|
end
|
|
285
310
|
|
|
311
|
+
def retrieve_all_locales(options={})
|
|
312
|
+
locales = []
|
|
313
|
+
next_page = nil
|
|
314
|
+
|
|
315
|
+
while true
|
|
316
|
+
tmp_locales, next_page = self.retrieve_locales(url: next_page)
|
|
317
|
+
break if tmp_locales.nil? || tmp_locales.empty?
|
|
318
|
+
locales += tmp_locales
|
|
319
|
+
break if next_page.nil?
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
locales
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
def retrieve_locales(options={})
|
|
326
|
+
url = options[:url]
|
|
327
|
+
|
|
328
|
+
url = "#{self.base_api_url}/locales.json" if url.nil?
|
|
329
|
+
uri = URI.parse(url)
|
|
330
|
+
|
|
331
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
332
|
+
http.use_ssl = true
|
|
333
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
334
|
+
|
|
335
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
|
336
|
+
request.basic_auth(@email, @password)
|
|
337
|
+
response = http.request(request)
|
|
338
|
+
|
|
339
|
+
body = response.body.force_encoding("UTF-8")
|
|
340
|
+
|
|
341
|
+
j_body = JSON.parse(body)
|
|
342
|
+
|
|
343
|
+
return j_body["locales"], j_body["next_page"]
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def retrieve_all_translations(options={})
|
|
347
|
+
translations = []
|
|
348
|
+
next_page = nil
|
|
349
|
+
article = options[:for_article]
|
|
350
|
+
|
|
351
|
+
while true
|
|
352
|
+
tmp_translations, next_page = self.retrieve_translations(url: next_page, for_article: article)
|
|
353
|
+
break if tmp_translations.nil? || tmp_translations.empty?
|
|
354
|
+
translations += tmp_translations
|
|
355
|
+
break if next_page.nil?
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
translations
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
def retrieve_translations(options={})
|
|
362
|
+
url = options[:url]
|
|
363
|
+
article = options[:for_article]
|
|
364
|
+
|
|
365
|
+
url = "#{self.base_api_url}/help_center/articles/#{article['id']}/translations.json" if url.nil?
|
|
366
|
+
uri = URI.parse(url)
|
|
367
|
+
|
|
368
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
369
|
+
http.use_ssl = true
|
|
370
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
371
|
+
|
|
372
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
|
373
|
+
request.basic_auth(@email, @password)
|
|
374
|
+
response = http.request(request)
|
|
375
|
+
|
|
376
|
+
body = response.body.force_encoding("UTF-8")
|
|
377
|
+
|
|
378
|
+
j_body = JSON.parse(body)
|
|
379
|
+
|
|
380
|
+
return j_body["translations"], j_body["next_page"]
|
|
381
|
+
end
|
|
382
|
+
|
|
286
383
|
def base_api_url
|
|
287
384
|
"https://#{self.subdomain}.zendesk.com/api/v2"
|
|
288
385
|
end
|
|
289
386
|
end
|
|
290
387
|
end
|
|
291
|
-
end
|
|
388
|
+
end
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: guidepost
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kiren Srinivasan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: aws-sdk
|
|
14
|
+
name: aws-sdk-s3
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '1'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '1'
|
|
27
27
|
description: Harness your knowledge base in your Rails applications
|
|
28
28
|
email: srinitude@gmail.com
|
|
29
29
|
executables: []
|
|
@@ -64,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
64
64
|
- !ruby/object:Gem::Version
|
|
65
65
|
version: '0'
|
|
66
66
|
requirements: []
|
|
67
|
-
|
|
68
|
-
rubygems_version: 2.7.6
|
|
67
|
+
rubygems_version: 3.1.2
|
|
69
68
|
signing_key:
|
|
70
69
|
specification_version: 4
|
|
71
70
|
summary: Harness your knowledge base in your Rails applications
|