Search in sources :

Example 16 with Response

use of retrofit.client.Response 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)

Example 17 with Response

use of retrofit.client.Response in project matrix-android-sdk by matrix-org.

the class ThirdPidRestClient method lookup3Pids.

/**
 * Retrieve user matrix id from a 3rd party id.
 * @param addresses 3rd party ids
 * @param mediums the medias.
 * @param callback the 3rd parties callback
 */
public void lookup3Pids(final List<String> addresses, final List<String> mediums, final ApiCallback<List<String>> callback) {
    // sanity checks
    if ((null == addresses) || (null == mediums) || (addresses.size() != mediums.size())) {
        callback.onUnexpectedError(new Exception("invalid params"));
        return;
    }
    // nothing to check
    if (0 == mediums.size()) {
        callback.onSuccess(new ArrayList<String>());
        return;
    }
    BulkLookupParams threePidsParams = new BulkLookupParams();
    ArrayList<List<String>> list = new ArrayList<>();
    for (int i = 0; i < addresses.size(); i++) {
        list.add(Arrays.asList(mediums.get(i), addresses.get(i)));
    }
    threePidsParams.threepids = list;
    try {
        mApi.bulkLookup(threePidsParams, new Callback<BulkLookupResponse>() {

            @Override
            public void success(BulkLookupResponse bulkLookupResponse, Response response) {
                HashMap<String, String> mxidByAddress = new HashMap<>();
                if (null != bulkLookupResponse.threepids) {
                    for (int i = 0; i < bulkLookupResponse.threepids.size(); i++) {
                        List<String> items = bulkLookupResponse.threepids.get(i);
                        // [0] : medium
                        // [1] : address
                        // [2] : matrix id
                        mxidByAddress.put(items.get(1), items.get(2));
                    }
                }
                ArrayList<String> matrixIds = new ArrayList<>();
                for (String address : addresses) {
                    if (mxidByAddress.containsKey(address)) {
                        matrixIds.add(mxidByAddress.get(address));
                    } else {
                        matrixIds.add("");
                    }
                }
                callback.onSuccess(matrixIds);
            }

            @Override
            public void failure(RetrofitError error) {
                callback.onUnexpectedError(error);
            }
        });
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BulkLookupResponse(org.matrix.androidsdk.rest.model.BulkLookupResponse) PidResponse(org.matrix.androidsdk.rest.model.pid.PidResponse) Response(retrofit.client.Response) BulkLookupParams(org.matrix.androidsdk.rest.model.BulkLookupParams) BulkLookupResponse(org.matrix.androidsdk.rest.model.BulkLookupResponse) ArrayList(java.util.ArrayList) List(java.util.List) RetrofitError(retrofit.RetrofitError)

Example 18 with Response

use of retrofit.client.Response in project matrix-android-sdk by matrix-org.

the class RetrofitUtils method createJsonResponse.

public static Response createJsonResponse(String url, int code, JSONObject json, List<Header> additionalHeaders) throws Exception {
    final String jsonStr = json.toString();
    final InputStream stream = new ByteArrayInputStream(jsonStr.getBytes("UTF8"));
    additionalHeaders.add(new Header("Content-Type", "application/json"));
    String status = "Unknown";
    if (sCodeToStatusMsg.containsKey(code)) {
        status = sCodeToStatusMsg.get(code);
    }
    return new Response(url, code, status, additionalHeaders, new TypedInput() {

        @Override
        public String mimeType() {
            return "application/json";
        }

        @Override
        public long length() {
            return jsonStr.length();
        }

        @Override
        public InputStream in() throws IOException {
            return stream;
        }
    });
}
Also used : Response(retrofit.client.Response) Header(retrofit.client.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TypedInput(retrofit.mime.TypedInput) IOException(java.io.IOException)

Example 19 with Response

use of retrofit.client.Response in project steps by linroid.

the class MainActivity method onAddCity.

@Override
public void onAddCity(String cityName) {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage("添加中....");
    dialog.show();
    WeatherApp app = (WeatherApp) getApplication();
    WeatherService service = app.getWeatherService();
    service.getDataAsync(cityName, new Callback<Data>() {

        @Override
        public void success(Data data, Response response) {
            Result result = data.getResults().get(0);
            getContentResolver().insert(DataContract.Weather.CONTENT_URI, result.toContentValues());
            // triggerSync();
            Toast.makeText(MainActivity.this, R.string.add_city_success, Toast.LENGTH_SHORT).show();
            dialog.dismiss();
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            Toast.makeText(MainActivity.this, R.string.add_city_fail, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : Response(retrofit.client.Response) WeatherService(com.linroid.weather.data.WeatherService) Data(com.linroid.weather.model.Data) ProgressDialog(android.app.ProgressDialog) Result(com.linroid.weather.model.Result) RetrofitError(retrofit.RetrofitError)

Example 20 with Response

use of retrofit.client.Response in project glasquare by davidvavra.

the class VenueListActivity method searchVenues.

private void searchVenues(String ll) {
    Callback<ExploreVenues.ExploreVenuesResponse> callback = new Callback<ExploreVenues.ExploreVenuesResponse>() {

        @Override
        public void success(ExploreVenues.ExploreVenuesResponse exploreVenuesResponse, Response response) {
            if (exploreVenuesResponse.getVenues().size() == 0) {
                showError(R.string.no_venues_found);
            } else {
                showContent(new VenuesAdapter(exploreVenuesResponse.getVenues()), new CardSelectedListener() {

                    @Override
                    public void onCardSelected(Object item) {
                        mSelectedVenue = (ExploreVenues.Venue) item;
                        openOptionsMenu();
                    }
                });
            }
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            showError(R.string.error_please_try_again);
            DebugLog.e(retrofitError);
        }
    };
    int type = getIntent().getIntExtra(EXTRA_TYPE, TYPE_EXPLORE);
    switch(type) {
        case TYPE_EXPLORE:
            Api.get().create(ExploreVenues.class).best(ll, callback);
            break;
        case TYPE_SEARCH:
            String query = getIntent().getStringExtra(EXTRA_QUERY);
            Api.get().create(ExploreVenues.class).search(ll, query, callback);
            break;
    }
}
Also used : Response(retrofit.client.Response) Callback(retrofit.Callback) VenuesAdapter(cz.destil.glasquare.adapter.VenuesAdapter) ExploreVenues(cz.destil.glasquare.api.ExploreVenues) RetrofitError(retrofit.RetrofitError)

Aggregations

Response (retrofit.client.Response)46 RetrofitError (retrofit.RetrofitError)27 LinkHeaders (com.instructure.canvasapi.utilities.LinkHeaders)8 View (android.view.View)7 TextView (android.widget.TextView)7 ImageView (android.widget.ImageView)6 ArrayList (java.util.ArrayList)5 Callback (retrofit.Callback)5 RestAdapter (retrofit.RestAdapter)5 SharedPreferences (android.content.SharedPreferences)4 User (com.instructure.canvasapi.model.User)4 ClientAuthInterceptor (io.plaidapp.data.api.ClientAuthInterceptor)4 HashMap (java.util.HashMap)4 Intent (android.content.Intent)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 ForgetPasswordResponse (org.matrix.androidsdk.rest.model.ForgetPasswordResponse)3 RequestEmailValidationResponse (org.matrix.androidsdk.rest.model.RequestEmailValidationResponse)3 RequestPhoneNumberValidationResponse (org.matrix.androidsdk.rest.model.RequestPhoneNumberValidationResponse)3 TokenRefreshResponse (org.matrix.androidsdk.rest.model.login.TokenRefreshResponse)3