Class ServerAPI

java.lang.Object
za.co.wethinkcode.robots.api.ServerAPI

public class ServerAPI extends Object
The Server API class encapsulates all behaviour related to outputting Command Results to the Client
  • Constructor Details

    • ServerAPI

      public ServerAPI()
  • Method Details

    • parsejson

      public static Command parsejson(String jsonString)
    • ok

      public static com.google.gson.JsonObject ok(com.google.gson.JsonObject data)
      Take in a JsonObject and return and OK message as a String
      Parameters:
      data - the JSON Object being wrapped in OK
      Returns:
      the wrapped JSON object represented as a string
    • error

      public static com.google.gson.JsonObject error(String message)
      Takes in an error message and wraps into a JSON structured error
      Parameters:
      message - the error message
      Returns:
      the error JSON represented a raw string.
    • error

      public static com.google.gson.JsonObject error(Exception e)
      Return an Error From an exception
      Parameters:
      e - the exception being passed in
      Returns:
      a JsonObject structured as an error
    • error

      public static com.google.gson.JsonObject error(UnsupportedRobotWorldCommand e)
      Overload to send back a specific error message for the custom UnsupportedRobotWorldCommand exception
      Parameters:
      e - the exception being passed in
      Returns:
      a JsonObject structured as an error
    • error

      public static com.google.gson.JsonObject error(RobotCannotActException e)
      Overload to send back a specific error message for the custom RobotCannotActException

      RobotCannotActException has an internal constructor for RobotCannotActException.constructTimeError(za.co.wethinkcode.robots.server.robots.Status, za.co.wethinkcode.robots.server.robots.Robot, za.co.wethinkcode.robots.server.world.World) method.
      This method allows for smarter errors to be sent to client regarding when next they will be able to act.

      Parameters:
      e - the exception being passed in
      Returns:
      a JsonObject structured as an error