Search in sources :

Example 1 with AbstractInputStreamContent

use of com.google.api.client.http.AbstractInputStreamContent in project gradle-play-publisher by ZeroBrain.

the class BasicUploadApk method upload.

public void upload(String applicationName, String packageName, File apkFiles, File secretFile, File authStore, String productType) {
    try {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(packageName), "ApplicationConfig.PACKAGE_NAME cannot be null or empty!");
        // Create the API service.
        AndroidPublisher service = AndroidPublisherHelper.init(applicationName, secretFile, authStore);
        final Edits edits = service.edits();
        // Create a new edit to make changes to your listing.
        Insert editRequest = edits.insert(packageName, null);
        AppEdit edit = editRequest.execute();
        final String editId = edit.getId();
        log.info(String.format("Created edit with id: %s", editId));
        // Upload new apk to developer console
        final AbstractInputStreamContent apkFile = new FileContent(AndroidPublisherHelper.MIME_TYPE_APK, apkFiles);
        Upload uploadRequest = edits.apks().upload(packageName, editId, apkFile);
        Apk apk = uploadRequest.execute();
        log.info(String.format("Version code %d has been uploaded", apk.getVersionCode()));
        // Assign apk to alpha track.
        List<Integer> apkVersionCodes = new ArrayList<Integer>();
        apkVersionCodes.add(apk.getVersionCode());
        Update updateTrackRequest = edits.tracks().update(packageName, editId, productType, new Track().setVersionCodes(apkVersionCodes));
        Track updatedTrack = updateTrackRequest.execute();
        log.info(String.format("Track %s has been updated.", updatedTrack.getTrack()));
        // Commit changes for edit.
        Commit commitRequest = edits.commit(packageName, editId);
        AppEdit appEdit = commitRequest.execute();
        log.info(String.format("App edit with id %s has been comitted", appEdit.getId()));
    } catch (IOException ex) {
        log.error("Excpetion was thrown while uploading apk to production track", ex);
    } catch (GeneralSecurityException ex) {
        log.error("Excpetion was thrown while uploading apk to production track", ex);
    }
}
Also used : AndroidPublisher(com.google.api.services.androidpublisher.AndroidPublisher) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) Upload(com.google.api.services.androidpublisher.AndroidPublisher.Edits.Apks.Upload) IOException(java.io.IOException) Insert(com.google.api.services.androidpublisher.AndroidPublisher.Edits.Insert) Update(com.google.api.services.androidpublisher.AndroidPublisher.Edits.Tracks.Update) AbstractInputStreamContent(com.google.api.client.http.AbstractInputStreamContent) FileContent(com.google.api.client.http.FileContent) Edits(com.google.api.services.androidpublisher.AndroidPublisher.Edits) Commit(com.google.api.services.androidpublisher.AndroidPublisher.Edits.Commit) AppEdit(com.google.api.services.androidpublisher.model.AppEdit) Apk(com.google.api.services.androidpublisher.model.Apk) Track(com.google.api.services.androidpublisher.model.Track)

Example 2 with AbstractInputStreamContent

use of com.google.api.client.http.AbstractInputStreamContent in project OpenRefine by OpenRefine.

the class FusionTableSerializer method sendBatch.

private boolean sendBatch(int batchSize) {
    try {
        // TODO: we really want to do GZIP compression here 
        // FIXME: text/csv doesn't work even though that's what the content is
        AbstractInputStreamContent content = ByteArrayContent.fromString("application/octet-stream", sbBatch.toString());
        Long count = FusionTableHandler.insertRows(service, tableId, content);
        if (count != null && count.intValue() != batchSize) {
            exceptions.add(new IOException("only imported " + count + " of " + batchSize + " rows"));
        }
    } catch (IOException e) {
        exceptions.add(e);
        if (e instanceof HttpResponseException) {
            int code = ((HttpResponseException) e).getStatusCode();
            if (code >= 400 && code < 500) {
                return false;
            }
        // 500s appear to be retried automatically by li
        }
    } finally {
        sbBatch = null;
    }
    return true;
}
Also used : HttpResponseException(com.google.api.client.http.HttpResponseException) IOException(java.io.IOException) AbstractInputStreamContent(com.google.api.client.http.AbstractInputStreamContent)

Aggregations

AbstractInputStreamContent (com.google.api.client.http.AbstractInputStreamContent)2 IOException (java.io.IOException)2 FileContent (com.google.api.client.http.FileContent)1 HttpResponseException (com.google.api.client.http.HttpResponseException)1 AndroidPublisher (com.google.api.services.androidpublisher.AndroidPublisher)1 Edits (com.google.api.services.androidpublisher.AndroidPublisher.Edits)1 Upload (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Apks.Upload)1 Commit (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Commit)1 Insert (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Insert)1 Update (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Tracks.Update)1 Apk (com.google.api.services.androidpublisher.model.Apk)1 AppEdit (com.google.api.services.androidpublisher.model.AppEdit)1 Track (com.google.api.services.androidpublisher.model.Track)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1