/**
* Parser for app ratings data
*/
/**
* Extracts ratings histogram from app data
* @param {Object} appData - Parsed app data
* @returns {Object}
*/
export function parseRatings(appData) {
if (!appData || !appData.rating) {
return {
ratings: 0,
histogram: {
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0,
},
};
}
// iTunes API doesn't provide histogram directly
// We can only return the average and count
// For histogram, we'd need to scrape the web page, which is more complex
// For now, return what we have
return {
ratings: appData.rating.count || 0,
average: appData.rating.average || null,
histogram: {
'1': 0, // Not available from API
'2': 0,
'3': 0,
'4': 0,
'5': 0,
},
};
}
/**
* Attempts to extract ratings histogram from HTML (if needed in future)
* This is a placeholder for potential web scraping enhancement
*/
export function parseRatingsFromHTML(html) {
// This would require HTML parsing
// For now, return empty histogram
return {
ratings: 0,
histogram: {
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0,
},
};
}