Search in sources :

Example 1 with RestAdapterCallback

use of org.matrix.androidsdk.rest.callback.RestAdapterCallback in project matrix-android-sdk by matrix-org.

the class ProfileRestClient method requestEmailValidationToken.

/**
 * Request an email validation token.
 *
 * @param address              the email address
 * @param clientSecret         the client secret number
 * @param attempt              the attempt count
 * @param nextLink             the next link
 * @param isDuringRegistration true if it occurs during a registration flow
 * @param callback             the callback
 */
public void requestEmailValidationToken(final String address, final String clientSecret, final int attempt, final String nextLink, final boolean isDuringRegistration, final ApiCallback<RequestEmailValidationResponse> callback) {
    final String description = "requestEmailValidationToken";
    RequestEmailValidationParams params = new RequestEmailValidationParams();
    params.email = address;
    params.clientSecret = clientSecret;
    params.sendAttempt = attempt;
    params.id_server = mHsConfig.getIdentityServerUri().getHost();
    if (!TextUtils.isEmpty(nextLink)) {
        params.next_link = nextLink;
    }
    final RestAdapterCallback<RequestEmailValidationResponse> adapterCallback = new RestAdapterCallback<RequestEmailValidationResponse>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

        @Override
        public void onRetry() {
            requestEmailValidationToken(address, clientSecret, attempt, nextLink, isDuringRegistration, callback);
        }
    }) {

        @Override
        public void success(RequestEmailValidationResponse requestEmailValidationResponse, Response response) {
            onEventSent();
            requestEmailValidationResponse.email = address;
            requestEmailValidationResponse.clientSecret = clientSecret;
            requestEmailValidationResponse.sendAttempt = attempt;
            callback.onSuccess(requestEmailValidationResponse);
        }
    };
    try {
        if (isDuringRegistration) {
            // URL differs in that case
            mApi.requestEmailValidationForRegistration(params, adapterCallback);
        } else {
            mApi.requestEmailValidation(params, adapterCallback);
        }
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : TokenRefreshResponse(org.matrix.androidsdk.rest.model.login.TokenRefreshResponse) RequestPhoneNumberValidationResponse(org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationResponse) AccountThreePidsResponse(org.matrix.androidsdk.rest.model.pid.AccountThreePidsResponse) ForgetPasswordResponse(org.matrix.androidsdk.rest.model.ForgetPasswordResponse) Response(retrofit.client.Response) RequestEmailValidationResponse(org.matrix.androidsdk.rest.model.RequestEmailValidationResponse) RestAdapterCallback(org.matrix.androidsdk.rest.callback.RestAdapterCallback) RequestEmailValidationParams(org.matrix.androidsdk.rest.model.RequestEmailValidationParams) RequestEmailValidationResponse(org.matrix.androidsdk.rest.model.RequestEmailValidationResponse)

Example 2 with RestAdapterCallback

use of org.matrix.androidsdk.rest.callback.RestAdapterCallback in project matrix-android-sdk by matrix-org.

the class ProfileRestClient method requestPhoneNumberValidationToken.

/**
 * Request a phone number validation token.
 *
 * @param phoneNumber          the phone number
 * @param countryCode          the country code of the phone number
 * @param clientSecret         the client secret number
 * @param attempt              the attempt count
 * @param isDuringRegistration true if it occurs during a registration flow
 * @param callback             the callback
 */
public void requestPhoneNumberValidationToken(final String phoneNumber, final String countryCode, final String clientSecret, final int attempt, final boolean isDuringRegistration, final ApiCallback<RequestPhoneNumberValidationResponse> callback) {
    final String description = "requestPhoneNumberValidationToken";
    RequestPhoneNumberValidationParams params = new RequestPhoneNumberValidationParams();
    params.phone_number = phoneNumber;
    params.country = countryCode;
    params.clientSecret = clientSecret;
    params.sendAttempt = attempt;
    params.id_server = mHsConfig.getIdentityServerUri().getHost();
    final RestAdapterCallback<RequestPhoneNumberValidationResponse> adapterCallback = new RestAdapterCallback<RequestPhoneNumberValidationResponse>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

        @Override
        public void onRetry() {
            requestPhoneNumberValidationToken(phoneNumber, countryCode, clientSecret, attempt, isDuringRegistration, callback);
        }
    }) {

        @Override
        public void success(RequestPhoneNumberValidationResponse requestPhoneNumberValidationResponse, Response response) {
            onEventSent();
            requestPhoneNumberValidationResponse.clientSecret = clientSecret;
            requestPhoneNumberValidationResponse.sendAttempt = attempt;
            callback.onSuccess(requestPhoneNumberValidationResponse);
        }
    };
    try {
        if (isDuringRegistration) {
            // URL differs in that case
            mApi.requestPhoneNumberValidationForRegistration(params, adapterCallback);
        } else {
            mApi.requestPhoneNumberValidation(params, adapterCallback);
        }
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : TokenRefreshResponse(org.matrix.androidsdk.rest.model.login.TokenRefreshResponse) RequestPhoneNumberValidationResponse(org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationResponse) AccountThreePidsResponse(org.matrix.androidsdk.rest.model.pid.AccountThreePidsResponse) ForgetPasswordResponse(org.matrix.androidsdk.rest.model.ForgetPasswordResponse) Response(retrofit.client.Response) RequestEmailValidationResponse(org.matrix.androidsdk.rest.model.RequestEmailValidationResponse) RequestPhoneNumberValidationParams(org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationParams) RestAdapterCallback(org.matrix.androidsdk.rest.callback.RestAdapterCallback) RequestPhoneNumberValidationResponse(org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationResponse)

Aggregations

RestAdapterCallback (org.matrix.androidsdk.rest.callback.RestAdapterCallback)2 ForgetPasswordResponse (org.matrix.androidsdk.rest.model.ForgetPasswordResponse)2 RequestEmailValidationResponse (org.matrix.androidsdk.rest.model.RequestEmailValidationResponse)2 RequestPhoneNumberValidationResponse (org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationResponse)2 TokenRefreshResponse (org.matrix.androidsdk.rest.model.login.TokenRefreshResponse)2 AccountThreePidsResponse (org.matrix.androidsdk.rest.model.pid.AccountThreePidsResponse)2 Response (retrofit.client.Response)2 RequestEmailValidationParams (org.matrix.androidsdk.rest.model.RequestEmailValidationParams)1 RequestPhoneNumberValidationParams (org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationParams)1