diff --git a/README.md b/README.md index ab80234..a2b708b 100755 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ of object you can create through the API. A particularly important file is [APIResource.cs](/Shippo/APIResource.cs), this file contains the code responsible for making requests. Also contained within this file are all the methods for generating different type of API objects. Each object's methods are contained within a region tag for convenient navigation. For example, the Parcel's methods are contained within: -```csharp +```csharp #region Parcel /* Parcel Code */ #endregion @@ -115,3 +115,4 @@ The Shippo API provides in depth support of carrier and shipping functionalities * UPS Mail Innovations * FedEx Smartpost * Additional services: cash-on-delivery, certified mail, delivery confirmation, and more. +* User parcel templates diff --git a/Shippo/APIResource.cs b/Shippo/APIResource.cs index 706d415..ddf0ed2 100644 --- a/Shippo/APIResource.cs +++ b/Shippo/APIResource.cs @@ -555,6 +555,40 @@ public Pickup CreatePickup(Hashtable parameters) #endregion + #region UserParcelTemplate + + public UserParcelTemplate CreateUserParcelTemplate(Hashtable parameters) + { + string ep = String.Format("{0}/user-parcel-templates", api_endpoint); + return DoRequest(ep, "POST", serialize(parameters)); + } + + public UserParcelTemplate UpdateUserParcelTemplate(String id, Hashtable parameters) + { + string ep = String.Format("{0}/user-parcel-templates/{1}", api_endpoint, id); + return DoRequest(ep, "PUT", serialize(parameters)); + } + + public void DeleteUserParcelTemplate(String id) + { + string ep = String.Format("{0}/user-parcel-templates/{1}", api_endpoint, id); + DoRequest(ep, "DELETE", null); + } + + public UserParcelTemplate RetrieveUserParcelTemplate(String id) + { + string ep = String.Format("{0}/user-parcel-templates/{1}", api_endpoint, id); + return DoRequest(ep); + } + + public ShippoCollection AllUserParcelTemplates() + { + string ep = String.Format("{0}/user-parcel-templates", api_endpoint); + return DoRequest>(ep); + } + + #endregion + public int TimeoutSeconds { get; set; } } } diff --git a/Shippo/UserParcelTemplate.cs b/Shippo/UserParcelTemplate.cs new file mode 100644 index 0000000..7dc55f0 --- /dev/null +++ b/Shippo/UserParcelTemplate.cs @@ -0,0 +1,38 @@ +using System; +using Newtonsoft.Json; + +namespace Shippo { + [JsonObject(MemberSerialization.OptIn)] + public class UserParcelTemplate : ShippoId { + [JsonProperty(PropertyName = "object_owner")] + public object ObjectOwner { get; set; } + + [JsonProperty(PropertyName = "object_created")] + public object ObjectCreated { get; set; } + + [JsonProperty(PropertyName = "object_updated")] + public object ObjectUpdated { get; set; } + + [JsonProperty(PropertyName = "name")] + public object Name { get; set; } + + [JsonProperty(PropertyName = "length")] + public object Length { get; set; } + + [JsonProperty(PropertyName = "width")] + public object Width { get; set; } + + [JsonProperty(PropertyName = "height")] + public object Height { get; set; } + + [JsonProperty(PropertyName = "distance_unit")] + public object DistanceUnit { get; set; } + + [JsonProperty(PropertyName = "weight")] + public object Weight { get; set; } + + [JsonProperty(PropertyName = "weight_unit")] + public object WeightUnit { get; set; } + } +} + diff --git a/ShippoTesting/ShippoTesting.csproj b/ShippoTesting/ShippoTesting.csproj index bc4aeb2..066dadc 100644 --- a/ShippoTesting/ShippoTesting.csproj +++ b/ShippoTesting/ShippoTesting.csproj @@ -1,4 +1,4 @@ - + Debug @@ -41,6 +41,7 @@ + @@ -66,4 +67,4 @@ - + \ No newline at end of file diff --git a/ShippoTesting/UserParcelTemplateTest.cs b/ShippoTesting/UserParcelTemplateTest.cs new file mode 100644 index 0000000..71921a2 --- /dev/null +++ b/ShippoTesting/UserParcelTemplateTest.cs @@ -0,0 +1,80 @@ +using NUnit.Framework; +using System; +using System.Collections; +using System.Linq; +using System.Threading; + +using Shippo; + + +namespace ShippoTesting { + [TestFixture] + public class UserParcelTemplateTest : ShippoTest + { + internal static string UserParcelTemplateObjectId; + + [Test, Order(1)] + public void TestValidCreate() + { + + Hashtable parameters = UserParcelTemplateTest.getParameterObject(); + UserParcelTemplate testObject = getAPIResource().CreateUserParcelTemplate(parameters); + Assert.AreEqual(parameters["name"], testObject.Name); + + UserParcelTemplateObjectId = testObject.ObjectId; + } + + [Test, Order(2)] + public void TestValidUpdate() + { + Hashtable parameters = UserParcelTemplateTest.getParameterObject_2(); + UserParcelTemplate testObject = getAPIResource().UpdateUserParcelTemplate(UserParcelTemplateObjectId, parameters); + Assert.AreEqual(parameters["length"], testObject.Length); + } + + [Test, Order(3)] + public void TestValidRetrieve() + { + UserParcelTemplate testObject = getAPIResource().RetrieveUserParcelTemplate(UserParcelTemplateObjectId); + Assert.AreEqual(UserParcelTemplateObjectId, testObject.ObjectId); + } + + [Test, Order(4)] + public void TestValidRetrieveAll() + { + ShippoCollection testObject = getAPIResource().AllUserParcelTemplates(); + Assert.GreaterOrEqual(testObject.Data.Count, 1); + } + + [Test, Order(5)] + public void TestValidDelete() + { + getAPIResource().DeleteUserParcelTemplate(UserParcelTemplateObjectId); + ShippoCollection testObject = getAPIResource().AllUserParcelTemplates(); + Assert.IsTrue(testObject.Data.All(d => d.ObjectId != UserParcelTemplateObjectId)); + } + + public static Hashtable getParameterObject() + { + Hashtable parameters = new Hashtable(); + parameters.Add("length", "5"); + parameters.Add("width", "5"); + parameters.Add("height", "5"); + parameters.Add("distance_unit", "in"); + parameters.Add("name", "Unit Test Parcel Template 1"); + return parameters; + } + + public static Hashtable getParameterObject_2() + { + Hashtable parameters = new Hashtable(); + parameters.Add("length", "10"); + parameters.Add("width", "15"); + parameters.Add("height", "20"); + parameters.Add("distance_unit", "in"); + parameters.Add("name", "Unit Test Parcel Template 2"); + return parameters; + } + } +} +