com.kallasoft.smugmug.api.json
Class AbstractResponse

java.lang.Object
  extended by com.kallasoft.smugmug.api.json.AbstractResponse
Direct Known Subclasses:
Anonymously.AnonymouslyResponse, ApplyWatermark.ApplyWatermarkResponse, ChangePosition.ChangePositionResponse, ChangeSettings.ChangeSettingsResponse, ChangeSettings.ChangeSettingsResponse, ChangeSettings.ChangeSettingsResponse, Create.CreateResponse, Create.CreateResponse, Create.CreateResponse, Create.CreateResponse, Delete.DeleteResponse, Delete.DeleteResponse, Delete.DeleteResponse, Delete.DeleteResponse, Delete.DeleteResponse, Get.GetResponse, Get.GetResponse, Get.GetResponse, Get.GetResponse, Get.GetResponse, GetAll.GetAllResponse, GetEXIF.GetEXIFResponse, GetInfo.GetInfoResponse, GetInfo.GetInfoResponse, GetStats.GetStatsResponse, GetStats.GetStatsResponse, GetTransferStats.GetTransferStatsResponse, GetTree.GetTreeResponse, GetURLs.GetURLsResponse, Logout.LogoutResponse, Rename.RenameResponse, Rename.RenameResponse, ReSort.ReSortResponse, Upload.UploadResponse, UploadFromURL.UploadFromURLResponse, UploadHTTPPut.UploadHTTPPutResponse, WithHash.WithHashResponse, WithPassword.WithPasswordResponse

public abstract class AbstractResponse
extends Object

A class that provides the base implementation of a response from the SmugMug JSON API methods.

For all of the methods defined in the SmugMug JSON API, all responses share the same fundamental structure of:

This base implementation of a response can take a String representing the JSON response, and parse out all this information, optionally creating the AbstractResponse.Error object if an error occurred, otherwise leaving it null.

To quickly check if the AbstractResponse you are dealing with represents an error, you can call the isError() method.

All AbstractResponse implementations in this API extend this base class and provide additional properties and parsing rules depending on the format of the reply for each particular request.

Author:
Riyad Kalla

Nested Class Summary
 class AbstractResponse.Error
          Class used to represent an error from a SmugMug JSON API response.
 
Constructor Summary
AbstractResponse(String responseText)
          Construct a response that parses it's values out of the given responseText that represents the JSON reply.
 
Method Summary
 AbstractResponse.Error getError()
          Used to get the AbstractResponse.Error associated with this response if one occurred, otherwise this will return null.
 String getMethod()
          Used to get the "method" value from the SmugMug JSON API reply.
 String getStat()
          Used to get the "stat" value from the SmugMug JSON API reply.
 boolean isError()
          Used to determine if this response represents an error or not.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractResponse

public AbstractResponse(String responseText)
                 throws RuntimeJSONException
Construct a response that parses it's values out of the given responseText that represents the JSON reply.

Parameters:
responseText - The text of the JSON reply. If the text is null this method simply returns.
Throws:
RuntimeJSONException - if an error occurs while parsing the JSON response text.
Method Detail

toString

public String toString()
Overrides:
toString in class Object

isError

public boolean isError()
Used to determine if this response represents an error or not.

Returns:
true if an error occurred and this response contains it's error code and message, otherwise returns false.

getStat

public String getStat()
Used to get the "stat" value from the SmugMug JSON API reply.

This should either be "ok" or "fail".

Returns:
the "stat" value from the SmugMug JSON API reply.

getMethod

public String getMethod()
Used to get the "method" value from the SmugMug JSON API reply.

This is the method that was called, e.g. "smugmug.login.withPassword".

Returns:
the "method" value from the SmugMug JSON API reply.

getError

public AbstractResponse.Error getError()
Used to get the AbstractResponse.Error associated with this response if one occurred, otherwise this will return null.

Returns:
the AbstractResponse.Error associated with this response if one occurred, otherwise this will return null.