diff --git a/src/Twilio/Types/App.cs b/src/Twilio/Types/App.cs new file mode 100644 index 000000000..43ba6fa9e --- /dev/null +++ b/src/Twilio/Types/App.cs @@ -0,0 +1,42 @@ +using System; + +namespace Twilio.Types +{ + /// + /// App Endpoint + /// + public class App : IEndpoint + { + public const string PREFIX = "app:"; + + private readonly string _app; + + /// + /// Create new app + /// + /// App name + public App(string app) + { + if (string.IsNullOrEmpty(app)) + { + throw new ArgumentException("Parameter 'app' cannot be null or empty.", nameof(app)); + } + + if (!app.ToLower().StartsWith(PREFIX)) + { + app = PREFIX + app; + } + + _app = app; + } + + /// + /// Convert to string + /// + /// String representation + public override string ToString() + { + return _app; + } + } +} diff --git a/test/Twilio.Test/Types/AppTest.cs b/test/Twilio.Test/Types/AppTest.cs new file mode 100644 index 000000000..b798cbc2d --- /dev/null +++ b/test/Twilio.Test/Types/AppTest.cs @@ -0,0 +1,23 @@ +using System; +using NUnit.Framework; +using Twilio.Exceptions; +using Twilio.Types; + +namespace Twilio.Tests.Types +{ + [TestFixture] + public class AppTest + { + [Test] + public void TestToString() + { + Assert.AreEqual("app:me", new App("me").ToString()); + Assert.AreEqual("app:YOU", new App("YOU").ToString()); + Assert.AreEqual("APP:HIM", new App("APP:HIM").ToString()); + Assert.AreEqual("aPp:her", new App("aPp:her").ToString()); + Assert.Throws(() => new App("").ToString()); + Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("app:AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); + Assert.AreEqual("app:AP12345?mycustomparam1=foo&mycustomparam2=bar", new App("AP12345?mycustomparam1=foo&mycustomparam2=bar").ToString()); + } + } +}