Skip to content

Commit

Permalink
Merge pull request #151 from Nexmo/Feature_completion
Browse files Browse the repository at this point in the history
Feature completion
  • Loading branch information
Rabeb Othmani authored May 10, 2019
2 parents 545c479 + 35434a0 commit 93f41fb
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Nexmo.Api.Test.Integration/AccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public void should_get_pricing()
Assert.AreEqual("Verizon Wireless", verizon.network);
}

[TestMethod]
public void should_get_prefix_pricing()
{
var pricing = Account.GetPrefixPricing("1","sms");
Assert.AreEqual("US", pricing.country);
}

[TestMethod]
public void should_set_settings()
{
Expand Down
26 changes: 26 additions & 0 deletions Nexmo.Api.Test.Integration/ConversionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nexmo.Api.Test.Unit
{
[TestClass]
public class ConversionTest
{
public void Should_submit()
{
Conversion.ConversionType = "sms";
Conversion.SubmitConversion(new Conversion.ConversionRequest
{
MessageId = "",
Delivered = true,
Timestamp = DateTime.UtcNow
});


}
}
}
49 changes: 33 additions & 16 deletions Nexmo.Api/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public class Number
/// </summary>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
/// <returns>Balance data</returns>
public static Balance GetBalance(Credentials creds = null)
public static Balance GetBalance(Credentials credentials = null)
{
var json = ApiRequest.DoRequest(ApiRequest.GetBaseUriFor(typeof(Account),
"/account/get-balance"),
// TODO: using this method sig allows us to have the api auth injected at the expense of opaque code here
new Dictionary<string, string>(),
creds);
credentials);

var obj = JsonConvert.DeserializeObject<Balance>(json);
return obj;
Expand All @@ -122,7 +122,7 @@ public static Balance GetBalance(Credentials creds = null)
/// <param name="type">The type of service you wish to retrieve data about: either sms, sms-transit or voice.</param>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
/// <returns>Pricing data</returns>
public static Pricing GetPricing(string country, string type = null, Credentials creds = null)
public static Pricing GetPricing(string country, string type = null, Credentials credentials = null)
{
var parameters = new Dictionary<string, string>
{
Expand All @@ -136,7 +136,24 @@ public static Pricing GetPricing(string country, string type = null, Credentials
var json = ApiRequest.DoRequest(ApiRequest.GetBaseUriFor(typeof(Account),
"/account/get-pricing/outbound/"),
parameters,
creds);
credentials);

var obj = JsonConvert.DeserializeObject<Pricing>(json);
return obj;
}

public static Pricing GetPrefixPricing(string prefix, string type, Credentials credentials = null)
{
var parameters = new Dictionary<string, string>
{
{ "prefix", prefix },
{ "type", type }
};

var json = ApiRequest.DoRequest(ApiRequest.GetBaseUriFor(typeof(Account),
"/account/get-prefix-pricing/outbound/"),
parameters,
credentials);

var obj = JsonConvert.DeserializeObject<Pricing>(json);
return obj;
Expand All @@ -148,9 +165,9 @@ public static Pricing GetPricing(string country, string type = null, Credentials
/// <param name="newsecret">New API secret</param>
/// <param name="httpMoCallbackurlCom">An encoded URI to the webhook endpoint endpoint that handles inbound messages.</param>
/// <param name="httpDrCallbackurlCom">An encoded URI to the webhook endpoint that handles deliver receipts (DLR).</param>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
/// <param name="credentials">(Optional) Overridden credentials for only this request</param>
/// <returns>Updated settings</returns>
public static Settings SetSettings(string newsecret = null, string httpMoCallbackurlCom = null, string httpDrCallbackurlCom = null, Credentials creds = null)
public static Settings SetSettings(string newsecret = null, string httpMoCallbackurlCom = null, string httpDrCallbackurlCom = null, Credentials credentials = null)
{
var parameters = new Dictionary<string, string>();
if (null != newsecret)
Expand All @@ -160,7 +177,7 @@ public static Settings SetSettings(string newsecret = null, string httpMoCallbac
if (null != httpDrCallbackurlCom)
parameters.Add("drCallBackUrl", httpDrCallbackurlCom);

var response = ApiRequest.DoPostRequest(ApiRequest.GetBaseUriFor(typeof(Account), "/account/settings"), parameters, creds);
var response = ApiRequest.DoPostRequest(ApiRequest.GetBaseUriFor(typeof(Account), "/account/settings"), parameters, credentials);

// TODO: update secret in config?

Expand All @@ -171,37 +188,37 @@ public static Settings SetSettings(string newsecret = null, string httpMoCallbac
/// Top-up an account that is configured for auto reload.
/// </summary>
/// <param name="transaction">The ID associated with your original auto-reload transaction.</param>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
public static void TopUp(string transaction, Credentials creds = null)
/// <param name="credentials">(Optional) Overridden credentials for only this request</param>
public static void TopUp(string transaction, Credentials credentials = null)
{
ApiRequest.DoRequest(ApiRequest.GetBaseUriFor(typeof(Account), "/account/top-up"), new Dictionary<string, string>
{
{"trx", transaction}
},
creds);
credentials);

// TODO: return response
}

/// <summary>
/// Retrieve all the phone numbers associated with your account.
/// </summary>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
/// <param name="credentials">(Optional) Overridden credentials for only this request</param>
/// <returns>All the phone numbers associated with your account.</returns>
public static NumbersResponse GetNumbers(Credentials creds = null)
public static NumbersResponse GetNumbers(Credentials credentials = null)
{
return GetNumbers(new NumbersRequest(), creds);
return GetNumbers(new NumbersRequest(), credentials);
}

/// <summary>
/// Retrieve all the phone numbers associated with your account that match the provided filter
/// </summary>
/// <param name="request">Filter for account numbers list</param>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
/// <param name="credentials">(Optional) Overridden credentials for only this request</param>
/// <returns></returns>
public static NumbersResponse GetNumbers(NumbersRequest request, Credentials creds = null)
public static NumbersResponse GetNumbers(NumbersRequest request, Credentials credentials = null)
{
var json = ApiRequest.DoRequest(ApiRequest.GetBaseUriFor(typeof(Account), "/account/numbers"), request, creds);
var json = ApiRequest.DoRequest(ApiRequest.GetBaseUriFor(typeof(Account), "/account/numbers"), request, credentials);
return JsonConvert.DeserializeObject<NumbersResponse>(json);
}
}
Expand Down
12 changes: 12 additions & 0 deletions Nexmo.Api/Client/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public Api.Account.Pricing GetPricing(string country, string type = null, Creden
return Api.Account.GetPricing(country, type, creds ?? Credentials);
}

/// <summary>
/// Retrieve our outbound pricing for a given numerical prefix
/// </summary>
/// <param name="prefix">numerical prefix. Examples: 44,1.</param>
/// <param name="type">The type of service you wish to retrieve data about: either sms, sms-transit or voice.</param>
/// <param name="creds">(Optional) Overridden credentials for only this request</param>
/// <returns>Pricing data</returns>
public Api.Account.Pricing GetPrefixPricing(string prefix, string type, Credentials creds = null)
{
return Api.Account.GetPricing(prefix, type, creds ?? Credentials);
}

/// <summary>
/// Set account settings
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Nexmo.Api/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private void PropagateCredentials()
ApiSecret = new ClientMethods.ApiSecret(Credentials);
Application = new ClientMethods.Application(Credentials);
Call = new ClientMethods.Call(Credentials);
Conversion = new ClientMethods.Conversion(Credentials);
Number = new ClientMethods.Number(Credentials);
NumberInsight = new ClientMethods.NumberInsight(Credentials);
NumberVerify = new ClientMethods.NumberVerify(Credentials);
Expand All @@ -44,6 +45,7 @@ private void PropagateCredentials()
public ClientMethods.ApiSecret ApiSecret { get; private set; }
public ClientMethods.Application Application { get; private set; }
public ClientMethods.Call Call { get; private set; }
public ClientMethods.Conversion Conversion { get; private set; }
public ClientMethods.Number Number { get; private set; }
public ClientMethods.NumberInsight NumberInsight { get; private set; }
public ClientMethods.NumberVerify NumberVerify { get; private set; }
Expand Down
23 changes: 23 additions & 0 deletions Nexmo.Api/Client/Conversion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Nexmo.Api.Request;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nexmo.Api.ClientMethods
{
public class Conversion
{
public Credentials Credentials { get; set; }
public Conversion(Credentials creds)
{
Credentials = creds;
}

public void SubmitConversion (Api.Conversion.ConversionRequest request, Credentials creds = null)
{
Api.Conversion.SubmitConversion(request, creds);
}
}
}
51 changes: 51 additions & 0 deletions Nexmo.Api/Conversion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Newtonsoft.Json;
using Nexmo.Api.Request;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nexmo.Api
{
public static class Conversion
{
/// <summary>
/// possible values : "voice" or "sms"
/// </summary>
public static string ConversionType { get; set; }

public class ConversionRequest
{
/// <summary>
/// The ID you receive in the response to a request.
/// possible values: message-id for SMS API, call-id for TTS and TTSP APIs,
/// event_id for Verify API.
/// </summary>
[JsonProperty("message-id")]
public string MessageId { get; set; }
/// <summary>
/// Set to true if your user replied to the message you sent.
/// Otherwise, set to false.
/// </summary>
[JsonProperty("delivered")]
public bool Delivered { get; set; }
/// <summary>
/// When the user completed your call-to-action in UTC±00:00
/// format: yyyy-MM-dd HH:mm:ss.
/// </summary>
[JsonProperty("timestamp")]
public DateTime Timestamp { get; set; }
}

/// <summary>
/// Tells if a message or call was successful.
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
public static void SubmitConversion (ConversionRequest request, Credentials creds = null)
{
var response = ApiRequest.DoPostRequest(new Uri($"https://api.nexmo.com/conversions/{ConversionType}"), request, creds);
}
}
}

0 comments on commit 93f41fb

Please sign in to comment.