Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert CallerIdValidation to inherit from InstanceResource

  • Loading branch information...
commit 53ff9878f2cdc04aa6d24da68488a1c7745326a1 1 parent 4ffbffc
Kevin Burke authored
View
40 src/main/java/com/twilio/sdk/resource/InstanceResource.java
@@ -12,7 +12,7 @@
* The Class InstanceResource.
*/
public abstract class InstanceResource extends Resource {
-
+
/** The properties. */
private Map<String, Object> properties;
@@ -38,26 +38,26 @@ public InstanceResource(TwilioRestClient client,
this.properties = new HashMap<String, Object>(properties);
this.setLoaded(true);
}
-
- private Object getAndLoadIfNecessary(String name) {
- Object prop = properties.get(name);
-
- if (prop == null && !this.isLoaded()) {
- try {
- this.load(new HashMap<String, String>());
- return properties.get(name);
- } catch (TwilioRestException e) {
- throw new RuntimeException(e);
- }
- }
- return prop;
- }
+
+ private Object getAndLoadIfNecessary(String name) {
+ Object prop = properties.get(name);
+
+ if (prop == null && !this.isLoaded()) {
+ try {
+ this.load(new HashMap<String, String>());
+ return properties.get(name);
+ } catch (TwilioRestException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return prop;
+ }
/**
* Gets the property.
*
* @param name the name
- * @return the property,
+ * @return the property,
* or null if it doesn't exist or is NULL in the response
*/
public String getProperty(String name) {
@@ -82,10 +82,10 @@ protected Object getObject(String name) {
throw new IllegalArgumentException("Property " + name
+ " does not exist");
}
-
+
return prop;
}
-
+
/**
* Sets the property as an Object
@@ -97,7 +97,7 @@ protected void setProperty(String name, Object value) {
properties.put(name, value);
}
-
+
/**
* Update.
*
@@ -107,7 +107,7 @@ protected void setProperty(String name, Object value) {
public void update(Map<String, String> params) throws TwilioRestException {
this.getClient().safeRequest(this.getResourceLocation(), "POST", params);
}
-
+
/* (non-Javadoc)
* @see com.twilio.sdk.resource.Resource#parseResponse(com.twilio.sdk.TwilioRestResponse)
*/
View
74 src/main/java/com/twilio/sdk/resource/instance/CallerIdValidation.java
@@ -3,26 +3,78 @@
import java.util.HashMap;
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;
+
+public class CallerIdValidation extends InstanceResource {
+
+ /** The Constant SID_PROPERTY. */
+ private static final String SID_PROPERTY = "sid";
-public class CallerIdValidation {
-
/** The properties. */
private Map<String, Object> properties;
-
+
/** The json keys. */
private boolean jsonKeys = true;
-
+
+ public CallerIdValidation(TwilioRestClient client) {
+ super(client);
+ }
+
+ public CallerIdValidation(TwilioRestClient client, String sid) {
+ super(client);
+ if (sid == null) {
+ throw new IllegalStateException("The Sid for a CallerId cannot be null");
+ }
+ this.setProperty(SID_PROPERTY, sid);
+ }
+
+ public CallerIdValidation(TwilioRestClient client, Map<String, Object> properties) {
+ super(client, properties);
+ }
+
/**
* Instantiates a new caller id validation.
*
- * @param response the response
+ * @param response the json API response
*/
- public CallerIdValidation(TwilioRestResponse response) {
+ public CallerIdValidation(TwilioRestClient client, TwilioRestResponse response) {
+ super(client);
this.properties = new HashMap<String, Object>(response.toMap());
this.jsonKeys = response.isJson();
}
-
+
+ /* (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() + "/OutgoingCallerIds/" +
+ this.getSid() + extension;
+ }
+
+ /**
+ * Gets the sid
+ *
+ * @return the sid
+ */
+ public String getSid() {
+ return getProperty("sid");
+ }
+
/**
* Gets the validation code.
*
@@ -33,10 +85,10 @@ public String getValidationCode() {
if (this.jsonKeys) {
return getProperty("validation_code");
}
-
+
return getProperty("ValidationCode");
}
-
+
/**
* Gets the phone number.
*
@@ -47,10 +99,10 @@ public String getPhoneNumber() {
if (this.jsonKeys) {
return getProperty("phone_number");
}
-
+
return getProperty("PhoneNumber");
}
-
+
/**
* Gets the property.
*
View
6 src/main/java/com/twilio/sdk/resource/list/OutgoingCallerIdList.java
@@ -13,7 +13,7 @@
// TODO: Auto-generated Javadoc
/**
* The Class OutgoingCallerIdList.
- *
+ *
* For more information see <a href="http://www.twilio.com/docs/api/rest/outgoing-caller-ids">http://www.twilio.com/docs/api/rest/outgoing-caller-ids</a>
*/
public class OutgoingCallerIdList extends ListResource<OutgoingCallerId>
@@ -64,13 +64,13 @@ protected OutgoingCallerId makeNew(TwilioRestClient client,
protected String getListKey() {
return "outgoing_caller_ids";
}
-
+
/* (non-Javadoc)
* @see com.twilio.sdk.resource.factory.OutgoingCallerIdFactory#create(java.util.Map)
*/
public CallerIdValidation create(Map<String, String> params) throws TwilioRestException {
TwilioRestResponse response = this.getClient().safeRequest(
this.getResourceLocation(), "POST", params);
- return new CallerIdValidation(response);
+ return new CallerIdValidation(this.getClient(), response);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.