Package za.co.wethinkcode.robots.api
Class ServerAPI
java.lang.Object
za.co.wethinkcode.robots.api.ServerAPI
The Server API class encapsulates all behaviour related to outputting Command Results to the Client
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.gson.JsonObjectReturn an Error From an exceptionstatic com.google.gson.JsonObjectTakes in an error message and wraps into a JSON structured errorstatic com.google.gson.JsonObjectOverload to send back a specific error message for the customRobotCannotActExceptionstatic com.google.gson.JsonObjectOverload to send back a specific error message for the customUnsupportedRobotWorldCommandexceptionstatic com.google.gson.JsonObjectok(com.google.gson.JsonObject data) Take in a JsonObject and return and OK message as a Stringstatic Command
-
Constructor Details
-
ServerAPI
public ServerAPI()
-
-
Method Details
-
parsejson
-
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
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
Return an Error From an exception- Parameters:
e- the exception being passed in- Returns:
- a JsonObject structured as an error
-
error
Overload to send back a specific error message for the customUnsupportedRobotWorldCommandexception- Parameters:
e- the exception being passed in- Returns:
- a JsonObject structured as an error
-
error
Overload to send back a specific error message for the customRobotCannotActExceptionRobotCannotActExceptionhas an internal constructor forRobotCannotActException.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
-