Skip to content

Instantly share code, notes, and snippets.

@ktoraskartwilio
Created November 21, 2013 22:32
Show Gist options
  • Save ktoraskartwilio/7590982 to your computer and use it in GitHub Desktop.
Save ktoraskartwilio/7590982 to your computer and use it in GitHub Desktop.
Drop DID's from an account
/*
* This class gets the list of IncomingPhoneNumbers(DID's)
* for an account. Based on the cut off date, the filtered
* DID's are deleted from this account
*
*/
public class DropDID {
public static String TWILIO_SE_ACCOUNT_SID;
public static String TWILIO_SE_AUTH_TOKEN;
public static String TWILIO_CUSTOMER_ACCOUNT_SID;
public static void main(String args[]) {
TWILIO_SE_ACCOUNT_SID = System.getenv("TWILIO_SE_ACCOUNT_SID");
TWILIO_SE_AUTH_TOKEN = System.getenv("TWILIO_SE_AUTH_TOKEN");
TWILIO_CUSTOMER_ACCOUNT_SID = System
.getenv("TWILIO_CUSTOMER_ACCOUNT_SID");
// Initialize Twilio REST Client
TwilioRestClient client = TwilioRestClientFactory
.createTwilioRestClient(TWILIO_SE_ACCOUNT_SID,
TWILIO_SE_AUTH_TOKEN, TWILIO_CUSTOMER_ACCOUNT_SID);
Account acc = client.getAccount();
// get list of IncomingPhoneNumbers for this Account (DID's)
IncomingPhoneNumberList incomingPhnNumList = acc.getIncomingPhoneNumbers();
Iterator<IncomingPhoneNumber> incomingPhnNumItr = incomingPhnNumList.iterator();
// iterate through the list of IncomingPhoneNumbers
while(incomingPhnNumItr.hasNext()) {
IncomingPhoneNumber incomingPhnNum = incomingPhnNumItr.next();
Date dateUpdated = incomingPhnNum.getDateUpdated();
//compare DateUpdated with the cutoff date. DateUpdated = the date on which this DID was last used
// call delete() to delete the DID from this account
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment