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));
}
}
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));
}
}
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;
}
});
}
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();
}
});
}
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;
}
}
Aggregations