@Override
  public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) {
    Map<String, String> errParams = new HashMap<String, String>();
    int responseCode = 0;
    String responseBody = "";
    TokenType deviceTokenType;

    LoggerService logger = serviceProvider.getLoggerService(SMPushRegisterDevice.class);  //Log to the StackMob Custom code console
    logger.debug("Start register device token");

    String deviceToken = request.getParams().get("device_token");  // DEVICE TOKEN should be YOUR mobile device token
    String tokenType = request.getParams().get("token_type");  // TOKEN TYPE should be YOUR device type (ios / gcm)
    logger.debug("Device token: " + deviceToken + ", " + "Token Type: " + tokenType);

    if (Util.isEmpty(deviceToken)) {
      return Util.badRequestResponse(errParams, "the device token passed was null or empty."); // http 400 - bad request
    }

    if (Util.isEmpty(tokenType)) {
      return Util.badRequestResponse(errParams, "the token type passed was null or empty."); // http 400 - bad request
    }

    // Check if the input token type was one of the 3 supported services
    if (tokenType.equals("ios")) {
      deviceTokenType = TokenType.iOS;
    } else if  (tokenType.equals("gcm")) {
      deviceTokenType = TokenType.AndroidGCM;
    } else if  (tokenType.equals("c2dm")) {
      deviceTokenType = TokenType.Android;
    } else {
      errParams.put("error", "the token type passed was not valid, must be ios, c2dm or gcm");
      return Util.badRequestResponse(errParams); // http 400 - bad request
    }

    TokenAndType token = new TokenAndType(deviceToken, deviceTokenType); // token type can be iOS or GCM
    String username = request.getParams().get("user_name"); // (OPTIONAL) USERNAME to register a token to a specific username

    try {
      PushService service = serviceProvider.getPushService();
      service.registerTokenForUser(username, token);
      responseCode = HttpURLConnection.HTTP_OK;
      responseBody = "token saved";
    } catch (ServiceNotActivatedException e){
      return Util.internalErrorResponse("service not activated", e, errParams);
    } catch (DatastoreException dse) {
      return Util.internalErrorResponse("datastore_exception", dse, errParams);  // http 500 - internal server error
    }

    logger.debug("End register device token code");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("response_body", responseBody);

    return new ResponseToProcess(responseCode, map);
  }