In the NebulaRnD.TwilioServer project there is a folder called HttpClient. This folder has a TwilioRestClient.cs code module. The TwilioRestClient class in that module has a large number of methods for all of the various requests that can be made to the Twilio server. Examples include:
- GetPhoneCalls returns a PhoneCallList with all calls for the current/default Account
- GetPhoneCalls(accountSid) overload returns calls for a non-default Account
- GetPhoneCalls(PhoneCallFilter) returns specific calls
- GetPhoneCallsForSid returns all calls associated with the provided call SID
- GetPhoneCallSegment(callSid, callSegmentSid) returns data for a single phone call
Here are other assorted methods in this class:
- PlaceCall initiates a new call and returns a PhoneCall object
- GetRecordings returns a RecordingList
- DeleteRecordingForSid deletes a specific recording from the Twilio server
- GetNotifications retrieves a NotificationList, with overloads for filtering
- SendSMS has a few overloads providing different ways to send a text message
- SetAccount allows for changing various Twilio account settings
- GetOutgoingCallerIds retrieves registered outgoing phone numbers for any authorized account
More methods will be added to the TwilioRestClient class based on requests posted to the Issue Tracker.
Most of the methods are similar:
- They first check to make sure there is an Account SID.
- Then they make sure there is an Auth Token.
- Then they begin building a URL using constants.
- The URL is then sent to method CreateGetRequest, CreatePutRequest, CreateDeleteRequest, or others.
- The result is an HttpWebRequest object.
- The request is passed to the CompleteRequest method, along with a delegate that handles parsing of the response.
- The delegate essentially de-serializes the XML response coming back from Twilio, casting the response into an appropriate Components object.
The delegates are similar but there are many patterns. A #region is in the TwilioRestClass with description "Examples for processing CompleteRequest". Examples from that commented out code may serve as a base for new methods added to this class.
- This class will certainly need new methods for some core functionality to answer questions like "how do I get the 'foo' data from the account?".
- New methods may need to be created to overload existing CreatePutRequest, CreateDeleteRequest, etc.
- Twilio may return an unexpected HttpStatusCode in the HttpWebResponse for some calls, and enhancements will need to be made to handle them.
- Errors aren't passed up to the client application. Enhancements will need to be made for this. Exception handling is at an absolute minimum in this class. See the #region "Errors and Exceptions".
The core of this code came from the Drop.io API
code library. The issues above should be addressed in that library as well.