Skip to content

Commit

Permalink
Refactor action methods
Browse files Browse the repository at this point in the history
  • Loading branch information
c1982 committed Apr 19, 2014
1 parent b479d58 commit f07c5ea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
22 changes: 8 additions & 14 deletions PureVpnApi.Test/VpnApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public void CreateUser()
.Authentication(apiUserName, apiPassword)
.Package("STANDARD")
.Period(90)
.Create()
.Send();
.Create();

Assert.AreEqual(1, result.Result);
Assert.AreNotEqual(String.Empty, result.User);
Expand All @@ -29,10 +28,9 @@ public void RenewUser()
{
var result = new VpnRequest()
.Authentication(apiUserName, apiPassword)
.Username("vpnuser123")
.Username("vpnuser123")
.Period(90)
.Renew()
.Send();
.Renew();

Assert.AreEqual(1, result.Result);
Assert.AreNotEqual(String.Empty, result.User);
Expand All @@ -44,9 +42,8 @@ public void FindStatus()
{
var result = new VpnRequest()
.Authentication(apiUserName, apiPassword)
.Username("vpnuser123")
.FindStatus()
.Send();
.Username("vpnuser123")
.FindStatus();

Assert.AreEqual(1, result.Result);
Assert.AreNotEqual(String.Empty, result.User);
Expand All @@ -59,8 +56,7 @@ public void Delete()
var result = new VpnRequest()
.Authentication(apiUserName, apiPassword)
.Username("vpnuser123")
.Delete()
.Send();
.Delete();

Assert.AreEqual(1, result.Result);
Assert.AreNotEqual(String.Empty, result.Status);
Expand All @@ -72,8 +68,7 @@ public void DisableUser()
var result = new VpnRequest()
.Authentication(apiUserName, apiPassword)
.Username("vpnuser123")
.Update("disable")
.Send();
.Update("disable");

Assert.AreEqual(1, result.Result);
}
Expand All @@ -84,8 +79,7 @@ public void ChangePassword()
var result = new VpnRequest()
.Authentication(apiUserName, apiPassword)
.Username("vpnuser123")
.ChangePassword("p@ssw0rd")
.Send();
.ChangePassword("p@ssw0rd");

Assert.AreEqual(1, result.Result);
}
Expand Down
27 changes: 14 additions & 13 deletions PureVpnApi/VpnRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,70 +68,71 @@ public VpnRequest Period(int Days)
}


public VpnRequest Create()
public VpnResponse Create()
{
AddValue("method", "create");
return this;

return Send();
}

/// <summary>
/// Username required
/// </summary>
/// <returns></returns>
public VpnRequest Renew()
public VpnResponse Renew()
{
AddValue("method", "renew");
return this;
return Send();
}

/// <summary>
/// Username required
/// </summary>
/// <returns></returns>
public VpnRequest FindStatus()
public VpnResponse FindStatus()
{
AddValue("method", "status");
return this;
return Send();
}


/// <summary>
/// Username required
/// </summary>
/// <returns></returns>
public VpnRequest Delete()
public VpnResponse Delete()
{
AddValue("method", "delete");
return this;
return Send();
}

/// <summary>
/// Username required
/// </summary>
/// <param name="updateStatus">enable,disable</param>
/// <returns></returns>
public VpnRequest Update(string updateStatus)
public VpnResponse Update(string updateStatus)
{
AddValue("method", "update_status");
AddValue("update_status", updateStatus);

return this;
return Send();
}

/// <summary>
/// Username required
/// </summary>
/// <param name="newPassword">New Password, Must be Alphanumeric and length should be 8 characters</param>
/// <returns></returns>
public VpnRequest ChangePassword(string newPassword)
public VpnResponse ChangePassword(string newPassword)
{
AddValue("method", "change_password");
AddValue("new_pass", newPassword);

return this;
return Send();
}

public VpnResponse Send()
private VpnResponse Send()
{
var remoteResponse = SendHttpRequest(API_HOST, "POST", args.ToString());
var responseObject = DeSerializeObject<VpnResponse>(remoteResponse);
Expand Down
3 changes: 1 addition & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Create standard new vpn user 90 days.
.Authentication("apiUserName", "apiPassword")
.Package("STANDARD")
.Period(90)
.Create()
.Send();
.Create();


if (result.Result == 1)
Expand Down

0 comments on commit f07c5ea

Please sign in to comment.