Add app ratings retrieval for Apple apps

Introduces a new method getAppRatings in AppStoreScraper to fetch app ratings. Updates CheckAppScoreCommand to display ratings instead of reviews, and refactors AppleAppRequest for improved parameter handling.
This commit is contained in:
2025-11-06 23:50:13 +07:00
parent 3ea1e824fd
commit 25c5d6d191
3 changed files with 27 additions and 6 deletions
@@ -84,4 +84,13 @@ public class AppStoreScraper {
}
return response.reviews();
}
public static long getAppRatings(String appId) {
var response = getResponse(appId);
if (response == null) {
log.error("response is null");
return 0L;
}
return response.ratings();
}
}
@@ -1,11 +1,23 @@
package com.miti99.storescraperbot.api.apple.request;
public record AppleAppRequest(String appId, Long id, Boolean ratings) {
public record AppleAppRequest(
Long id,
String appId,
// String country, // Tạm thời chưa cần phân biệt
Boolean ratings) {
public AppleAppRequest(String appId) {
this(appId, null, true);
this(
null,
appId,
// "vn",
true);
}
public AppleAppRequest(Long id) {
this(null, id, true);
this(
id,
null,
// "vn",
true);
}
}
@@ -37,14 +37,14 @@ public class CheckAppScoreCommand extends BaseStoreScraperBotCommand {
var sb = new StringBuilder();
sb.append("<b>Apple Apps:</b>\n");
sb.append("<code>\n");
sb.append("%-20s | %-10s | %-10s\n".formatted("AppId", "Score", "Reviews"));
sb.append("%-20s | %-10s | %-10s\n".formatted("AppId", "Score", "Ratings"));
sb.append("-".repeat(43));
sb.append("\n");
for (var app : group.getAppleApps()) {
var appId = app.appId();
double score = AppStoreScraper.getAppScore(appId);
long reviews = AppStoreScraper.getAppReviews(appId);
sb.append("%-20s | %-10s | %-10s\n".formatted(appId, score, reviews));
long ratings = AppStoreScraper.getAppRatings(appId);
sb.append("%-20s | %-10s | %-10s\n".formatted(appId, score, ratings));
}
sb.append("</code>\n");
sb.append("\n");