com.twilio.sdk.resource.Resource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twilio-java-sdk Show documentation
Show all versions of twilio-java-sdk Show documentation
Release Candidate for Next-Gen Twilio Java Helper Library
package com.twilio.sdk.resource;
import com.twilio.sdk.TwilioClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.TwilioRestResponse;
import java.util.Map;
// TODO: Auto-generated Javadoc
/**
* The Class Resource.
*/
public abstract class Resource {
/** The client. */
private C client;
/** The request account sid. */
private String requestAccountSid;
/** The filters. */
protected Map filters;
/**
* Instantiates a new resource.
*
* @param client the client
*/
public Resource(C client) {
this.client = client;
}
/**
* Gets the client.
*
* @return the client
*/
protected C getClient() {
return this.client;
}
/**
* Load.
*
* @param params the params
* @throws TwilioRestException the twilio rest exception
*/
protected void load(Map params) throws TwilioRestException {
String path = getResourceLocation();
TwilioRestResponse response = getClient().safeRequest(path, "GET", params);
parseResponse(response);
loaded = true;
}
/**
* Parses the response.
*
* @param response the response
*/
protected abstract void parseResponse(TwilioRestResponse response);
// flags whether or not the HTTP request to popluate
// this data has occured. We can construct resources
// that are lazily loaded
/** The loaded. */
private boolean loaded;
/**
* Checks if is loaded.
*
* @return true, if is loaded
*/
protected boolean isLoaded() {
return loaded;
}
/**
* Sets the loaded.
*
* @param loaded the new loaded
*/
protected void setLoaded(boolean loaded) {
this.loaded = loaded;
}
// Taken from the request uri, or the request account
/**
* Gets the request account sid.
*
* @return the request account sid
*/
protected String getRequestAccountSid() {
return this.requestAccountSid;
}
/**
* Sets the request account sid.
*
* @param sid the new request account sid
*/
public void setRequestAccountSid(String sid) {
this.requestAccountSid = sid;
}
/**
* Gets the resource location.
*
* @return the resource location
*/
protected abstract String getResourceLocation();
}