Skip to content

Commit

Permalink
Merge pull request #101 from plivo/beta
Browse files Browse the repository at this point in the history
Add PHLO support
  • Loading branch information
nixonsam authored Mar 14, 2019
2 parents 1501cc7 + ae44138 commit 8738339
Show file tree
Hide file tree
Showing 18 changed files with 564 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

# Change Log

## [v4.4.0](https://github.com/plivo/plivo-dotnet/tree/v4.4.0) (2019-03-14)
- Add PHLO support
- Add Multi-Party Call triggers

## [v4.3.0-beta1](https://github.com/plivo/plivo-dotnet/tree/v4.3.0-beta1) (2019-03-14)
- Add PHLO support in beta release
- Add Multi-Party Call triggers

## [v4.2.3](https://github.com/plivo/plivo-dotnet/tree/v4.2.3) (2019-01-04)
- Update Thread Safety handling for synchronous execution.

Expand Down
12 changes: 10 additions & 2 deletions src/Plivo/Client/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public class HttpClient
/// <param name="proxyPort">Proxy Port.</param>
/// <param name="proxyUsername">Proxy Username.</param>
/// <param name="proxyPassword">Proxy Password.</param>
/// <param name="baseUri">Switch between environments</param>

public HttpClient(BasicAuth basicAuth,
string proxyAddress = null, string proxyPort = null,
string proxyUsername = null, string proxyPassword = null)
string proxyUsername = null, string proxyPassword = null, string baseUri = null)
{
_client = new SystemHttpClient(basicAuth,
new Dictionary<string, string>
Expand All @@ -41,7 +43,7 @@ public HttpClient(BasicAuth basicAuth,
{"Password", proxyPassword},
{"Username", proxyUsername},
{"Port", proxyPort}
});
}, baseUri);
_basicAuth = basicAuth;
}

Expand Down Expand Up @@ -101,5 +103,11 @@ public void SetTimeout(int timeout)
{
((SystemHttpClient) _client)._client.Timeout = TimeSpan.FromSeconds(timeout);
}

public string AsQueryString(IEnumerable<KeyValuePair<string, object>> parameters)
{
return _client.AsQueryString(parameters);
}

}
}
4 changes: 3 additions & 1 deletion src/Plivo/Client/IHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface IHttpClient
Task<PlivoResponse<T>> SendRequest<T>(string method, string uri, Dictionary<string, object> data,
Dictionary<string, string> filesToUpload = null)
where T : new();
}

string AsQueryString(IEnumerable<KeyValuePair<string, object>> parameters);
}
}
8 changes: 5 additions & 3 deletions src/Plivo/Client/SystemHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected override string ResolvePropertyName(string propertyName)
/// </summary>
/// <param name="basicAuth">Basic auth.</param>
/// <param name="proxyServerSettings">Proxy settings.</param>
public SystemHttpClient(BasicAuth basicAuth, Dictionary<string, string> proxyServerSettings)
/// <param name="baseUri">Switch between environments</param>
public SystemHttpClient(BasicAuth basicAuth, Dictionary<string, string> proxyServerSettings, string baseUri = null)
{
#if NETSTANDARD2_0
IWebProxy proxy = null;
Expand Down Expand Up @@ -105,7 +106,8 @@ public SystemHttpClient(BasicAuth basicAuth, Dictionary<string, string> proxySer
);
_client.DefaultRequestHeaders.Authorization = authHeader;
_client.DefaultRequestHeaders.Add("User-Agent", "plivo-dotnet/" + ThisAssembly.AssemblyVersion);
_client.BaseAddress = new Uri("https://api.plivo.com/" + Version.ApiVersion + "/");
var baseServerUri = string.IsNullOrEmpty(baseUri) ? "https://api.plivo.com/" + Version.ApiVersion : baseUri;
_client.BaseAddress = new Uri(baseServerUri + "/");

_jsonSettings = new JsonSerializerSettings
{
Expand Down Expand Up @@ -238,7 +240,7 @@ public async Task<PlivoResponse<T>> SendRequest<T>(string method, string uri, Di
return plivoResponse;
}

public static string AsQueryString(IEnumerable<KeyValuePair<string, object>> parameters)
public string AsQueryString(IEnumerable<KeyValuePair<string, object>> parameters)
{
if (!parameters.Any())
return "";
Expand Down
71 changes: 71 additions & 0 deletions src/Plivo/PhloApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Plivo.Authentication;
using Plivo.Client;
using Plivo.Resource.Phlo;
using System;

namespace Plivo
{
public class PhloApi
{
/// <summary>
/// Gets or sets the client.
/// </summary>
/// <value>The client.</value>
public HttpClient Client { get; set; }

/// <summary>
/// The basic auth.
/// </summary>
protected BasicAuth BasicAuth;


// resource interfaces
private readonly Lazy<PhloInterface> _phlo;
/// <summary>
/// Gets the account.
/// </summary>
/// <value>The account.</value>
public PhloInterface Phlo => _phlo.Value;

//private Lazy<NodeInterface> _node;
//public PhloInterface Node => _node.Value;

/// <summary>
/// Authentication ID
/// </summary>
private string _authId;

/// <summary>
/// Authentication Token
/// </summary>
private string _authToken;


/// <summary>
/// Initializes a new instance of the <see cref="T:plivo.PhloApi"/> class.
/// </summary>
/// <param name="authId">Auth identifier.</param>
/// <param name="authToken">Auth token.</param>
/// <param name="proxyAddress">Proxy Address.</param>
/// <param name="proxyPort">Proxy Port.</param>
/// <param name="proxyUsername">Proxy Username.</param>
/// <param name="proxyPassword">Proxy Password.</param>
public PhloApi(
string authId,
string authToken,
string proxyAddress = null,
string proxyPort = null,
string proxyUsername = null,
string proxyPassword = null,
string baseUri = null
)
{
BasicAuth = new BasicAuth(authId, authToken);
Client = new HttpClient(BasicAuth, proxyAddress, proxyPort, proxyUsername, proxyPassword, baseUri="https://phlorunner.plivo.com/v1");
_authId = authId;
_authToken = authToken;
_phlo = new Lazy<PhloInterface>(() => new PhloInterface(Client, _authId, _authToken));

}
}
}
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.2.3</ReleaseVersion>
<ReleaseVersion>4.4.0</ReleaseVersion>
<Version></Version>
<Authors>Plivo SDKs Team</Authors>
<Owners>Plivo Inc.</Owners>
Expand Down
4 changes: 3 additions & 1 deletion src/Plivo/Plivo.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
<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.2.3</version>
<version>4.4.0</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.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.
* 4.2.2 Fix dynamic object usage with async/await statement.
* 4.2.1 Fix Web Proxy support.
Expand Down
43 changes: 43 additions & 0 deletions src/Plivo/Resource/Member/Member.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Plivo.Resource.Member
{
public class Member: Resource
{
public BaseResponse AbortTransfer()
{
return ((MemberInterface) Interface)
.Update("abort_transfer");
}

public BaseResponse ResumeCall()
{
return ((MemberInterface) Interface)
.Update("resume_call");
}

public BaseResponse VoicemailDrop()
{
return ((MemberInterface) Interface)
.Update("voicemail_drop");
}

public BaseResponse Hangup()
{
return ((MemberInterface) Interface)
.Update("hangup");
}

public BaseResponse Hold()
{
return ((MemberInterface) Interface)
.Update("hold");
}

public BaseResponse Unhold()
{
return ((MemberInterface) Interface)
.Update("unhold");
}


}
}
54 changes: 54 additions & 0 deletions src/Plivo/Resource/Member/MemberInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Plivo.Client;
using System.Threading.Tasks;

namespace Plivo.Resource.Member
{
public class MemberInterface: ResourceInterface
{
/// <summary>
/// PHLO Id
/// </summary>
private string _phloId;
/// <summary>
/// Node type
/// </summary>
private string _nodeType;
/// <summary>
/// Node Id
/// </summary>
private string _nodeId;
/// <summary>
/// Member Id
/// </summary>
private string _memberId;

public MemberInterface(HttpClient client, string phloId, string nodeType, string nodeId) : base(client)
{
_phloId = phloId;
_nodeType = nodeType;
_nodeId = nodeId;


Uri = $"phlo/{_phloId}/";

}

public BaseResponse Update(string action)
{
var result = Task.Run(async () => await Client.Update<BaseResponse>(Uri + $"{_nodeType}/{_nodeId}/members/{_memberId}?action={action}").ConfigureAwait(false)).Result;
return result.Object;

}

public Member Get(string memberId)
{
var member = new Member();
member.Interface = this;
_memberId = memberId;
return member;
}



}
}
44 changes: 44 additions & 0 deletions src/Plivo/Resource/MultiPartyCall/MultiPartyCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Plivo.Exception;
using Plivo.Resource.Member;

namespace Plivo.Resource.MultiPartyCall
{
public class MultiPartyCall : Node.Node
{
public Lazy<MemberInterface> _member;
private MemberInterface MemberI => _member.Value;

public BaseResponse Call(string triggerSource, string to, string role)
{

return ((MultiPartyCallInterface) Interface).Update("call", triggerSource, to, role);

}

public BaseResponse WarmTransfer(string triggerSource, string to, string role="agent")
{
return ((MultiPartyCallInterface) Interface).Update("warm_transfer", triggerSource, to, role);

}

public BaseResponse ColdTransfer(string triggerSource, string to, string role="agent")
{
return ((MultiPartyCallInterface) Interface).Update("cold_transfer", triggerSource, to, role);

}

public Member.Member Member(string MemberId)
{
if (string.IsNullOrEmpty(MemberId))
{
throw new PlivoValidationException("MemberId is mandatory, can not be null or empty");
}
return MemberI.Get(MemberId);

}



}
}
Loading

0 comments on commit 8738339

Please sign in to comment.