-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from plivo/beta
Add PHLO support
- Loading branch information
Showing
18 changed files
with
564 additions
and
9 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
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
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
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
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,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)); | ||
|
||
} | ||
} | ||
} |
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
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
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,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"); | ||
} | ||
|
||
|
||
} | ||
} |
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,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; | ||
} | ||
|
||
|
||
|
||
} | ||
} |
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,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); | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
} |
Oops, something went wrong.