use of retrofit.client.Response in project sbt-android by scala-android.
the class DesignerNewsLogin method showLoggedInUser.
private void showLoggedInUser() {
DesignerNewsService designerNewsService = new RestAdapter.Builder().setEndpoint(DesignerNewsService.ENDPOINT).setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(), BuildConfig.DESIGNER_NEWS_CLIENT_ID)).build().create(DesignerNewsService.class);
designerNewsService.getAuthedUser(new Callback<UserResponse>() {
@Override
public void success(UserResponse userResponse, Response response) {
final User user = userResponse.user;
designerNewsPrefs.setLoggedInUser(user);
Toast confirmLogin = new Toast(getApplicationContext());
View v = LayoutInflater.from(DesignerNewsLogin.this).inflate(R.layout.toast_logged_in_confirmation, null, false);
((TextView) v.findViewById(R.id.name)).setText(user.display_name);
// need to use app context here as the activity will be destroyed shortly
Glide.with(getApplicationContext()).load(user.portrait_url).placeholder(R.drawable.avatar_placeholder).transform(new CircleTransform(getApplicationContext())).into((ImageView) v.findViewById(R.id.avatar));
v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
confirmLogin.setView(v);
confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
confirmLogin.setDuration(Toast.LENGTH_LONG);
confirmLogin.show();
}
@Override
public void failure(RetrofitError error) {
Log.e(getClass().getCanonicalName(), error.getMessage(), error);
}
});
}
use of retrofit.client.Response in project sbt-android by scala-android.
the class DribbbleShot method postComment.
public void postComment(View view) {
if (dribbblePrefs.isLoggedIn()) {
if (TextUtils.isEmpty(enterComment.getText()))
return;
enterComment.setEnabled(false);
dribbbleApi.postComment(shot.id, enterComment.getText().toString().trim(), new retrofit.Callback<Comment>() {
@Override
public void success(Comment comment, Response response) {
loadComments();
enterComment.getText().clear();
enterComment.setEnabled(true);
}
@Override
public void failure(RetrofitError error) {
enterComment.setEnabled(true);
}
});
} else {
Intent login = new Intent(DribbbleShot.this, DribbbleLogin.class);
login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR, ContextCompat.getColor(this, R.color.background_light));
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(DribbbleShot.this, postComment, getString(R.string.transition_dribbble_login));
startActivityForResult(login, RC_LOGIN_COMMENT, options.toBundle());
}
}
use of retrofit.client.Response in project halyard by spinnaker.
the class DistributedDeployer method disableOrcaServerGroups.
private <T extends Account> Set<Integer> disableOrcaServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Orca, T> orcaService, RunningServiceDetails runningOrcaDetails) {
Map<Integer, List<RunningServiceDetails.Instance>> instances = runningOrcaDetails.getInstances();
List<Integer> existingVersions = new ArrayList<>(instances.keySet());
existingVersions.sort(Integer::compareTo);
Map<String, String> disableRequest = new HashMap<>();
Set<Integer> result = new HashSet<>();
disableRequest.put("enabled", "false");
List<Integer> disabledVersions = existingVersions.subList(0, existingVersions.size() - 1);
for (Integer version : disabledVersions) {
try {
for (RunningServiceDetails.Instance instance : instances.get(version)) {
log.info("Disabling instance " + instance.getId());
Orca orca = orcaService.connectToInstance(details, runtimeSettings, orcaService.getService(), instance.getId());
orca.setInstanceStatusEnabled(disableRequest);
}
result.add(version);
} catch (RetrofitError e) {
Response response = e.getResponse();
if (response == null) {
log.warn("Unexpected error disabling orca", e);
} else if (response.getStatus() == 400 && ((Map) e.getBodyAs(Map.class)).containsKey("discovery")) {
log.info("Orca instance is managed by eureka");
result.add(version);
} else {
log.warn("Orca version doesn't support explicit disabling of instances", e);
}
}
}
Set<Integer> unknownVersions = disabledVersions.stream().filter(i -> !result.contains(i)).collect(Collectors.toSet());
if (unknownVersions.size() > 0) {
log.warn("There are existing orca server groups that cannot be explicitly disabled, we will have to wait for these to drain work");
}
return unknownVersions;
}
use of retrofit.client.Response in project halyard by spinnaker.
the class DistributedDeployer method reapRoscoServerGroups.
private <T extends Account> void reapRoscoServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Rosco, T> roscoService) {
if (runtimeSettings.getServiceSettings(roscoService.getService()).getSkipLifeCycleManagement()) {
return;
}
ServiceSettings roscoSettings = runtimeSettings.getServiceSettings(roscoService.getService());
Rosco.AllStatus allStatus;
try {
Rosco rosco = roscoService.connectToPrimaryService(details, runtimeSettings);
allStatus = rosco.getAllStatus();
} catch (RetrofitError e) {
boolean enabled = roscoSettings.getEnabled() != null && roscoSettings.getEnabled();
if (enabled) {
throw new HalException(Problem.Severity.FATAL, "Rosco is enabled, and no connection to rosco could be established: " + e, e);
}
Response response = e.getResponse();
if (response == null) {
throw new IllegalStateException("Unknown connection failure: " + e, e);
}
// 404 when the service couldn't be found, 503 when k8s couldn't establish a connection
if (response.getStatus() == 404 || response.getStatus() == 503) {
log.info("Rosco is not enabled, and there are no server groups to reap");
return;
} else {
throw new HalException(Problem.Severity.FATAL, "Rosco is not enabled, but couldn't be connected to for unknown reason: " + e, e);
}
}
RunningServiceDetails roscoDetails = roscoService.getRunningServiceDetails(details, runtimeSettings);
Set<String> activeInstances = new HashSet<>();
allStatus.getInstances().forEach((s, e) -> {
if (e.getStatus().equals(Rosco.Status.RUNNING)) {
String[] split = s.split("@");
if (split.length != 2) {
log.warn("Unsupported rosco status format");
return;
}
String instanceId = split[1];
activeInstances.add(instanceId);
}
});
Map<Integer, Integer> executionsByServerGroupVersion = new HashMap<>();
roscoDetails.getInstances().forEach((s, is) -> {
int count = is.stream().reduce(0, (c, i) -> c + (activeInstances.contains(i) ? 1 : 0), (a, b) -> a + b);
executionsByServerGroupVersion.put(s, count);
});
// Omit the last deployed roscos from being deleted, since they are kept around for rollbacks.
List<Integer> allRoscos = new ArrayList<>(executionsByServerGroupVersion.keySet());
allRoscos.sort(Integer::compareTo);
cleanupServerGroups(details, roscoService, roscoSettings, executionsByServerGroupVersion, allRoscos);
}
use of retrofit.client.Response in project glasquare by davidvavra.
the class CheckInActivity method checkIn.
private void checkIn() {
final String venueId = getIntent().getStringExtra(EXTRA_VENUE_ID);
final Location location = LocationUtils.getLastLocation();
final String ll = LocationUtils.getLatLon(location);
int accuracy = (int) location.getAccuracy();
int altitude = (int) location.getAltitude();
showProgress(R.string.checking_in);
showCheckInInfo();
String broadcast = getBroadcast();
Api.get().create(CheckIns.class).add(venueId, ll, mShout, broadcast, accuracy, altitude, new Callback<CheckIns.CheckInResponse>() {
@Override
public void success(final CheckIns.CheckInResponse checkInResponse, Response response) {
mCheckInResponse = checkInResponse;
if (mAddingPhoto) {
ImageUtils.processPictureWhenReady(CheckInActivity.this, mPhoto, new ImageUtils.OnPictureReadyListener() {
@Override
public void onPictureReady() {
new BaseAsyncTask() {
@Override
public void inBackground() {
ImageUtils.resize(mPhoto);
}
@Override
public void postExecute() {
addPhoto();
}
}.start();
}
});
} else {
showCheckInComplete();
}
}
@Override
public void failure(RetrofitError retrofitError) {
if (!Auth.handle(CheckInActivity.this, retrofitError)) {
showError(R.string.error_please_try_again);
}
}
});
}
Aggregations