📄 apiresponse.java
字号:
package com.bv.api.response;import com.bv.api.Error;/** * A structure to hold the information returned by the server in response to an <code>execute()</code> call. * @author C. Oattes, Kris Nobes */public class ApiResponse { protected Error error; protected String response = null; protected String version; /** * Create a "successful" API response. */ public ApiResponse() { this.error = Error.NoError; this.response = ""; } /** * Create a "successful" API response. * @param response The response from the server. */ public ApiResponse(String response) { this.error = Error.NoError; this.response = response; } /** * Create an ApiResponse when the API call failed. * @param error The error that occured. */ public ApiResponse(Error error) { this.response = ""; this.error = error; } /** * Create an ApiResponse when the API call failed. <code>Response</code> is the response from the server. * @param error The error that occured. * @param response The response from the server. */ public ApiResponse(Error error, String response) { this.response = response; this.error = error; } /** * Check whether the API response was successful. * @return <code>true</code> if the API call was successful, otherwise, <code>false</code> */ public boolean isSuccess() { if(error.equals(Error.NoError)) { return true; } else { return false; } } /** * Get the server response. * @return The server response to the API Call. */ public String getResponse() { return response; } /** * Get the Error associated with the ApiResponse. * @return <code>{@link Error}.NoError</code> If the call was successful, otherwise, the appropriate {@link Error} */ public Error getError() { return error; } /** * Get a String representation of this ApiResponse. * This will be the empty string if the error is set to <code>{@link Error}.NoError</code>, otherwise the error code, error message & response if present. * @return The string representation of this API Response. */ public String toString() { String returnString = ""; if (error == Error.NoError) { // Leave the return string empty } else { returnString = "Error " + error.getCode() + ": " + error.getMessage(); if (isSetResponse()) { returnString += " " + getResponse(); } } return returnString; } /** * Check whether the response string was set * @return If the response is set (i.e. not null or empty string) */ private boolean isSetResponse() { return (!response.equals("") && response != null); } /** * Generate a generic ApiResponse, with "response" set to whatever is returned by the server * @param response * @return An ApiResponse */ public ApiResponse processResponse(String response) { return new ApiResponse(response); } /** * Set the response string for the ApiResponse * @param response The response from the server */ protected void setResponse(String response) { this.response = response; } /** * Set the error for the Api response * @param err The Error object */ protected void setError(Error err) { this.error = err; } /** * Set the API version for the ApiResponse * @param version The Api Version */ protected void setVersion(String version) { this.version = version; } /** * Return the API Version * @return The api version */ public String getVersion() { return version; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -