Skip to content

Commit

Permalink
Method for getting current user's review of a given app added
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Jul 24, 2018
1 parent 1e71660 commit 41a8112
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/github/yeriomin/playstoreapi/GooglePlayAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class GooglePlayAPI {
private static final String REVIEWS_URL = FDFE_URL + "rev";
private static final String ADD_REVIEW_URL = FDFE_URL + "addReview";
private static final String DELETE_REVIEW_URL = FDFE_URL + "deleteReview";
private static final String USER_REVIEW_URL = FDFE_URL + "userReview";
private static final String ABUSE_URL = FDFE_URL + "flagContent";
private static final String UPLOADDEVICECONFIG_URL = FDFE_URL + "uploadDeviceConfig";
private static final String RECOMMENDATIONS_URL = FDFE_URL + "rec";
Expand Down Expand Up @@ -591,6 +592,26 @@ public ReviewResponse addOrEditReview(String packageName, String comment, String
return addOrEditReview(packageName, comment, title, stars, false);
}

/**
* Returns the review which current user has left for given app
*
* @param packageName
* @param testing
* @return
* @throws IOException
*/
public ReviewResponse getReview(String packageName, boolean testing) throws IOException {
Map<String, String> params = new HashMap<String, String>();
params.put("doc", packageName);
params.put("itpr", testing ? "true" : "false"); // True for beta feedback, false for ordinary reviews
byte[] responseBytes = client.get(USER_REVIEW_URL, params, getDefaultHeaders());
return ResponseWrapper.parseFrom(responseBytes).getPayload().getReviewResponse();
}

public ReviewResponse getReview(String packageName) throws IOException {
return getReview(packageName, false);
}

public ReviewResponse betaFeedback(String packageName, String comment) throws IOException {
return addOrEditReview(packageName, comment, "", 5, true);
}
Expand Down
11 changes: 2 additions & 9 deletions src/main/proto/GooglePlay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1010,25 +1010,18 @@ message Review {
}
message Author {
optional string name = 2;
optional Avatar urls = 5;
optional Image avatar = 5;
}
message Author2 {
optional string personIdString = 1;
optional string personId = 2;
optional int32 unknown1 = 3;
optional int32 unknown2 = 4;
optional string name = 5;
optional Avatar urls = 10;
optional Image avatar = 10;
optional string googlePlusUrl = 19;
optional string googlePlusTagline = 22;
}
message Avatar {
optional int32 unknown1 = 1;
optional string url = 5;
optional string secureUrl = 7;
optional bool unknown2 = 9;
optional bool unknown3 = 22;
}
message ReviewResponse {
optional GetReviewsResponse getResponse = 1;
optional string nextPageUrl = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,29 @@ public void deliveryWithPatchInfo() throws Exception {
Assert.assertEquals("2", request.url().queryParameterValues("pf").get(0));
}

@Test
public void currentReview() throws Exception {
ReviewResponse response = api.getReview("org.mozilla.firefox");

Assert.assertTrue(response.hasGetResponse());
Assert.assertEquals(1, response.getGetResponse().getReviewCount());
Assert.assertEquals(4, response.getGetResponse().getReview(0).getStarRating());
Assert.assertEquals("Good", response.getGetResponse().getReview(0).getComment());
Assert.assertEquals("Yalp Store", response.getGetResponse().getReview(0).getAuthor2().getName());
Assert.assertEquals("https://lh5.googleusercontent.com/-O1xATtrLivM/AAAAAAAAAAI/AAAAAAAAAAA/AAnnY7pEJJJVH9ZwCTIz_Ve-QLleM9qn7A/photo.jpg", response.getGetResponse().getReview(0).getAuthor2().getAvatar().getImageUrl());
Assert.assertEquals("117839429276925272251", response.getGetResponse().getReview(0).getAuthor2().getPersonId());
Assert.assertEquals("person-117839429276925272251", response.getGetResponse().getReview(0).getAuthor2().getPersonIdString());

List<Request> requests = ((MockOkHttpClientAdapter) api.getClient()).getRequests();
Assert.assertEquals(1, requests.size());
Request request = requests.get(0);
Assert.assertEquals(2, request.url().pathSegments().size());
Assert.assertEquals("fdfe", request.url().pathSegments().get(0));
Assert.assertEquals("userReview", request.url().pathSegments().get(1));
Assert.assertEquals(2, request.url().queryParameterNames().size());
Assert.assertEquals("org.mozilla.firefox", request.url().queryParameter("doc"));
}

@Test
public void reviews() throws Exception {
ReviewResponse response = api.reviews("com.cpuid.cpu_z", GooglePlayAPI.REVIEW_SORT.HIGHRATING, 0, 20);
Expand All @@ -443,7 +466,7 @@ public void reviews() throws Exception {
Assert.assertEquals("It is awesome app I install and it work success fully", response.getGetResponse().getReview(1).getComment());
Assert.assertEquals("Nitesh Kumar", response.getGetResponse().getReview(0).getAuthor2().getName());
Assert.assertEquals("https://plus.google.com/+NiteshKumar", response.getGetResponse().getReview(0).getAuthor2().getGooglePlusUrl());
Assert.assertEquals("https://lh3.googleusercontent.com/-t-T8LKa60Fc/AAAAAAAAAAI/AAAAAAAAStk/wS6mDBhiWQA/photo.jpg", response.getGetResponse().getReview(0).getAuthor2().getUrls().getUrl());
Assert.assertEquals("https://lh3.googleusercontent.com/-t-T8LKa60Fc/AAAAAAAAAAI/AAAAAAAAStk/wS6mDBhiWQA/photo.jpg", response.getGetResponse().getReview(0).getAuthor2().getAvatar().getImageUrl());
Assert.assertEquals("104245217570938637686", response.getGetResponse().getReview(0).getAuthor2().getPersonId());
Assert.assertEquals("person-104245217570938637686", response.getGetResponse().getReview(0).getAuthor2().getPersonIdString());

Expand All @@ -469,7 +492,7 @@ public void addReview() throws Exception {
Assert.assertEquals("Работает!", response.getUserReview().getComment());
Assert.assertEquals("konstantin razdolbaev", response.getUserReview().getAuthor2().getName());
Assert.assertEquals("", response.getUserReview().getAuthor2().getGooglePlusUrl());
Assert.assertEquals("https://lh3.googleusercontent.com/-PkFVwXLKCKk/AAAAAAAAAAI/AAAAAAAAAAA/AKB_U8valX_uc0SKPSZEhVtxDUqYtRwIgQ/photo.jpg", response.getUserReview().getAuthor2().getUrls().getUrl());
Assert.assertEquals("https://lh3.googleusercontent.com/-PkFVwXLKCKk/AAAAAAAAAAI/AAAAAAAAAAA/AKB_U8valX_uc0SKPSZEhVtxDUqYtRwIgQ/photo.jpg", response.getUserReview().getAuthor2().getAvatar().getImageUrl());
Assert.assertEquals("100687909122075437983", response.getUserReview().getAuthor2().getPersonId());
Assert.assertEquals("person-100687909122075437983", response.getUserReview().getAuthor2().getPersonIdString());

Expand Down
Binary file not shown.

1 comment on commit 41a8112

@nagayev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

Please sign in to comment.