guidepost 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/guidepost/provider/zendesk.rb +136 -41
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd66962286cce8f0f618a5778d333434e9606427f00921b3be6b68775adb52de
|
4
|
+
data.tar.gz: 998473908c96ed016f5dff6fe20d660b47ed212fcfc7f51ad3ee1a92a9374829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c55c394e4202705ed8c791d0d259c231c5e66f7ac32ca4a6d2c39f270ee39ce405cf0b97738733ed888754c783334e49bd9dea6105016825b3c0e56b3512b2a8
|
7
|
+
data.tar.gz: f3264e4bf8c58b020a6891273986a377252501293c25048d7bf6432035281231723b47e8325f81d81b428bec01fdd0f55d2f81ccf44e1e7b057979c47f77af0a
|
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
|
@@ -22,6 +22,7 @@ module Guidepost
|
|
22
22
|
return [] if query.empty?
|
23
23
|
|
24
24
|
url = "#{self.base_api_url}/help_center/articles/search.json?query=#{query}&per_page=10"
|
25
|
+
url += "&locale=#{options[:locale]}" if !options[:locale].nil? && !options[:locale].empty?
|
25
26
|
uri = URI.parse(url)
|
26
27
|
|
27
28
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -52,7 +53,8 @@ module Guidepost
|
|
52
53
|
def backup_all_articles(options={})
|
53
54
|
# Get all articles (with pagination)
|
54
55
|
sideload = options[:sideload] || false
|
55
|
-
|
56
|
+
all_locales = options[:all_locales] || true
|
57
|
+
articles = self.retrieve_all_articles(sideload: sideload, all_locales: all_locales)
|
56
58
|
|
57
59
|
# Upload to S3
|
58
60
|
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
@@ -66,19 +68,30 @@ module Guidepost
|
|
66
68
|
|
67
69
|
def retrieve_all_articles(options={})
|
68
70
|
sideload = options[:sideload] || false
|
71
|
+
all_locales = options[:all_locales] || true
|
72
|
+
|
69
73
|
page_next = nil
|
70
74
|
articles = []
|
71
75
|
article_attachments = nil
|
72
76
|
|
77
|
+
locales = (self.retrieve_all_locales || []).map{|locale_json| locale_json['locale'] } if all_locales
|
78
|
+
locales = [''] if locales.nil? || locales.empty?
|
79
|
+
|
73
80
|
if !sideload
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
81
|
+
article_attachments = []
|
82
|
+
locales.each do |locale|
|
83
|
+
page_next = nil
|
84
|
+
locale_articles = []
|
85
|
+
while true
|
86
|
+
page_articles, page_next = self.retrieve_articles(url: page_next, locale: locale)
|
87
|
+
break if page_articles.nil? || page_articles.empty?
|
88
|
+
locale_articles += page_articles
|
89
|
+
break if page_next.nil?
|
90
|
+
end
|
91
|
+
articles += locale_articles
|
80
92
|
|
81
|
-
|
93
|
+
article_attachments += self.retrieve_all_article_attachments(articles: locale_articles, locale: locale)
|
94
|
+
end
|
82
95
|
|
83
96
|
return {
|
84
97
|
articles: articles,
|
@@ -89,50 +102,57 @@ module Guidepost
|
|
89
102
|
else
|
90
103
|
sections = []
|
91
104
|
categories = []
|
105
|
+
article_attachments = []
|
92
106
|
|
93
107
|
section_urls = Hash.new
|
94
108
|
category_urls = Hash.new
|
95
109
|
|
96
|
-
|
97
|
-
|
110
|
+
locales.each do |locale|
|
111
|
+
page_next = nil
|
112
|
+
locales_articles = []
|
98
113
|
|
99
|
-
|
100
|
-
|
101
|
-
categories_from_page = page["categories"]
|
114
|
+
while true
|
115
|
+
page, page_next = self.retrieve_articles(url: page_next, sideload: true, locale: locale)
|
102
116
|
|
103
|
-
|
104
|
-
|
105
|
-
|
117
|
+
articles_from_page = page["articles"]
|
118
|
+
sections_from_page = page["sections"]
|
119
|
+
categories_from_page = page["categories"]
|
106
120
|
|
107
|
-
|
121
|
+
no_more_articles = articles_from_page.nil? || articles_from_page.empty?
|
122
|
+
no_more_sections = sections_from_page.nil? || sections_from_page.empty?
|
123
|
+
no_more_categories = categories_from_page.nil? || categories_from_page.empty?
|
108
124
|
|
109
|
-
|
125
|
+
break if no_more_articles && no_more_sections && no_more_categories
|
110
126
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
127
|
+
locales_articles += articles_from_page
|
128
|
+
|
129
|
+
sections_from_page.each do |s|
|
130
|
+
url = s["url"]
|
131
|
+
if !section_urls.has_key?(url)
|
132
|
+
section_urls[url] = 1
|
133
|
+
else
|
134
|
+
section_urls[url] += 1
|
135
|
+
end
|
136
|
+
sections << s if section_urls[url] == 1
|
117
137
|
end
|
118
|
-
sections << s if section_urls[url] == 1
|
119
|
-
end
|
120
138
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
139
|
+
categories_from_page.each do |c|
|
140
|
+
url = c["url"]
|
141
|
+
if !category_urls.has_key?(url)
|
142
|
+
category_urls[url] = 1
|
143
|
+
else
|
144
|
+
category_urls[url] += 1
|
145
|
+
end
|
146
|
+
categories << c if category_urls[url] == 1
|
127
147
|
end
|
128
|
-
categories << c if category_urls[url] == 1
|
129
|
-
end
|
130
148
|
|
131
|
-
|
149
|
+
break if page_next.nil?
|
150
|
+
end
|
151
|
+
articles += locales_articles
|
152
|
+
|
153
|
+
article_attachments += self.retrieve_all_article_attachments(articles: locales_articles, locale: locale)
|
132
154
|
end
|
133
155
|
|
134
|
-
article_attachments = self.retrieve_all_article_attachments(articles: articles)
|
135
|
-
|
136
156
|
return {
|
137
157
|
categories: categories,
|
138
158
|
category_count: categories.count,
|
@@ -148,12 +168,13 @@ module Guidepost
|
|
148
168
|
|
149
169
|
def retrieve_articles(options={})
|
150
170
|
url = options[:url]
|
171
|
+
locale = (options[:locale] || "").downcase
|
151
172
|
sideload = options[:sideload] || false
|
152
173
|
|
153
174
|
if !sideload
|
154
|
-
url = "#{self.base_api_url}/help_center/articles.json?per_page=25&page=1" if url.nil?
|
175
|
+
url = "#{self.base_api_url}/help_center/#{locale}/articles.json?per_page=25&page=1" if url.nil?
|
155
176
|
else
|
156
|
-
url = "#{self.base_api_url}/help_center/articles.json?include=sections,categories&per_page=25&page=1" if url.nil?
|
177
|
+
url = "#{self.base_api_url}/help_center/#{locale}/articles.json?include=sections,categories&per_page=25&page=1" if url.nil?
|
157
178
|
end
|
158
179
|
|
159
180
|
uri = URI.parse(url)
|
@@ -252,7 +273,7 @@ module Guidepost
|
|
252
273
|
articles = options[:articles]
|
253
274
|
articles.each do |article|
|
254
275
|
while true
|
255
|
-
attachments, next_page = self.retrieve_article_attachments(for_article: article)
|
276
|
+
attachments, next_page = self.retrieve_article_attachments(for_article: article, url: next_page, locale: options[:locale])
|
256
277
|
break if attachments.nil? || attachments.empty?
|
257
278
|
article_attachments += attachments
|
258
279
|
break if next_page.nil?
|
@@ -263,9 +284,11 @@ module Guidepost
|
|
263
284
|
end
|
264
285
|
|
265
286
|
def retrieve_article_attachments(options={})
|
287
|
+
url = options[:url]
|
266
288
|
article = options[:for_article]
|
289
|
+
locale = (options[:locale] || "").downcase
|
267
290
|
|
268
|
-
url = "#{self.base_api_url}/help_center/articles/#{article["id"]}/attachments.json?per_page=25&page=1" if url.nil?
|
291
|
+
url = "#{self.base_api_url}/help_center/#{locale}/articles/#{article["id"]}/attachments.json?per_page=25&page=1" if url.nil?
|
269
292
|
uri = URI.parse(url)
|
270
293
|
|
271
294
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -283,6 +306,78 @@ module Guidepost
|
|
283
306
|
return j_body["article_attachments"], j_body["next_page"]
|
284
307
|
end
|
285
308
|
|
309
|
+
def retrieve_all_locales(options={})
|
310
|
+
locales = []
|
311
|
+
next_page = nil
|
312
|
+
|
313
|
+
while true
|
314
|
+
tmp_locales, next_page = self.retrieve_locales(url: next_page)
|
315
|
+
break if tmp_locales.nil? || tmp_locales.empty?
|
316
|
+
locales += tmp_locales
|
317
|
+
break if next_page.nil?
|
318
|
+
end
|
319
|
+
|
320
|
+
locales
|
321
|
+
end
|
322
|
+
|
323
|
+
def retrieve_locales(options={})
|
324
|
+
url = options[:url]
|
325
|
+
|
326
|
+
url = "#{self.base_api_url}/locales.json" if url.nil?
|
327
|
+
uri = URI.parse(url)
|
328
|
+
|
329
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
330
|
+
http.use_ssl = true
|
331
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
332
|
+
|
333
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
334
|
+
request.basic_auth(@email, @password)
|
335
|
+
response = http.request(request)
|
336
|
+
|
337
|
+
body = response.body.force_encoding("UTF-8")
|
338
|
+
|
339
|
+
j_body = JSON.parse(body)
|
340
|
+
|
341
|
+
return j_body["locales"], j_body["next_page"]
|
342
|
+
end
|
343
|
+
|
344
|
+
def retrieve_all_translations(options={})
|
345
|
+
translations = []
|
346
|
+
next_page = nil
|
347
|
+
article = options[:for_article]
|
348
|
+
|
349
|
+
while true
|
350
|
+
tmp_translations, next_page = self.retrieve_translations(url: next_page, for_article: article)
|
351
|
+
break if tmp_translations.nil? || tmp_translations.empty?
|
352
|
+
translations += tmp_translations
|
353
|
+
break if next_page.nil?
|
354
|
+
end
|
355
|
+
|
356
|
+
translations
|
357
|
+
end
|
358
|
+
|
359
|
+
def retrieve_translations(options={})
|
360
|
+
url = options[:url]
|
361
|
+
article = options[:for_article]
|
362
|
+
|
363
|
+
url = "#{self.base_api_url}/help_center/articles/#{article['id']}/translations.json" if url.nil?
|
364
|
+
uri = URI.parse(url)
|
365
|
+
|
366
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
367
|
+
http.use_ssl = true
|
368
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
369
|
+
|
370
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
371
|
+
request.basic_auth(@email, @password)
|
372
|
+
response = http.request(request)
|
373
|
+
|
374
|
+
body = response.body.force_encoding("UTF-8")
|
375
|
+
|
376
|
+
j_body = JSON.parse(body)
|
377
|
+
|
378
|
+
return j_body["translations"], j_body["next_page"]
|
379
|
+
end
|
380
|
+
|
286
381
|
def base_api_url
|
287
382
|
"https://#{self.subdomain}.zendesk.com/api/v2"
|
288
383
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guidepost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kiren Srinivasan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|