All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twilio.sdk.resource.Resource Maven / Gradle / Ivy

There is a newer version: 7.0.0-rc-10
Show newest version
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();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy