Java源码示例:com.akdeniz.googleplaycrawler.GooglePlay.ResponseWrapper

示例1
/**
 * Try to make sense of a {@link ResponseWrapper}, containing a search result.
 * 
 * @param rw
 *          a wrapper containing either a {@link SearchResponse},
 *          {@link ListResponse} or a {@link PreFetch}
 */
public void append(ResponseWrapper rw) {
	// The SearchResponse format changed considerably over time. The message
	// type seems to have gotten deprecated for Android 5 and later in favor of
	// ListResponse. Apparently, SearchResponse got too too unwieldy.
	append(Unwrap.searchResponse(rw).getDocList());
	append(Unwrap.listResponse(rw).getDocList());
	for (PreFetch pf : rw.getPreFetchList()) {
		try {
			append(ResponseWrapper.parseFrom(pf.getResponse()));
		}
		catch (InvalidProtocolBufferException e) {
			// We tried, we failed.
		}
	}
}
 
示例2
/**
 * Fetches a search results for given query. Offset and numberOfResult
 * parameters are optional and <code>null</code> can be passed!
 */
public SearchResponse search(String query, Integer offset,
		Integer numberOfResult) throws IOException {

	ResponseWrapper responseWrapper = executeGETRequest(
			SEARCH_URL,
			new String[][] {
					{ "c", "3" },
					{ "q", query },
					{ "o", (offset == null) ? null : String.valueOf(offset) },
					{
							"n",
							(numberOfResult == null) ? null : String
									.valueOf(numberOfResult) }, });

	return responseWrapper.getPayload().getSearchResponse();
}
 
示例3
/**
 * Fetches applications within supplied category and sub-category. If
 * <code>null</code> is given for sub-category, it fetches sub-categories of
 * passed category.
 * 
 * Default values for offset and numberOfResult are "0" and "20" respectively.
 * These values are determined by Google Play Store.
 */
public ListResponse list(String categoryId, String subCategoryId,
		Integer offset, Integer numberOfResult) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(
			LIST_URL,
			new String[][] {
					{ "c", "3" },
					{ "cat", categoryId },
					{ "ctr", subCategoryId },
					{ "o", (offset == null) ? null : String.valueOf(offset) },
					{
							"n",
							(numberOfResult == null) ? null : String
									.valueOf(numberOfResult) }, });

	return responseWrapper.getPayload().getListResponse();
}
 
示例4
/**
 * Fetches the reviews of given package name by sorting passed choice.
 * 
 * Default values for offset and numberOfResult are "0" and "20" respectively.
 * These values are determined by Google Play Store.
 */
public ReviewResponse reviews(String packageName, REVIEW_SORT sort,
		Integer offset, Integer numberOfResult) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(
			REVIEWS_URL,
			new String[][] {
					{ "doc", packageName },
					{ "sort", (sort == null) ? null : String.valueOf(sort.value) },
					{ "o", (offset == null) ? null : String.valueOf(offset) },
					{
							"n",
							(numberOfResult == null) ? null : String
									.valueOf(numberOfResult) } });

	return responseWrapper.getPayload().getReviewResponse();
}
 
示例5
/**
 * Fetches the recommendations of given package name.
 * 
 * Default values for offset and numberOfResult are "0" and "20" respectively.
 * These values are determined by Google Play Store.
 */
public ListResponse recommendations(String packageName,
		RECOMMENDATION_TYPE type, Integer offset, Integer numberOfResult)
		throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(
			RECOMMENDATIONS_URL,
			new String[][] {
					{ "c", "3" },
					{ "doc", packageName },
					{ "rt", (type == null) ? null : String.valueOf(type.value) },
					{ "o", (offset == null) ? null : String.valueOf(offset) },
					{
							"n",
							(numberOfResult == null) ? null : String
									.valueOf(numberOfResult) } });

	return responseWrapper.getPayload().getListResponse();
}
 
示例6
/**
 * Fetches a search results for given query. Offset and numberOfResult
 * parameters are optional and <code>null</code> can be passed!
 */
public SearchResponse search(String query, Integer offset, Integer numberOfResult)
		throws IOException {

	ResponseWrapper responseWrapper = executeGETRequest(SEARCH_URL, new String[][] {
			{ "c", "3" },
			{ "q", query },
			{ "o", (offset == null) ? null : String.valueOf(offset) },
			{ "n", (numberOfResult == null) ? null : String.valueOf(numberOfResult) }, });

	return responseWrapper.getPayload().getSearchResponse();
}
 
示例7
/**
 * Fetches detailed information about passed package name. If it is needed to
 * fetch information about more than one application, consider to use
 * <code>bulkDetails</code>.
 */
public DetailsResponse details(String packageName) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(DETAILS_URL, new String[][] { {
			"doc",
			packageName }, });

	return responseWrapper.getPayload().getDetailsResponse();
}
 
示例8
/** Equivalent of details but bulky one! */
public BulkDetailsResponse bulkDetails(List<String> packageNames) throws IOException {

	Builder bulkDetailsRequestBuilder = BulkDetailsRequest.newBuilder();
	bulkDetailsRequestBuilder.addAllDocid(packageNames);

	ResponseWrapper responseWrapper = executePOSTRequest(BULKDETAILS_URL, bulkDetailsRequestBuilder
			.build().toByteArray(), "application/x-protobuf");

	return responseWrapper.getPayload().getBulkDetailsResponse();
}
 
示例9
public BrowseResponse browse(String categoryId, String subCategoryId) throws IOException {

		ResponseWrapper responseWrapper = executeGETRequest(BROWSE_URL, new String[][] {
				{ "c", "3" },
				{ "cat", categoryId },
				{ "ctr", subCategoryId } });

		return responseWrapper.getPayload().getBrowseResponse();
	}
 
示例10
/**
 * Fetches applications within supplied category and sub-category. If
 * <code>null</code> is given for sub-category, it fetches sub-categories of
 * passed category.
 *
 * Default values for offset and numberOfResult are "0" and "20" respectively.
 * These values are determined by Google Play Store.
 */
public ListResponse list(String categoryId, String subCategoryId, Integer offset,
		Integer numberOfResult) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(LIST_URL, new String[][] {
			{ "c", "3" },
			{ "cat", categoryId },
			{ "ctr", subCategoryId },
			{ "o", (offset == null) ? null : String.valueOf(offset) },
			{ "n", (numberOfResult == null) ? null : String.valueOf(numberOfResult) }, });

	return responseWrapper.getPayload().getListResponse();
}
 
示例11
public DownloadData delivery(String packageName, int versionCode, int offerType)
		throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(DELIVERY_URL, new String[][] {
			{ "ot", String.valueOf(offerType) },
			{ "doc", packageName },
			{ "vc", String.valueOf(versionCode) }, });

	AndroidAppDeliveryData appDeliveryData = responseWrapper.getPayload().getDeliveryResponse()
			.getAppDeliveryData();
	return new DownloadData(this, appDeliveryData);
}
 
示例12
/**
 * This function is used for fetching download url and donwload cookie, rather
 * than actual purchasing.
 */
private BuyResponse purchase(String packageName, int versionCode, int offerType)
		throws IOException {

	ResponseWrapper responseWrapper = executePOSTRequest(PURCHASE_URL, new String[][] {
			{ "ot", String.valueOf(offerType) },
			{ "doc", packageName },
			{ "vc", String.valueOf(versionCode) }, });

	return responseWrapper.getPayload().getBuyResponse();
}
 
示例13
/**
 * Fetches the reviews of given package name by sorting passed choice.
 *
 * Default values for offset and numberOfResult are "0" and "20" respectively.
 * These values are determined by Google Play Store.
 */
public ReviewResponse reviews(String packageName, REVIEW_SORT sort, Integer offset,
		Integer numberOfResult) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(REVIEWS_URL, new String[][] {
			{ "doc", packageName },
			{ "sort", (sort == null) ? null : String.valueOf(sort.value) },
			{ "o", (offset == null) ? null : String.valueOf(offset) },
			{ "n", (numberOfResult == null) ? null : String.valueOf(numberOfResult) } });

	return responseWrapper.getPayload().getReviewResponse();
}
 
示例14
/**
 * Uploads device configuration to google server so that can be seen from web
 * as a registered device!!
 *
 * @see https://play.google.com/store/account
 */
public UploadDeviceConfigResponse uploadDeviceConfig() throws Exception {

	UploadDeviceConfigRequest request = UploadDeviceConfigRequest.newBuilder()
			.setDeviceConfiguration(Utils.getDeviceConfigurationProto()).build();
	ResponseWrapper responseWrapper = executePOSTRequest(UPLOADDEVICECONFIG_URL,
			request.toByteArray(), "application/x-protobuf");
	return responseWrapper.getPayload().getUploadDeviceConfigResponse();
}
 
示例15
/**
 * Fetches the recommendations of given package name.
 *
 * Default values for offset and numberOfResult are "0" and "20" respectively.
 * These values are determined by Google Play Store.
 */
public ListResponse recommendations(String packageName, RECOMMENDATION_TYPE type, Integer offset,
		Integer numberOfResult) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(RECOMMENDATIONS_URL, new String[][] {
			{ "c", "3" },
			{ "doc", packageName },
			{ "rt", (type == null) ? null : String.valueOf(type.value) },
			{ "o", (offset == null) ? null : String.valueOf(offset) },
			{ "n", (numberOfResult == null) ? null : String.valueOf(numberOfResult) } });

	return responseWrapper.getPayload().getListResponse();
}
 
示例16
/**
 * Executes POST request and returns result as {@link ResponseWrapper}.
 * Content type can be specified for given byte array.
 */
public ResponseWrapper executePOSTRequest(String url, byte[] datapost, String contentType)
		throws IOException {

	HttpEntity httpEntity = executePost(url, new ByteArrayEntity(datapost),
			getHeaderParameters(this.getToken(), contentType));
	return GooglePlay.ResponseWrapper.parseFrom(httpEntity.getContent());

}
 
示例17
public static SearchResponse searchResponse(ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (payload(rw).hasSearchResponse()) {
		return pl.getSearchResponse();
	}
	return SearchResponse.getDefaultInstance();
}
 
示例18
public static ListResponse listResponse(ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (pl.hasListResponse()) {
		return pl.getListResponse();
	}
	return ListResponse.getDefaultInstance();
}
 
示例19
public static DeliveryResponse deliveryResponse(ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (pl.hasDeliveryResponse()) {
		return pl.getDeliveryResponse();
	}
	return DeliveryResponse.getDefaultInstance();
}
 
示例20
public static BulkDetailsResponse bulkDetailsResponse(ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (pl.hasBulkDetailsResponse()) {
		return pl.getBulkDetailsResponse();
	}
	return BulkDetailsResponse.getDefaultInstance();
}
 
示例21
public static DetailsResponse detailsResponse(ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (pl.hasDetailsResponse()) {
		return pl.getDetailsResponse();
	}
	return DetailsResponse.getDefaultInstance();
}
 
示例22
public static TocResponse tocResponse(ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (pl.hasTocResponse()) {
		return pl.getTocResponse();
	}
	return TocResponse.getDefaultInstance();
}
 
示例23
public static UploadDeviceConfigResponse uploadDeviceConfigResponse(
		ResponseWrapper rw) {
	Payload pl = payload(rw);
	if (pl.hasUploadDeviceConfigResponse()) {
		return pl.getUploadDeviceConfigResponse();
	}
	return UploadDeviceConfigResponse.getDefaultInstance();
}
 
示例24
public ResponseWrapper searchApp(String query) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(SEARCH_URL,
			new String[][] { { "c", "3" }, { "q", query },

			});

	return responseWrapper;
}
 
示例25
/**
 * Fetches detailed information about passed package name. If it is needed to
 * fetch information about more than one application, consider to use
 * <code>bulkDetails</code>.
 */
public DetailsResponse details(String packageName) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(DETAILS_URL,
			new String[][] { { "doc", packageName }, });

	return responseWrapper.getPayload().getDetailsResponse();
}
 
示例26
/** Equivalent of details but bulky one! */
public BulkDetailsResponse bulkDetails(List<String> packageNames)
		throws IOException {

	Builder bulkDetailsRequestBuilder = BulkDetailsRequest.newBuilder();
	bulkDetailsRequestBuilder.addAllDocid(packageNames).setIncludeDetails(true);

	ResponseWrapper responseWrapper = executePOSTRequest(BULKDETAILS_URL,
			bulkDetailsRequestBuilder.build().toByteArray(),
			"application/x-protobuf");

	return responseWrapper.getPayload().getBulkDetailsResponse();
}
 
示例27
public DownloadData delivery(String packageName, int versionCode,
		int offerType) throws IOException {
	ResponseWrapper responseWrapper = executeGETRequest(DELIVERY_URL,
			new String[][] { { "ot", String.valueOf(offerType) },
					{ "doc", packageName }, { "vc", String.valueOf(versionCode) }, });

	AndroidAppDeliveryData appDeliveryData = responseWrapper.getPayload()
			.getDeliveryResponse().getAppDeliveryData();
	return new DownloadData(this, appDeliveryData);
}
 
示例28
/**
 * This function is used for fetching download url and donwload cookie, rather
 * than actual purchasing.
 */
private BuyResponse purchase(String packageName, int versionCode,
		int offerType) throws IOException {

	ResponseWrapper responseWrapper = executePOSTRequest(PURCHASE_URL,
			new String[][] { { "ot", String.valueOf(offerType) },
					{ "doc", packageName }, { "vc", String.valueOf(versionCode) }, });

	return responseWrapper.getPayload().getBuyResponse();
}
 
示例29
/**
 * Uploads device configuration to google server so that can be seen from web
 * as a registered device!!
 * 
 * @see https://play.google.com/store/account
 */
public UploadDeviceConfigResponse uploadDeviceConfig() throws Exception {

	UploadDeviceConfigRequest request = UploadDeviceConfigRequest.newBuilder()
			.setDeviceConfiguration(Utils.getDeviceConfigurationProto())
			.setManufacturer("Samsung").build();
	ResponseWrapper responseWrapper = executePOSTRequest(
			UPLOADDEVICECONFIG_URL, request.toByteArray(), "application/x-protobuf");
	return responseWrapper.getPayload().getUploadDeviceConfigResponse();
}
 
示例30
/**
 * Executes GET request and returns result as {@link ResponseWrapper}.
 * Standard header parameters will be used for request.
 * 
 * @see getHeaderParameters
 * */
private ResponseWrapper executeGETRequest(String path, String[][] datapost)
		throws IOException {

	HttpEntity httpEntity = executeGet(path, datapost,
			getHeaderParameters(this.getToken(), null));
	return GooglePlay.ResponseWrapper.parseFrom(httpEntity.getContent());

}