@Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    if (action.equals("login")) {
      executeLogin(args, callbackContext);
      return true;

    } else if (action.equals("logout")) {
      if (hasAccessToken()) {
        LoginManager.getInstance().logOut();
        callbackContext.success();
      } else {
        callbackContext.error("No valid session found, must call init and login before logout.");
      }
      return true;

    } else if (action.equals("getLoginStatus")) {
      callbackContext.success(getResponse());
      return true;

    } else if (action.equals("getAccessToken")) {
      if (hasAccessToken()) {
        callbackContext.success(AccessToken.getCurrentAccessToken().getToken());
      } else {
        // Session not open
        callbackContext.error("Session not open.");
      }
      return true;

    } else if (action.equals("logEvent")) {
      executeLogEvent(args, callbackContext);
      return true;

    } else if (action.equals("logPurchase")) {
      /*
       * While calls to logEvent can be made to register purchase events,
       * there is a helper method that explicitly takes a currency indicator.
       */
      if (args.length() != 2) {
        callbackContext.error("Invalid arguments");
        return true;
      }
      int value = args.getInt(0);
      String currency = args.getString(1);
      logger.logPurchase(BigDecimal.valueOf(value), Currency.getInstance(currency));
      callbackContext.success();
      return true;

    } else if (action.equals("showDialog")) {
      executeDialog(args, callbackContext);
      return true;

    } else if (action.equals("graphApi")) {
      executeGraph(args, callbackContext);

      return true;
    } else if (action.equals("appInvite")) {
      executeAppInvite(args, callbackContext);

      return true;
    }
    return false;
  }