com.jelastic.api.users.response.ApiTokenResponse Maven / Gradle / Ivy
The newest version!
/*Server class MD5: 8eecd81fdabd72d68d69ba6a5ae1b098*/
package com.jelastic.api.users.response;
import com.jelastic.api.Response;
import com.jelastic.api.core.persistence.entity.ApiToken;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class ApiTokenResponse extends Response {
private final static String TOKEN = "token";
ApiToken token;
public ApiTokenResponse() {
super(Response.OK);
}
public ApiTokenResponse(ApiToken token) {
super(Response.OK);
this.token = token;
}
public ApiTokenResponse(int result, String error) {
super(result, error);
}
public ApiToken getToken() {
return token;
}
public ApiToken getApiToken() {
return token;
}
public void setToken(ApiToken token) {
this.token = token;
}
public JSONObject toJSON() {
JSONObject json = super.toJSON();
try {
if (token != null) {
json.put("token", token.toJSON());
}
} catch (Exception e) {
e.printStackTrace();
try {
json.put("result", Response.ERROR_UNKNOWN).put("error", e.toString());
} catch (JSONException ex) {
}
}
return json;
}
@Override
public ApiTokenResponse _fromJSON(JSONObject json) throws JSONException {
super._fromJSON(json);
if (json.has(TOKEN)) {
this.token = new ApiToken()._fromJSON(json.getJSONObject(TOKEN));
}
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy