Skip to content

Commit

Permalink
Wishlist methods added
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Apr 23, 2018
1 parent 8dcfa71 commit 6e4154d
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/main/java/com/github/yeriomin/playstoreapi/GooglePlayAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class GooglePlayAPI {
private static final String CATEGORIES_LIST_URL = FDFE_URL + "categoriesList";
private static final String TESTING_PROGRAM_URL = FDFE_URL + "apps/testingProgram";
private static final String LOG_URL = FDFE_URL + "log";
private static final String LIBRARY_URL = FDFE_URL + "library";
private static final String MODIFY_LIBRARY_URL = FDFE_URL + "modifyLibrary";
private static final String API_FDFE_URL = FDFE_URL + "api/";
private static final String USER_PROFILE_URL = API_FDFE_URL + "userProfile";

Expand Down Expand Up @@ -126,6 +128,16 @@ public enum SUBCATEGORY {
}
}

public enum LIBRARY_ID {
WISHLIST("u-wl");

public String value;

LIBRARY_ID(String value) {
this.value = value;
}
}

HttpClientAdapter client;
private Locale locale;
private DeviceInfoProvider deviceInfoProvider;
Expand Down Expand Up @@ -705,6 +717,47 @@ public UserProfileResponse userProfile() throws IOException {
).getPayload().getUserProfileResponse();
}

public void addLibraryApp(LIBRARY_ID libraryId, String packageName) throws IOException {
ModifyLibraryRequest request = ModifyLibraryRequest.newBuilder()
.addAddPackageName(packageName)
.setLibraryId(libraryId.value)
.build()
;
client.post(MODIFY_LIBRARY_URL, request.toByteArray(), getDefaultHeaders());
}

public void addWishlistApp(String packageName) throws IOException {
addLibraryApp(LIBRARY_ID.WISHLIST, packageName);
}

public void removeLibraryApp(LIBRARY_ID libraryId, String packageName) throws IOException {
ModifyLibraryRequest request = ModifyLibraryRequest.newBuilder()
.addRemovePackageName(packageName)
.setLibraryId(libraryId.value)
.build()
;
client.post(MODIFY_LIBRARY_URL, request.toByteArray(), getDefaultHeaders());
}

public void removeWishlistApp(String packageName) throws IOException {
removeLibraryApp(LIBRARY_ID.WISHLIST, packageName);
}

public ListResponse getLibraryApps(LIBRARY_ID libraryId) throws IOException {
Map<String, String> params = new HashMap<String, String>();
params.put("c", "0");
params.put("dl", "7"); // magic
if (null != libraryId) {
params.put("libid", libraryId.value);
}
byte[] responseBytes = client.get(LIBRARY_URL, params, getDefaultHeaders());
return ResponseWrapper.parseFrom(responseBytes).getPayload().getListResponse();
}

public ListResponse getWishlistApps() throws IOException {
return getLibraryApps(LIBRARY_ID.WISHLIST);
}

/**
* login methods use this
* Most likely not all of these are required, but the Market app sends them, so we will too
Expand Down
5 changes: 5 additions & 0 deletions src/main/proto/GooglePlay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1240,3 +1240,8 @@ message StatCounters {
message UsageStatsExtensionProto {
optional AndroidDataUsageProto dataUsage = 1;
}
message ModifyLibraryRequest {
optional string libraryId = 1;
repeated string addPackageName = 2;
repeated string removePackageName = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,64 @@ public void userProfile() throws Exception {
Assert.assertEquals("https://lh5.googleusercontent.com/-NxRLoKjJ7LM/AAAAAAAAAAI/AAAAAAAAAAA/AGi4gfwqBhB2A69d0pMdvrYAhASD_01wVA/photo.jpg", response.getUserProfile().getImage(0).getImageUrl());
}

@Test
public void wishlist() throws Exception {
api.addWishlistApp("com.whatsapp");
api.addWishlistApp("com.instagram.android");
ListResponse response = api.getWishlistApps();
api.removeWishlistApp("com.whatsapp");

Assert.assertEquals(1, response.getDocCount());
Assert.assertTrue(response.getDoc(0).getChild(0).getChildCount() > 1);

DocV2 details1 = response.getDoc(0).getChild(0).getChild(0);
Assert.assertEquals("WhatsApp Messenger", details1.getTitle());
DocV2 details2 = response.getDoc(0).getChild(0).getChild(1);
Assert.assertEquals("Instagram", details2.getTitle());

List<Request> requests = ((MockOkHttpClientAdapter) api.getClient()).getRequests();
Assert.assertEquals(4, requests.size());

Request request1 = requests.get(0);
Assert.assertEquals("POST", request1.method());
Assert.assertEquals(2, request1.url().pathSegments().size());
Assert.assertEquals("fdfe", request1.url().pathSegments().get(0));
Assert.assertEquals("modifyLibrary", request1.url().pathSegments().get(1));
ModifyLibraryRequest modifyLibraryRequest1 = ModifyLibraryRequest.parseFrom(MockOkHttpClientAdapter.getBodyBytes(request1));
Assert.assertEquals(1, modifyLibraryRequest1.getAddPackageNameCount());
Assert.assertEquals("com.whatsapp", modifyLibraryRequest1.getAddPackageName(0));
Assert.assertEquals("u-wl", modifyLibraryRequest1.getLibraryId());

Request request2 = requests.get(1);
Assert.assertEquals("POST", request2.method());
Assert.assertEquals(2, request2.url().pathSegments().size());
Assert.assertEquals("fdfe", request2.url().pathSegments().get(0));
Assert.assertEquals("modifyLibrary", request2.url().pathSegments().get(1));
ModifyLibraryRequest modifyLibraryRequest2 = ModifyLibraryRequest.parseFrom(MockOkHttpClientAdapter.getBodyBytes(request2));
Assert.assertEquals(1, modifyLibraryRequest2.getAddPackageNameCount());
Assert.assertEquals("com.instagram.android", modifyLibraryRequest2.getAddPackageName(0));
Assert.assertEquals("u-wl", modifyLibraryRequest2.getLibraryId());

Request request3 = requests.get(2);
Assert.assertEquals("GET", request3.method());
Assert.assertEquals(2, request3.url().pathSegments().size());
Assert.assertEquals("fdfe", request3.url().pathSegments().get(0));
Assert.assertEquals("library", request3.url().pathSegments().get(1));
Assert.assertEquals("0", request3.url().queryParameter("c"));
Assert.assertEquals("7", request3.url().queryParameter("dl"));
Assert.assertEquals("u-wl", request3.url().queryParameter("libid"));

Request request4 = requests.get(3);
Assert.assertEquals("POST", request4.method());
Assert.assertEquals(2, request4.url().pathSegments().size());
Assert.assertEquals("fdfe", request4.url().pathSegments().get(0));
Assert.assertEquals("modifyLibrary", request4.url().pathSegments().get(1));
ModifyLibraryRequest modifyLibraryRequest3 = ModifyLibraryRequest.parseFrom(MockOkHttpClientAdapter.getBodyBytes(request4));
Assert.assertEquals(1, modifyLibraryRequest3.getRemovePackageNameCount());
Assert.assertEquals("com.whatsapp", modifyLibraryRequest3.getRemovePackageName(0));
Assert.assertEquals("u-wl", modifyLibraryRequest3.getLibraryId());
}

private GooglePlayAPI initApi() {
Properties properties = new Properties();
try {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 6e4154d

Please sign in to comment.