Search in sources :

Example 36 with Response

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);
        }
    });
}
Also used : User(io.plaidapp.data.api.designernews.model.User) CircleTransform(io.plaidapp.util.glide.CircleTransform) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) UserResponse(io.plaidapp.data.api.designernews.model.UserResponse) UserResponse(io.plaidapp.data.api.designernews.model.UserResponse) Response(retrofit.client.Response) Toast(android.widget.Toast) DesignerNewsService(io.plaidapp.data.api.designernews.DesignerNewsService) ClientAuthInterceptor(io.plaidapp.data.api.ClientAuthInterceptor) ImageView(android.widget.ImageView) RetrofitError(retrofit.RetrofitError)

Example 37 with Response

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());
    }
}
Also used : Response(retrofit.client.Response) Comment(io.plaidapp.data.api.dribbble.model.Comment) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) RetrofitError(retrofit.RetrofitError) ActivityOptions(android.app.ActivityOptions)

Example 38 with Response

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;
}
Also used : RedisService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RedisService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) LogCollector(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.LogCollector) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) Rosco(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RoscoService.Rosco) Map(java.util.Map) ResolvedConfiguration(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService.ResolvedConfiguration) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Response(retrofit.client.Response) DistributedServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedServiceProvider) Set(java.util.Set) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) Collectors(java.util.stream.Collectors) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) RetrofitError(retrofit.RetrofitError) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) Jedis(redis.clients.jedis.Jedis) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) Collections(java.util.Collections) Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Response(retrofit.client.Response) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) RetrofitError(retrofit.RetrofitError)

Example 39 with Response

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);
}
Also used : HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Response(retrofit.client.Response) Rosco(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RoscoService.Rosco) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) RetrofitError(retrofit.RetrofitError) HashSet(java.util.HashSet)

Example 40 with Response

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);
            }
        }
    });
}
Also used : Response(retrofit.client.Response) CheckIns(cz.destil.glasquare.api.CheckIns) BaseAsyncTask(cz.destil.glasquare.util.BaseAsyncTask) Location(android.location.Location) 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