Skip to content

Commit

Permalink
Adding connect app resources and fixing create methods to use safeReq…
Browse files Browse the repository at this point in the history
…uest
  • Loading branch information
frankstratton committed Sep 26, 2011
1 parent 47fc332 commit dc1d9ca
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/java/com/twilio/sdk/resource/InstanceResource.java
Expand Up @@ -72,6 +72,17 @@ public String getProperty(String name) {
+ " is an object. Use getOjbect() instead.");
}

protected Object getObject(String name) {
Object prop = properties.get(name);

if (prop == null) {
throw new IllegalArgumentException("Property " + name
+ " does not exist");
}

return prop;
}

/**
* Sets the property.
*
Expand Down
59 changes: 59 additions & 0 deletions src/java/com/twilio/sdk/resource/instance/Account.java
Expand Up @@ -14,9 +14,11 @@
import com.twilio.sdk.resource.factory.OutgoingCallerIdFactory;
import com.twilio.sdk.resource.factory.SmsFactory;
import com.twilio.sdk.resource.list.ApplicationList;
import com.twilio.sdk.resource.list.AuthorizedConnectAppList;
import com.twilio.sdk.resource.list.AvailablePhoneNumberList;
import com.twilio.sdk.resource.list.CallList;
import com.twilio.sdk.resource.list.ConferenceList;
import com.twilio.sdk.resource.list.ConnectAppList;
import com.twilio.sdk.resource.list.IncomingPhoneNumberList;
import com.twilio.sdk.resource.list.NotificationList;
import com.twilio.sdk.resource.list.OutgoingCallerIdList;
Expand Down Expand Up @@ -669,4 +671,61 @@ public Transcription getTranscription(String sid) {
tr.setRequestAccountSid(this.getRequestAccountSid());
return tr;
}


/**
* Gets the connect app list with the given filters
*
* {@see <a href="http://www.twilio.com/docs/api/rest/connect-apps">http://www.twilio.com/docs/api/rest/connect-apps</a>}
*
* @param filters
* the filters
* @return the connect app list
*/
public ConnectAppList getConnectApps(Map<String, String> filters) {
ConnectAppList list = new ConnectAppList(this.getClient(),
filters);
list.setRequestAccountSid(this.getRequestAccountSid());
return list;
}

/**
* Get a given connect app instance by sid
* @param sid The 34 character sid starting with CN
* @return the connect app
*/
public ConnectApp getConnectApp(String sid) {
ConnectApp cn = new ConnectApp(this.getClient(), sid);
cn.setRequestAccountSid(this.getRequestAccountSid());
return cn;
}

/**
* Gets the connect app list with the given filters
*
* {@see <a href="http://www.twilio.com/docs/api/rest/connect-apps">http://www.twilio.com/docs/api/rest/connect-apps</a>}
*
* @param filters
* the filters
* @return the connect app list
*/
public AuthorizedConnectAppList getAuthorizedConnectApps(Map<String, String> filters) {
AuthorizedConnectAppList list = new AuthorizedConnectAppList(this.getClient(),
filters);
list.setRequestAccountSid(this.getRequestAccountSid());
return list;
}

/**
* Get a given connect app instance by sid
* @param sid The 34 character sid starting with CN
* @return the connect app
*/
public AuthorizedConnectApp getAuthorizedConnectApp(String sid) {
AuthorizedConnectApp cn = new AuthorizedConnectApp(this.getClient(), sid);
cn.setRequestAccountSid(this.getRequestAccountSid());
return cn;
}


}
178 changes: 178 additions & 0 deletions src/java/com/twilio/sdk/resource/instance/AuthorizedConnectApp.java
@@ -0,0 +1,178 @@
package com.twilio.sdk.resource.instance;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.resource.InstanceResource;

/**
* The AuthorizedConnectApps list resource shows all of the Connect Apps that
* you have authorized for your account. Each Connect App corresponds to a
* subaccount within your Twilio account, which acts as that Connect App's
* sandbox. The instance resource shows you the permissions you have granted for
* a Connect App as well as information about the Connect App itself.
*
*
*
* For more information see {@see <a
* href="http://www.twilio.com/docs/api/rest/authorized-connect-apps"
* >http://www.twilio.com/docs/api/rest/authorized-connect-apps}
*/
public class AuthorizedConnectApp extends InstanceResource {

/** The Constant SID_PROPERTY. */
private static final String SID_PROPERTY = "connect_app_sid";

/** The Constant DATE_UPDATED_PROPERTY. */
private static final String DATE_UPDATED_PROPERTY = "date_updated";

/** The Constant DATE_CREATED_PROPERTY. */
private static final String DATE_CREATED_PROPERTY = "date_created";

/** The Constant FRIENDLY_NAME_PROPERTY. */
private static final String FRIENDLY_NAME_PROPERTY = "friendly_name";

/**
* Instantiates a new application.
*
* @param client
* the client
*/
public AuthorizedConnectApp(TwilioRestClient client) {
super(client);
}

/**
* Instantiates a new application.
*
* @param client
* the client
* @param sid
* the sid
*/
public AuthorizedConnectApp(TwilioRestClient client, String sid) {
super(client);
this.setProperty(SID_PROPERTY, sid);
}

/**
* Instantiates a new application.
*
* @param client
* the client
* @param properties
* the properties
*/
public AuthorizedConnectApp(TwilioRestClient client,
Map<String, Object> properties) {
super(client, properties);
}

/*
* (non-Javadoc)
*
* @see com.twilio.sdk.resource.Resource#getResourceLocation()
*/
@Override
protected String getResourceLocation() {
return "/" + TwilioRestClient.DEFAULT_VERSION + "/Accounts/"
+ this.getRequestAccountSid() + "/AuthorizedConnectApps/" + this.getSid()
+ ".json";
}

/*
* Property getters
*/
/**
* Gets the sid.
*
* @return the sid
*/
public String getSid() {
return this.getProperty(SID_PROPERTY);
}

/**
* Gets the friendly name.
*
* @return the friendly name
*/
public String getFriendlyName() {
return this.getProperty(FRIENDLY_NAME_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_PROPERTY));
} 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_PROPERTY));
} catch (ParseException e) {
return null;
}
}

/**
* Gets the account sid.
*
* @return the account sid
*/
public String getAccountSid() {
return this.getProperty("account_sid");
}

/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
return this.getProperty("connect_app_description");
}

/**
* Gets the company name.
*
* @return the company name
*/
public String getCompanyName() {
return this.getProperty("connect_app_company_name");
}

/**
* Gets the homepage url.
*
* @return the homepage url
*/
public String getHomepageUrl() {
return this.getProperty("connect_app_homepage_url");
}

public List<String> getPermissions() {
Object obj = this.getObject("permissions");
return (List<String>) obj;
}
}

0 comments on commit dc1d9ca

Please sign in to comment.