Skip to content

Commit 44feb32

Browse files
committed
DOC-204 PAPI sources :)
1 parent d2d02bc commit 44feb32

File tree

3 files changed

+92
-346
lines changed

3 files changed

+92
-346
lines changed

scripts/papi.js

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ const updateSources = async () => {
250250
let sources = []
251251
let sourcesUpdated = []
252252
let nextPageToken = "MA=="
253+
let categories = new Set()
254+
let sourceCategories = []
253255

254256
while (nextPageToken !== null) {
255257
const res = await getCatalog(`${PAPI_URL}/catalog/sources/`, nextPageToken)
@@ -263,15 +265,33 @@ const updateSources = async () => {
263265
return 0;
264266
})
265267

268+
const libraryCategories = [
269+
'server',
270+
'mobile',
271+
'ott',
272+
'roku',
273+
'website'
274+
]
275+
266276
sources.forEach(source => {
267277
let slug = slugify(source.name)
268278
let settings = source.options
279+
let mainCategory = source.categories[0] ? source.categories[0].toLowerCase : ''
280+
269281
settings.sort((a, b) => {
270282
if(a.name < b.name) { return -1; }
271283
if(a.name > b.name) { return 1; }
272284
return 0;
273285
})
274286

287+
288+
if (libraryCategories.includes(mainCategory)) {
289+
url = `connections/sources/catalog/libraries/${mainCategory}/${slug}`
290+
} else {
291+
url = `connections/sources/catalog/cloud-apps/${slug}`
292+
}
293+
294+
275295
let updatedSource = {
276296
display_name: source.name,
277297
slug,
@@ -281,20 +301,40 @@ const updateSources = async () => {
281301
},
282302
// mark: {
283303
// url: source.logos.mark
284-
// }
304+
// },
305+
categories: source.categories,
285306
}
286307
sourcesUpdated.push(updatedSource)
287308
doesCatalogItemExist(updatedSource)
309+
source.categories.reduce((s, e) => s.add(e), categories);
288310

289311

290-
const options = { noArrayIndent: true };
291-
output = "# AUTOGENERATED FROM PUBLIC API. DO NOT EDIT\n"
292-
var todayDate = new Date().toISOString().slice(0,10);
293-
output += "# source data last updated " + todayDate + " \n";
294-
output += yaml.safeDump({ items: sourcesUpdated }, options);
295-
fs.writeFileSync(path.resolve(__dirname, `../src/_data/catalog/sources_papi.yml`), output);
296312
})
297313

314+
const sourceArray = Array.from(categories)
315+
sourceArray.forEach(category => {
316+
sourceCategories.push({
317+
display_name: category,
318+
slug: slugify(category)
319+
})
320+
})
321+
322+
323+
// Create source catalog yaml file
324+
const options = { noArrayIndent: false };
325+
var todayDate = new Date().toISOString().slice(0,10);
326+
output = "# AUTOGENERATED FROM PLATFORM API. DO NOT EDIT\n"
327+
output += "# sources last updated " + todayDate + " \n";
328+
output += yaml.safeDump({ items: sourcesUpdated }, options);
329+
fs.writeFileSync(path.resolve(__dirname, `../src/_data/catalog/sources.yml`), output);
330+
331+
// Create source-category mapping yaml file
332+
var todayDate = new Date().toISOString().slice(0,10);
333+
output = "# AUTOGENERATED FROM PLATFORM API. DO NOT EDIT\n"
334+
output += "# source cateogries last updated " + todayDate + " \n";
335+
output += yaml.safeDump({ items: sourceCategories }, options);
336+
fs.writeFileSync(path.resolve(__dirname, `../src/_data/catalog/source_categories.yml`), output);
337+
298338

299339

300340
}
@@ -455,6 +495,6 @@ const updateWarehouses = async () => {
455495

456496
}
457497

458-
updateDestinations()
459-
//updateSources()
460-
updateWarehouses()
498+
// updateDestinations()
499+
updateSources()
500+
// updateWarehouses()

src/_data/catalog/source_categories.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# AUTOGENERATED FROM PLATFORM API. DO NOT EDIT
2-
# source cateogries last updated 2021-06-08
2+
# source cateogries last updated 2021-06-11
33
items:
44
- display_name: Server
55
slug: server
6+
- display_name: Mobile
7+
slug: mobile
68
- display_name: Email Marketing
79
slug: email-marketing
810
- display_name: CRM
@@ -19,8 +21,6 @@ items:
1921
slug: custom
2022
- display_name: Analytics
2123
slug: analytics
22-
- display_name: Mobile
23-
slug: mobile
2424
- display_name: Surveys
2525
slug: surveys
2626
- display_name: Personalization

0 commit comments

Comments
 (0)