All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.easimart.EasimartConfigController Maven / Gradle / Ivy

package co.easimart;

import org.json.JSONObject;

import bolts.Continuation;
import bolts.Task;

/** package */ class EasimartConfigController {

  private EasimartCurrentConfigController currentConfigController;
  private final EasimartHttpClient restClient;

  public EasimartConfigController(EasimartHttpClient restClient,
                                  EasimartCurrentConfigController currentConfigController) {
    this.restClient = restClient;
    this.currentConfigController = currentConfigController;
  }
  /* package */ EasimartCurrentConfigController getCurrentConfigController() {
    return currentConfigController;
  }

  public Task getAsync(String sessionToken) {
    final EasimartRESTCommand command = EasimartRESTConfigCommand.fetchConfigCommand(sessionToken);
    command.enableRetrying();
    return command.executeAsync(restClient).onSuccessTask(new Continuation>() {
      @Override
      public Task then(Task task) throws Exception {
        JSONObject result = task.getResult();

        final EasimartConfig config = new EasimartConfig(result, EasimartDecoder.get());
        return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation() {
          @Override
          public EasimartConfig then(Task task) throws Exception {
            return config;
          }
        });
      }
    });
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy