com.twilio.sdk.resource.instance.Recording 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
Java helper library for Twilio services
package com.twilio.sdk.resource.instance;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.TwilioRestResponse;
import com.twilio.sdk.resource.InstanceResource;
// TODO: Auto-generated Javadoc
/**
* The Class Recording.
*
* For more information see https://www.twilio.com/docs/api/rest/recording
*
*
*/
public class Recording extends InstanceResource {
/** The Constant SID_PROPERTY. */
private static final String SID_PROPERTY = "sid";
/**
* Instantiates a new recording.
*
* @param client the client
*/
public Recording(TwilioRestClient client) {
super(client);
}
/**
* Instantiates a new recording.
*
* @param client the client
* @param sid the sid
*/
public Recording(TwilioRestClient client, String sid) {
super(client);
if (sid == null) {
throw new IllegalStateException("The Sid for a Recording can not be null");
}
this.setProperty(SID_PROPERTY, sid);
}
/**
* Instantiates a new recording.
*
* @param client the client
* @param properties the properties
*/
public Recording(TwilioRestClient client, Map properties) {
super(client, properties);
}
/* (non-Javadoc)
* @see com.twilio.sdk.resource.Resource#getResourceLocation()
*/
@Override
protected String getResourceLocation() {
return this.getResourceLocation(".json");
}
/**
* Gets the resource location.
*
* @param extension the extension
* @return the resource location
*/
protected String getResourceLocation(String extension) {
return "/" + TwilioRestClient.DEFAULT_VERSION + "/Accounts/"
+ this.getRequestAccountSid() + "/Recordings/" + this.getSid()
+ extension;
}
/*
* Property getters
*/
/**
* Gets the sid.
*
* @return the sid
*/
public String getSid() {
return this.getProperty(SID_PROPERTY);
}
/**
* Gets the date created.
*
* @return the date created
*/
public Date getDateCreated() {
SimpleDateFormat format = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z");
try {
return format.parse(this.getProperty("date_created"));
} catch (ParseException e) {
return null;
}
}
/**
* Gets the date updated.
*
* @return the date updated
*/
public Date getDateUpdated() {
SimpleDateFormat format = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss Z");
try {
return format.parse(this.getProperty("date_updated"));
} catch (ParseException e) {
return null;
}
}
/**
* Gets the account sid.
*
* @return the account sid
*/
public String getAccountSid() {
return this.getProperty("account_sid");
}
/**
* Gets the call sid.
*
* @return the call sid
*/
public String getCallSid() {
return this.getProperty("call_sid");
}
/**
* Gets the duration.
*
* @return the duration
*/
public int getDuration() {
return Integer.parseInt(this.getProperty("duration"));
}
/**
* Gets the api version.
*
* @return the api version
*/
public String getApiVersion() {
return this.getProperty("api_version");
}
/**
* Gets the media.
*
* @param extension the extension
* @return the media
*/
public InputStream getMedia(String extension) {
return this.getClient().requestStream(
this.getResourceLocation(extension), "GET", (Map) null);
}
/**
* Delete this Recording
*
* @return true, if successful
* @throws TwilioRestException the twilio rest exception
*/
public boolean delete() throws TwilioRestException {
TwilioRestResponse response = this.getClient().safeRequest(
this.getResourceLocation(), "DELETE", (Map) null);
return !response.isError();
}
}