Skip to content

Commit

Permalink
Merge pull request #105 from plivo/AggregateException
Browse files Browse the repository at this point in the history
Aggregate exception
  • Loading branch information
nixonsam authored Jun 12, 2019
2 parents 8738339 + 10cd05d commit 053107b
Show file tree
Hide file tree
Showing 30 changed files with 889 additions and 327 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# Change Log

## [v4.4.1](https://github.com/plivo/plivo-dotnet/tree/v4.4.1) (2019-06-12)
- Add AggregateException Flattening

## [v4.4.0](https://github.com/plivo/plivo-dotnet/tree/v4.4.0) (2019-03-14)
- Add PHLO support
- Add Multi-Party Call triggers
Expand Down
2 changes: 1 addition & 1 deletion src/Plivo/Plivo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.3</TargetFrameworks>
<ReleaseVersion>4.4.0</ReleaseVersion>
<ReleaseVersion>4.4.1</ReleaseVersion>
<Version></Version>
<Authors>Plivo SDKs Team</Authors>
<Owners>Plivo Inc.</Owners>
Expand Down
3 changes: 2 additions & 1 deletion src/Plivo/Plivo.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<summary>A .NET SDK to make voice calls &amp; send SMS using Plivo and to generate Plivo XML</summary>
<description>A .NET SDK to make voice calls &amp; send SMS using Plivo and to generate Plivo XML</description>
<id>Plivo</id>
<version>4.4.0</version>
<version>4.4.1</version>
<title>Plivo</title>
<authors>Plivo SDKs Team</authors>
<owners>Plivo, Inc.</owners>
<licenseUrl>https://github.com/plivo/plivo-dotnet/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>http://github.com/plivo/plivo-dotnet</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>
* 4.4.1 Add AggregateException Flattening
* 4.4.0 Add PHLO support and Multi-party call triggers
* 4.3.0-beta1 Add PHLO support and Multi-party call triggers in beta release
* 4.2.3 Update Thread Safety handling for synchronous execution.
Expand Down
143 changes: 75 additions & 68 deletions src/Plivo/Resource/Account/AccountInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,79 @@

namespace Plivo.Resource.Account
{
/// <summary>
/// Account interface.
/// </summary>
public class AccountInterface : ResourceInterface
{
/// <summary>
/// Initializes a new instance of the <see cref="T:plivo.Resource.Account.AccountInterface"/> class.
/// </summary>
/// <param name="client">Client.</param>
public AccountInterface(HttpClient client) : base(client)
{
Uri = "Account/" + Client.GetAuthId() + "/";
}
#region Get
/// <summary>
/// Get the specified id.
/// </summary>
/// <returns>The get.</returns>
public Account Get()
{
var account = Task.Run(async () => await GetResource<Account>("").ConfigureAwait(false)).Result;
account.Interface = this;
return account;
}
/// <summary>
/// Asynchronously get the specified id.
/// </summary>
/// <returns>The get.</returns>
public async Task<Account> GetAsync()
{
var account = await GetResource<Account>("");
account.Interface = this;
return account;
}
#endregion
#region Update
/// <summary>
/// Update the specified name, city and address.
/// </summary>
/// <returns>The update.</returns>
/// <param name="name">Name.</param>
/// <param name="city">City.</param>
/// <param name="address">Address.</param>
public UpdateResponse<Account> Update(string name = null, string city = null, string address = null)
{
var mandatoryParams = new List<string> {"name"};
var data = CreateData(
mandatoryParams, new {name, city, address});
var result = Task.Run(async () => await Client.Update<UpdateResponse<Account>>(Uri, data).ConfigureAwait(false)).Result;
return result.Object;
}
/// <summary>
/// Asynchronously update the specified name, city and address.
/// </summary>
/// <returns>The update.</returns>
/// <param name="name">Name.</param>
/// <param name="city">City.</param>
/// <param name="address">Address.</param>
public async Task<UpdateResponse<Account>> UpdateAsync(string name = null, string city = null, string address = null)
{
var mandatoryParams = new List<string> { "name" };
var data = CreateData(
mandatoryParams, new { name, city, address });
var result = await Client.Update<UpdateResponse<Account>>(Uri, data);
return result.Object;
}
#endregion
}
/// <summary>
/// Account interface.
/// </summary>
public class AccountInterface : ResourceInterface
{
/// <summary>
/// Initializes a new instance of the <see cref="T:plivo.Resource.Account.AccountInterface"/> class.
/// </summary>
/// <param name="client">Client.</param>
public AccountInterface(HttpClient client) : base(client)
{
Uri = "Account/" + Client.GetAuthId() + "/";
}
#region Get
/// <summary>
/// Get the specified id.
/// </summary>
/// <returns>The get.</returns>
public Account Get()
{
return ExecuteWithExceptionUnwrap(() =>
{
var account = Task.Run(async () => await GetResource<Account>("").ConfigureAwait(false)).Result;
account.Interface = this;
return account;
});
}
/// <summary>
/// Asynchronously get the specified id.
/// </summary>
/// <returns>The get.</returns>
public async Task<Account> GetAsync()
{
var account = await GetResource<Account>("");
account.Interface = this;
return account;
}
#endregion

#region Update
/// <summary>
/// Update the specified name, city and address.
/// </summary>
/// <returns>The update.</returns>
/// <param name="name">Name.</param>
/// <param name="city">City.</param>
/// <param name="address">Address.</param>
public UpdateResponse<Account> Update(string name = null, string city = null, string address = null)
{
var mandatoryParams = new List<string> { "name" };
var data = CreateData(mandatoryParams, new { name, city, address });

return ExecuteWithExceptionUnwrap(() =>
{
var result = Task.Run(async () => await Client.Update<UpdateResponse<Account>>(Uri, data).ConfigureAwait(false)).Result;
return result.Object;
});
}
/// <summary>
/// Asynchronously update the specified name, city and address.
/// </summary>
/// <returns>The update.</returns>
/// <param name="name">Name.</param>
/// <param name="city">City.</param>
/// <param name="address">Address.</param>
public async Task<UpdateResponse<Account>> UpdateAsync(string name = null, string city = null, string address = null)
{
var mandatoryParams = new List<string> { "name" };
var data = CreateData(
mandatoryParams, new { name, city, address });
var result = await Client.Update<UpdateResponse<Account>>(Uri, data);
return result.Object;
}
#endregion
}
}
14 changes: 14 additions & 0 deletions src/Plivo/Resource/Address/AddressDeleteResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plivo.Resource.Address
{
public class AddressDeleteResponse : DeleteResponse<Address>
{
/// <summary>
/// Gets or sets the status code.
/// </summary>
public uint StatusCode { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/Plivo/Resource/Address/AddressGetResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plivo.Resource.Address
{
public class AddressGetResponse : Address
{
/// <summary>
/// Gets or sets the error.
/// </summary>
/// <value>The error.</value>
public ErrorMessage Error { get; set; }
}
}
44 changes: 29 additions & 15 deletions src/Plivo/Resource/Address/AddressInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ public UpdateResponse<Address> Update(
filesToUpload.Add("file", fileToUpload);
}

var result = Task.Run(async () => await Client.Update<UpdateResponse<Address>>(Uri + addressId + "/", data, filesToUpload).ConfigureAwait(false)).Result;
return result.Object;

return ExecuteWithExceptionUnwrap(() =>
{
var result = Task.Run(async () => await Client.Update<UpdateResponse<Address>>(Uri + addressId + "/", data, filesToUpload).ConfigureAwait(false)).Result;
return result.Object;
});
}

/// <summary>
Expand Down Expand Up @@ -359,11 +363,14 @@ public async Task<UpdateResponse<Address>> UpdateAsync(
/// <param name="id">Identifier.</param>
public Address Get(string id)
{
var address = Task.Run(async () => await GetResource<Address>(id).ConfigureAwait(false)).Result;
address.Interface = this;
return address;
}
/// <summary>
return ExecuteWithExceptionUnwrap(() =>
{
var address = Task.Run(async () => await GetResource<AddressGetResponse>(id).ConfigureAwait(false)).Result;
address.Interface = this;
return address;
});
} /// <summary>
/// Asynchronously get address with the specified id.
/// </summary>
/// <returns>The get.</returns>
Expand Down Expand Up @@ -408,13 +415,17 @@ public ListResponse<Address> List(
limit,
offset
});
var resources = Task.Run(async () => await ListResources<ListResponse<Address>>(data).ConfigureAwait(false)).Result;
resources.Objects.ForEach(
(obj) => obj.Interface = this
);

return resources;
}
return ExecuteWithExceptionUnwrap(() =>
{
var resources = Task.Run(async () => await ListResources<ListResponse<Address>>(data).ConfigureAwait(false)).Result;
resources.Objects.ForEach(
(obj) => obj.Interface = this
);
return resources;
});
}
/// <summary>
/// List Addresses with the specified params.
/// </summary>
Expand Down Expand Up @@ -472,8 +483,11 @@ public async Task<DeleteResponse<Address>> DeleteAsync(string id)
/// <param name="id">Identifier.</param>
public DeleteResponse<Address> Delete(string id)
{
return Task.Run(async () => await DeleteResource<DeleteResponse<Address>>(id).ConfigureAwait(false)).Result;
}
return ExecuteWithExceptionUnwrap(() =>
{
return Task.Run(async () => await DeleteAsync(id).ConfigureAwait(false)).Result;
});
}
#endregion
}
}
51 changes: 33 additions & 18 deletions src/Plivo/Resource/Application/ApplicationInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ public ApplicationCreateResponse Create(
logIncomingMessages
});

var result = Task.Run(async () => await Client.Update<ApplicationCreateResponse>(Uri, data).ConfigureAwait(false)).Result;
return ExecuteWithExceptionUnwrap(() =>
{
var result = Task.Run(async () => await Client.Update<ApplicationCreateResponse>(Uri, data).ConfigureAwait(false)).Result;
return result.Object;
}
return result.Object;
});
}
/// <summary>
/// Asynchronously create Application with the specified appName, answerUrl, answerMethod, hangupUrl, hangupMethod, fallbackAnswerUrl,
/// fallbackMethod, messageUrl, messageMethod, defaultNumberApp, defaultEndpointApp, subaccount and logIncomingMessages.
Expand Down Expand Up @@ -139,10 +142,13 @@ public async Task<ApplicationCreateResponse> CreateAsync(
/// <param name="appId">App identifier.</param>
public Application Get(string appId)
{
var application = Task.Run(async () => await GetResource<Application>(appId).ConfigureAwait(false)).Result;
application.Interface = this;
return application;
}
return ExecuteWithExceptionUnwrap(() =>
{
var application = Task.Run(async () => await GetResource<Application>(appId).ConfigureAwait(false)).Result;
application.Interface = this;
return application;
});
}
/// <summary>
/// Asynchronously get Application with the specified appId.
/// </summary>
Expand Down Expand Up @@ -171,13 +177,16 @@ public ListResponse<Application> List(
var data = CreateData(
mandatoryParams, new { subaccount, limit, offset });

var resources = Task.Run(async () => await ListResources<ListResponse<Application>>(data).ConfigureAwait(false)).Result;
resources.Objects.ForEach(
(obj) => obj.Interface = this
);
return ExecuteWithExceptionUnwrap(() =>
{
var resources = Task.Run(async () => await ListResources<ListResponse<Application>>(data).ConfigureAwait(false)).Result;
resources.Objects.ForEach(
(obj) => obj.Interface = this
);
return resources;
}
return resources;
});
}
/// <summary>
/// List Application with the specified subaccount, limit and offset.
/// </summary>
Expand Down Expand Up @@ -209,8 +218,11 @@ public async Task<ListResponse<Application>> ListAsync(
/// <param name="appId">App identifier.</param>
public DeleteResponse<Application> Delete(string appId)
{
return Task.Run(async () => await DeleteResource<DeleteResponse<Application>>(appId).ConfigureAwait(false)).Result;
}
return ExecuteWithExceptionUnwrap(() =>
{
return Task.Run(async () => await DeleteResource<DeleteResponse<Application>>(appId).ConfigureAwait(false)).Result;
});
}
/// <summary>
/// Asynchronously delete Application with the specified appId.
/// </summary>
Expand Down Expand Up @@ -268,9 +280,12 @@ public UpdateResponse<Application> Update(
logIncomingMessages
});

var result = Task.Run(async () => await Client.Update<UpdateResponse<Application>>(Uri + appId + "/", data).ConfigureAwait(false)).Result;
return result.Object;
}
return ExecuteWithExceptionUnwrap(() =>
{
var result = Task.Run(async () => await Client.Update<UpdateResponse<Application>>(Uri + appId + "/", data).ConfigureAwait(false)).Result;
return result.Object;
});
}
/// <summary>
/// Asynchronously update Application with the specified appId, answerUrl, answerMethod, hangupUrl, hangupMethod, fallbackAnswerUrl,
/// fallbackMethod, messageUrl, messageMethod, defaultNumberApp, defaultEndpointApp and subaccount.
Expand Down
Loading

0 comments on commit 053107b

Please sign in to comment.