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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.gson.JsonObjectcleanForNetworkJSONtoJSON(com.google.gson.JsonObject raw) Simple utility method to clean Json Objects for transmission.static StringcleanForNetworkRaw(String raw) Simple utility method to clean raw strings up for transmission over a networkstatic 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 customUnsupportedRobotWorldCommandexceptionstatic 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 customTooManyOfYouExceptionexceptionstatic com.google.gson.JsonObjectOverload to send back a specific error message for the customUnsupportedRobotWorldCommandexceptionstatic com.google.gson.JsonObjectOverload to send back a specific error message for the customTooManyOfYouExceptionexceptionstatic com.google.gson.JsonObjectok(com.google.gson.JsonObject data) Take in a JsonObject and return and OK message as a Stringstatic Commandstatic StringwebAPIOut(com.google.gson.JsonObject data) Utility method to send a cleaned JSON object over the HTTP web layer
-
Field Details
-
DELIMITER
Custom delimiter used to send multiple new line characters over the network.
-
-
Constructor Details
-
ServerAPI
public ServerAPI()
-
-
Method Details
-
parsejson
-
webAPIOut
Utility method to send a cleaned JSON object over the HTTP web layer -
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 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 customTooManyOfYouExceptionexception- 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 customTooManyOfYouExceptionexception- 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.domain.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
-
cleanForNetworkRaw
Simple utility method to clean raw strings up for transmission over a networkThis involves replacing \n characters with a custom delimiter
- Parameters:
raw- the unclean string- Returns:
- the cleaned string
-
cleanForNetworkJSONtoJSON
public static com.google.gson.JsonObject cleanForNetworkJSONtoJSON(com.google.gson.JsonObject raw) Simple utility method to clean Json Objects for transmission. Shallow call tocleanForNetworkRaw(String)- Parameters:
raw- the unclean JSON- Returns:
- the cleaned JSON
-