Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Checkin
- Loading branch information
Devin Rader
committed
May 10, 2013
1 parent
4aaaae3
commit a65e9ae
Showing
83 changed files
with
6,162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package> | ||
<metadata> | ||
<id>Twilio.WinRT</id> | ||
<version>0.0.1-alpha</version> | ||
<authors>Twilio</authors> | ||
<description>Twilio REST API helper library for Windows Store Apps</description> | ||
<language>en-US</language> | ||
<projectUrl>http://github.com/twilio/twilio-csharp</projectUrl> | ||
<iconUrl>http://www.twilio.com/packages/company/img/logos_downloadable_round.png</iconUrl> | ||
<licenseUrl>https://github.com/twilio/twilio-csharp/blob/master/LICENSE.txt</licenseUrl> | ||
<tags>REST SMS voice telephony phone twilio twiml Windows8 WinRT WinJS</tags> | ||
<dependencies> | ||
<dependency id="RestRT" /> | ||
</dependencies> | ||
<releaseNotes> | ||
</releaseNotes> | ||
</metadata> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
REM tools\nuget.exe update -self | ||
|
||
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /nologo /maxcpucount /nr:true /verbosity:minimal /p:BuildInParallel=true /p:Configuration=Release /p:RestorePackages=true /t:Rebuild src/Twilio.2012.sln | ||
|
||
rd download /s /q | ||
|
||
if not exist download mkdir download | ||
if not exist download\package mkdir download\package | ||
if not exist download\package\twilio.winrt mkdir download\package\twilio.winrt | ||
|
||
if not exist download\package\twilio.winrt\lib mkdir download\package\twilio.winrt\lib | ||
if not exist download\package\twilio.winrt\lib\windows8 mkdir download\package\twilio.winrt\lib\windows8 | ||
|
||
copy LICENSE.txt download | ||
|
||
copy src\Twilio.WinRT\bin\Release\Twilio.winmd download\package\twilio.winrt\lib\windows8\ | ||
copy src\Twilio.WinRT\bin\Release\Twilio.pri download\package\twilio.winrt\lib\windows8\ | ||
|
||
|
||
tools\nuget.exe pack Twilio.WinRT.nuspec -BasePath download\package\twilio.winrt -o download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Twilio.WinRT", "Twilio.WinRT\Twilio.WinRT.csproj", "{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|ARM = Debug|ARM | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|ARM = Release|ARM | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|ARM.ActiveCfg = Debug|ARM | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|ARM.Build.0 = Debug|ARM | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|x64.ActiveCfg = Debug|x64 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|x64.Build.0 = Debug|x64 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|x86.ActiveCfg = Debug|x86 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Debug|x86.Build.0 = Debug|x86 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|ARM.ActiveCfg = Release|ARM | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|ARM.Build.0 = Release|ARM | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|x64.ActiveCfg = Release|x64 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|x64.Build.0 = Release|x64 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|x86.ActiveCfg = Release|x86 | ||
{B73FB286-30FD-48A5-B022-CC5FC5D6F27F}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using RestRT; | ||
using Windows.Foundation; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using System.Threading.Tasks; | ||
|
||
namespace Twilio | ||
{ | ||
public sealed partial class TwilioRestClient | ||
{ | ||
/// <summary> | ||
/// Retrieve the account details for the currently authenticated account. Makes a GET request to an Account Instance resource. | ||
/// </summary> | ||
public IAsyncOperation<Account> GetAccountAsync() | ||
{ | ||
return (IAsyncOperation<Account>)AsyncInfo.Run((System.Threading.CancellationToken ct) => GetAccountAsyncInternal()); | ||
} | ||
private async Task<Account> GetAccountAsyncInternal() | ||
{ | ||
var request = new RestRequest(); | ||
request.Resource = "Accounts/{AccountSid}.json"; | ||
|
||
var result = await ExecuteAsync(request, typeof(Account)); | ||
return (Account)result; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve the account details for a subaccount. Makes a GET request to an Account Instance resource. | ||
/// </summary> | ||
/// <param name="accountSid">The Sid of the subaccount to retrieve</param> | ||
public IAsyncOperation<Account> GetAccountAsync(string accountSid) | ||
{ | ||
return (IAsyncOperation<Account>)AsyncInfo.Run((System.Threading.CancellationToken ct) => GetAccountAsyncInternal(accountSid)); | ||
} | ||
private async Task<Account> GetAccountAsyncInternal(string accountSid) | ||
{ | ||
var request = new RestRequest(); | ||
request.Resource = "Accounts/{AccountSid}.json"; | ||
|
||
request.AddUrlSegment("AccountSid", accountSid); | ||
|
||
var result = await ExecuteAsync(request, typeof(Account)); | ||
return (Account)result; | ||
} | ||
|
||
/// <summary> | ||
/// List all subaccounts created for the authenticated account. Makes a GET request to the Account List resource. | ||
/// </summary> | ||
public IAsyncOperation<AccountResult> ListSubAccountsAsync() | ||
{ | ||
return (IAsyncOperation<AccountResult>)AsyncInfo.Run((System.Threading.CancellationToken ct) => ListSubAccountsAsyncInternal()); | ||
} | ||
private async Task<AccountResult> ListSubAccountsAsyncInternal() | ||
{ | ||
var request = new RestRequest(); | ||
request.Resource = "Accounts.json"; | ||
|
||
var result = await ExecuteAsync(request, typeof(AccountResult)); | ||
return (AccountResult)result; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new subaccount under the authenticated account. Makes a POST request to the Account List resource. | ||
/// </summary> | ||
/// <param name="friendlyName">Name associated with this account for your own reference (can be empty string)</param> | ||
public IAsyncOperation<Account> CreateSubAccountAsync(string friendlyName) | ||
{ | ||
return (IAsyncOperation<Account>)AsyncInfo.Run((System.Threading.CancellationToken ct) => CreateSubAccountAsyncInternal(friendlyName)); | ||
} | ||
private async Task<Account> CreateSubAccountAsyncInternal(string friendlyName) | ||
{ | ||
var request = new RestRequest(); | ||
request.Method = Method.POST; | ||
request.Resource = "Accounts.json"; | ||
|
||
request.AddParameter("FriendlyName", friendlyName); | ||
|
||
var result = await ExecuteAsync(request, typeof(Account)); | ||
return (Account)result; | ||
} | ||
|
||
/// <summary> | ||
/// Changes the status of a subaccount. You must be authenticated as the master account to call this method on a subaccount. | ||
/// WARNING: When closing an account, Twilio will release all phone numbers assigned to it and shut it down completely. | ||
/// You can't ever use a closed account to make and receive phone calls or send and receive SMS messages. | ||
/// It's closed, gone, kaput. It will still appear in your accounts list, and you will still have access to historical | ||
/// data for that subaccount, but you cannot reopen a closed account. | ||
/// </summary> | ||
/// <param name="subAccountSid">The subaccount to change the status on</param> | ||
/// <param name="status">The status to change the subaccount to</param> | ||
public IAsyncOperation<Account> ChangeSubAccountStatusAsync(string subAccountSid, AccountStatus status) | ||
{ | ||
return (IAsyncOperation<Account>)AsyncInfo.Run((System.Threading.CancellationToken ct) => ChangeSubAccountStatusAsyncInternal(subAccountSid, status)); | ||
} | ||
private async Task<Account> ChangeSubAccountStatusAsyncInternal(string subAccountSid, AccountStatus status) | ||
{ | ||
if (subAccountSid == AccountSid) | ||
{ | ||
throw new InvalidOperationException("Subaccount status can only be changed when authenticated from the master account."); | ||
} | ||
|
||
var request = new RestRequest(); | ||
request.Method = Method.POST; | ||
request.Resource = "Accounts/{AccountSid}.json"; | ||
|
||
request.AddParameter("Status", status.ToString().ToLower()); | ||
request.AddUrlSegment("AccountSid", subAccountSid); | ||
|
||
var result = await ExecuteAsync(request, typeof(Account)); | ||
return (Account)result; | ||
} | ||
|
||
/// <summary> | ||
/// Update the friendly name associated with the currently authenticated account. Makes a POST request to an Account Instance resource. | ||
/// </summary> | ||
/// <param name="friendlyName">Name to use when updating</param> | ||
public IAsyncOperation<Account> UpdateAccountNameAsync(string friendlyName) | ||
{ | ||
return (IAsyncOperation<Account>)AsyncInfo.Run((System.Threading.CancellationToken ct) => UpdateAccountNameAsyncInternal(friendlyName)); | ||
} | ||
private async Task<Account> UpdateAccountNameAsyncInternal(string friendlyName) | ||
{ | ||
var request = new RestRequest(); | ||
request.Method = Method.POST; | ||
request.Resource = "Accounts/{AccountSid}.json"; | ||
request.AddParameter("FriendlyName", friendlyName); | ||
|
||
var result = await ExecuteAsync(request, typeof(Account)); | ||
return (Account)result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System; | ||
using RestRT; | ||
using RestRT.Extensions; | ||
using RestRT.Validation; | ||
using System.Threading.Tasks; | ||
using Windows.Foundation; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
|
||
namespace Twilio | ||
{ | ||
public sealed partial class TwilioRestClient | ||
{ | ||
/// <summary> | ||
/// Retrieve the details for an application instance. Makes a GET request to an Application Instance resource. | ||
/// </summary> | ||
/// <param name="applicationSid">The Sid of the application to retrieve</param> | ||
public IAsyncOperation<Application> GetApplicationAsync(string applicationSid) | ||
{ | ||
return (IAsyncOperation<Application>)AsyncInfo.Run((System.Threading.CancellationToken ct) => GetApplicationAsyncInternal(applicationSid)); | ||
} | ||
private async Task<Application> GetApplicationAsyncInternal(string applicationSid) | ||
{ | ||
var request = new RestRequest(); | ||
request.Resource = "Accounts/{AccountSid}/Applications/{ApplicationSid}.json"; | ||
|
||
request.AddUrlSegment("ApplicationSid", applicationSid); | ||
|
||
var result = await ExecuteAsync(request, typeof(Application)); | ||
return (Application)result; | ||
} | ||
|
||
/// <summary> | ||
/// List applications on current account | ||
/// </summary> | ||
public IAsyncOperation<ApplicationResult> ListApplicationsAsync() | ||
{ | ||
return (IAsyncOperation<ApplicationResult>)AsyncInfo.Run((System.Threading.CancellationToken ct) => ListApplicationsAsyncInternal(null, null, null)); | ||
} | ||
|
||
/// <summary> | ||
/// List applications on current account with filters | ||
/// </summary> | ||
/// <param name="friendlyName">Optional friendly name to match</param> | ||
/// <param name="pageNumber">Page number to start retrieving results from</param> | ||
/// <param name="count">How many results to return</param> | ||
public IAsyncOperation<ApplicationResult> ListApplicationsAsync(string friendlyName, int? pageNumber, int? count) | ||
{ | ||
return (IAsyncOperation<ApplicationResult>)AsyncInfo.Run((System.Threading.CancellationToken ct) => ListApplicationsAsyncInternal(friendlyName, pageNumber, count)); | ||
} | ||
private async Task<ApplicationResult> ListApplicationsAsyncInternal(string friendlyName, int? pageNumber, int? count) | ||
{ | ||
var request = new RestRequest(); | ||
request.Resource = "Accounts/{AccountSid}/Applications.json"; | ||
|
||
if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); | ||
if (pageNumber.HasValue) request.AddParameter("Page", pageNumber.Value); | ||
if (count.HasValue) request.AddParameter("PageSize", count.Value); | ||
|
||
//return Execute<ApplicationResult>(request); | ||
var result = await ExecuteAsync(request, typeof(ApplicationResult)); | ||
return (ApplicationResult)result; | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Create a new application | ||
/// </summary> | ||
/// <param name="friendlyName">The friendly name to name the application</param> | ||
/// <param name="options">Optional parameters to use when purchasing number</param> | ||
public IAsyncOperation<Application> AddApplicationAsync(string friendlyName, ApplicationOptions options) | ||
{ | ||
return (IAsyncOperation<Application>)AsyncInfo.Run((System.Threading.CancellationToken ct) => AddApplicationAsyncInternal(friendlyName, options)); | ||
} | ||
private async Task<Application> AddApplicationAsyncInternal(string friendlyName, ApplicationOptions options) | ||
{ | ||
var request = new RestRequest(); | ||
request.Method = Method.POST; | ||
request.Resource = "Accounts/{AccountSid}/Applications.json"; | ||
|
||
Require.Argument("FriendlyName", friendlyName); | ||
Validate.IsValidLength(friendlyName, 64); | ||
request.AddParameter("FriendlyName", friendlyName); | ||
|
||
// some check for null. in those cases an empty string is a valid value (to remove a URL assignment) | ||
if (options != null) | ||
{ | ||
if (options.VoiceUrl != null) request.AddParameter("VoiceUrl", options.VoiceUrl); | ||
if (options.VoiceMethod.HasValue()) request.AddParameter("VoiceMethod", options.VoiceMethod.ToString()); | ||
if (options.VoiceFallbackUrl != null) request.AddParameter("VoiceFallbackUrl", options.VoiceFallbackUrl); | ||
if (options.VoiceFallbackMethod.HasValue()) request.AddParameter("VoiceFallbackMethod", options.VoiceFallbackMethod.ToString()); | ||
if (options.VoiceCallerIdLookup.HasValue) request.AddParameter("VoiceCallerIdLookup", options.VoiceCallerIdLookup.Value); | ||
if (options.StatusCallback.HasValue()) request.AddParameter("StatusCallback", options.StatusCallback); | ||
if (options.StatusCallbackMethod.HasValue()) request.AddParameter("StatusCallbackMethod", options.StatusCallbackMethod.ToString()); | ||
if (options.SmsUrl != null) request.AddParameter("SmsUrl", options.SmsUrl); | ||
if (options.SmsMethod.HasValue()) request.AddParameter("SmsMethod", options.SmsMethod.ToString()); | ||
if (options.SmsFallbackUrl != null) request.AddParameter("SmsFallbackUrl", options.SmsFallbackUrl); | ||
if (options.SmsFallbackMethod.HasValue()) request.AddParameter("SmsFallbackMethod", options.SmsFallbackMethod.ToString()); | ||
} | ||
|
||
var result = await ExecuteAsync(request, typeof(Application)); | ||
return (Application)result; | ||
} | ||
|
||
/// <summary> | ||
/// Tries to update the application's properties, and returns the updated resource representation if successful. | ||
/// </summary> | ||
/// <param name="applicationSid">The Sid of the application to update</param> | ||
/// <param name="friendlyName">The friendly name to rename the application to (optional, null to leave as-is)</param> | ||
/// <param name="options">Which settings to update. Only properties with values set will be updated.</param> | ||
public IAsyncOperation<Application> UpdateApplicationAsync(string applicationSid, string friendlyName, ApplicationOptions options) | ||
{ | ||
return (IAsyncOperation<Application>)AsyncInfo.Run((System.Threading.CancellationToken ct) => UpdateApplicationAsyncInternal(applicationSid, friendlyName, options)); | ||
} | ||
private async Task<Application> UpdateApplicationAsyncInternal(string applicationSid, string friendlyName, ApplicationOptions options) | ||
{ | ||
Require.Argument("ApplicationSid", applicationSid); | ||
|
||
var request = new RestRequest(); | ||
request.Method = Method.POST; | ||
request.Resource = "Accounts/{AccountSid}/Applications/{ApplicationSid}.json"; | ||
request.AddUrlSegment("ApplicationSid", applicationSid); | ||
|
||
if (friendlyName.HasValue()) request.AddParameter("FriendlyName", friendlyName); | ||
if (options != null) | ||
{ | ||
if (options.VoiceUrl != null) request.AddParameter("VoiceUrl", options.VoiceUrl); | ||
if (options.VoiceMethod.HasValue()) request.AddParameter("VoiceMethod", options.VoiceMethod.ToString()); | ||
if (options.VoiceFallbackUrl != null) request.AddParameter("VoiceFallbackUrl", options.VoiceFallbackUrl); | ||
if (options.VoiceFallbackMethod.HasValue()) request.AddParameter("VoiceFallbackMethod", options.VoiceFallbackMethod.ToString()); | ||
if (options.VoiceCallerIdLookup.HasValue) request.AddParameter("VoiceCallerIdLookup", options.VoiceCallerIdLookup.Value); | ||
if (options.StatusCallback.HasValue()) request.AddParameter("StatusCallback", options.StatusCallback); | ||
if (options.StatusCallbackMethod.HasValue()) request.AddParameter("StatusCallbackMethod", options.StatusCallbackMethod.ToString()); | ||
if (options.SmsUrl != null) request.AddParameter("SmsUrl", options.SmsUrl); | ||
if (options.SmsMethod.HasValue()) request.AddParameter("SmsMethod", options.SmsMethod.ToString()); | ||
if (options.SmsFallbackUrl != null) request.AddParameter("SmsFallbackUrl", options.SmsFallbackUrl); | ||
if (options.SmsFallbackMethod.HasValue()) request.AddParameter("SmsFallbackMethod", options.SmsFallbackMethod.ToString()); | ||
} | ||
|
||
var result = await ExecuteAsync(request, typeof(Application)); | ||
return (Application)result; | ||
} | ||
|
||
/// <summary> | ||
/// Delete this application. If this application's sid is assigned to any IncomingPhoneNumber resources as a VoiceApplicationSid or SmsApplicationSid it will be removed. | ||
/// </summary> | ||
/// <param name="applicationSid">The Sid of the number to remove</param> | ||
public IAsyncOperation<DeleteStatus> DeleteApplicationAsync(string applicationSid) | ||
{ | ||
return (IAsyncOperation<DeleteStatus>)AsyncInfo.Run((System.Threading.CancellationToken ct) => DeleteApplicationAsyncInternal(applicationSid)); | ||
} | ||
private async Task<DeleteStatus> DeleteApplicationAsyncInternal(string applicationSid) | ||
{ | ||
Require.Argument("ApplicationSid", applicationSid); | ||
var request = new RestRequest(); | ||
request.Method = Method.DELETE; | ||
request.Resource = "Accounts/{AccountSid}/Applications/{ApplicationSid}.json"; | ||
|
||
request.AddUrlSegment("ApplicationSid", applicationSid); | ||
|
||
var response = (RestResponse)await ExecuteAsync(request); | ||
return response.StatusCode == (int)System.Net.HttpStatusCode.NoContent ? DeleteStatus.Success : DeleteStatus.Failed; | ||
} | ||
} | ||
} |
Oops, something went wrong.