Search in sources :

Example 1 with PaymentsRegionException

use of org.whispersystems.signalservice.internal.push.exceptions.PaymentsRegionException in project Signal-Android by signalapp.

the class PushServiceSocket method writeProfile.

/**
 * @return The avatar URL path, if one was written.
 */
public Optional<String> writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
    String requestBody = JsonUtil.toJson(signalServiceProfileWrite);
    ProfileAvatarUploadAttributes formAttributes;
    String response = makeServiceRequest(String.format(PROFILE_PATH, ""), "PUT", requestBody, NO_HEADERS, PaymentsRegionException::responseCodeHandler, Optional.absent());
    if (signalServiceProfileWrite.hasAvatar() && profileAvatar != null) {
        try {
            formAttributes = JsonUtil.fromJson(response, ProfileAvatarUploadAttributes.class);
        } catch (IOException e) {
            Log.w(TAG, e);
            throw new MalformedResponseException("Unable to parse entity", e);
        }
        uploadToCdn0(AVATAR_UPLOAD_PATH, formAttributes.getAcl(), formAttributes.getKey(), formAttributes.getPolicy(), formAttributes.getAlgorithm(), formAttributes.getCredential(), formAttributes.getDate(), formAttributes.getSignature(), profileAvatar.getData(), profileAvatar.getContentType(), profileAvatar.getDataLength(), profileAvatar.getOutputStreamFactory(), null, null);
        return Optional.of(formAttributes.getKey());
    }
    return Optional.absent();
}
Also used : PaymentsRegionException(org.whispersystems.signalservice.internal.push.exceptions.PaymentsRegionException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 2 with PaymentsRegionException

use of org.whispersystems.signalservice.internal.push.exceptions.PaymentsRegionException in project Signal-Android by WhisperSystems.

the class PushServiceSocket method writeProfile.

/**
 * @return The avatar URL path, if one was written.
 */
public Optional<String> writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
    String requestBody = JsonUtil.toJson(signalServiceProfileWrite);
    ProfileAvatarUploadAttributes formAttributes;
    String response = makeServiceRequest(String.format(PROFILE_PATH, ""), "PUT", requestBody, NO_HEADERS, PaymentsRegionException::responseCodeHandler, Optional.absent());
    if (signalServiceProfileWrite.hasAvatar() && profileAvatar != null) {
        try {
            formAttributes = JsonUtil.fromJson(response, ProfileAvatarUploadAttributes.class);
        } catch (IOException e) {
            Log.w(TAG, e);
            throw new MalformedResponseException("Unable to parse entity", e);
        }
        uploadToCdn0(AVATAR_UPLOAD_PATH, formAttributes.getAcl(), formAttributes.getKey(), formAttributes.getPolicy(), formAttributes.getAlgorithm(), formAttributes.getCredential(), formAttributes.getDate(), formAttributes.getSignature(), profileAvatar.getData(), profileAvatar.getContentType(), profileAvatar.getDataLength(), profileAvatar.getOutputStreamFactory(), null, null);
        return Optional.of(formAttributes.getKey());
    }
    return Optional.absent();
}
Also used : PaymentsRegionException(org.whispersystems.signalservice.internal.push.exceptions.PaymentsRegionException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Aggregations

IOException (java.io.IOException)2 GroupsV2AuthorizationString (org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString)2 MalformedResponseException (org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)2 PaymentsRegionException (org.whispersystems.signalservice.internal.push.exceptions.PaymentsRegionException)2