Skip to content

Commit

Permalink
Add genres / categories list to App details result (#622)
Browse files Browse the repository at this point in the history
* feat: app categories mappings;

* docs: categories in the example;

* refactor: moved some extractCategories logic from Helpers to app MAPPINGS;

* familyGenre fields removed from app details;

* IAppItem ts declaration for app.categories field;

* refactor: removed unnecessary now unique check;

* refactor: extractCategories mappingHelpers;
  • Loading branch information
alexoleynik0 authored Aug 1, 2023
1 parent 705b9ee commit 4e49a6a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ Results:
developerInternalID: '5700313618786177705',
genre: 'Tools',
genreId: 'TOOLS',
familyGenre: undefined,
familyGenreId: undefined,
categories: [
{ name: 'Tools', id: 'TOOLS' },
{ name: 'Another category without id', id: null }
],
icon: 'https://lh3.googleusercontent.com/ZrNeuKthBirZN7rrXPN1JmUbaG8ICy3kZSHt-WgSnREsJzo2txzCzjIoChlevMIQEA',
headerImage: 'https://lh3.googleusercontent.com/e4Sfy0cOmqpike76V6N6n-tDVbtbmt6MxbnbkKBZ_7hPHZRfsCeZhMBZK8eFDoDa1Vf-',
screenshots: [
Expand Down
6 changes: 4 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ export interface IAppItemFullDetail extends IAppItem {
developerAddress: string
genre: string
genreId: string
familyGenre: string
familyGenreId: string
categories: Array<{
name: string
id: string|null
}>
icon: string
headerImage: string
screenshots: string[]
Expand Down
16 changes: 14 additions & 2 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,20 @@ const MAPPINGS = {
},
genre: ['ds:5', 1, 2, 79, 0, 0, 0],
genreId: ['ds:5', 1, 2, 79, 0, 0, 2],
familyGenre: ['ds:5', 0, 12, 13, 1, 0],
familyGenreId: ['ds:5', 0, 12, 13, 1, 2],
categories: {
path: ['ds:5', 1, 2],
fun: (searchArray) => {
const categories = helper.extractCategories(R.path([118], searchArray));
if (categories.length === 0) {
// add genre and genreId like GP does when there're no categories available
categories.push({
name: R.path([79, 0, 0, 0], searchArray),
id: R.path([79, 0, 0, 2], searchArray)
});
}
return categories;
}
},
icon: ['ds:5', 1, 2, 95, 0, 3, 2],
headerImage: ['ds:5', 1, 2, 96, 0, 3, 2],
screenshots: {
Expand Down
24 changes: 23 additions & 1 deletion lib/utils/mappingHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,34 @@ function extractFeatures (featuresArray) {
}));
}

/**
* Recursively extracts the categories of the App
* @param {array} categories The categories array
*/
function extractCategories (searchArray, categories = []) {
if (searchArray === null || searchArray.length === 0) return categories;

if (searchArray.length >= 4 && typeof searchArray[0] === 'string') {
categories.push({
name: searchArray[0],
id: searchArray[2]
});
} else {
searchArray.forEach((sub) => {
extractCategories(sub, categories);
});
}

return categories;
}

module.exports = {
descriptionHtmlLocalized,
descriptionText,
priceText,
normalizeAndroidVersion,
buildHistogram,
extractComments,
extractFeatures
extractFeatures,
extractCategories
};
8 changes: 6 additions & 2 deletions test/lib.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const validateAppDetails = (app) => {
assert.isString(app.descriptionHTML);
assert.isString(app.released);
assert.equal(app.genreId, 'GAME_PUZZLE');
assert.equal(app.familyGenre, undefined);
assert.equal(app.familyGenreId, undefined);

assert.isArray(app.categories);
assert.isAbove(app.categories.length, 1);
assert.equal(app.categories[0].id, 'GAME_PUZZLE');
assert.notEqual(app.categories[1].id, 'GAME_PUZZLE');
assert.hasAllKeys(app.categories[0], ['name', 'id']);

assert.isString(app.version);
if (app.size) {
Expand Down

0 comments on commit 4e49a6a

Please sign in to comment.