Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Added support for user-parcel-templates #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
34 changes: 34 additions & 0 deletions Shippo/APIResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserParcelTemplate>(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<UserParcelTemplate>(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<UserParcelTemplate>(ep);
}

public ShippoCollection<UserParcelTemplate> AllUserParcelTemplates()
{
string ep = String.Format("{0}/user-parcel-templates", api_endpoint);
return DoRequest<ShippoCollection<UserParcelTemplate>>(ep);
}

#endregion

public int TimeoutSeconds { get; set; }
}
}
38 changes: 38 additions & 0 deletions Shippo/UserParcelTemplate.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

5 changes: 3 additions & 2 deletions ShippoTesting/ShippoTesting.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -41,6 +41,7 @@
<ItemGroup>
<Compile Include="AddressTest.cs" />
<Compile Include="ParcelTest.cs" />
<Compile Include="UserParcelTemplateTest.cs" />
<Compile Include="ShipmentTest.cs" />
<Compile Include="RateTest.cs" />
<Compile Include="TransactionTest.cs" />
Expand All @@ -66,4 +67,4 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>
</Project>
80 changes: 80 additions & 0 deletions ShippoTesting/UserParcelTemplateTest.cs
Original file line number Diff line number Diff line change
@@ -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<UserParcelTemplate> testObject = getAPIResource().AllUserParcelTemplates();
Assert.GreaterOrEqual(testObject.Data.Count, 1);
}

[Test, Order(5)]
public void TestValidDelete()
{
getAPIResource().DeleteUserParcelTemplate(UserParcelTemplateObjectId);
ShippoCollection<UserParcelTemplate> 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;
}
}
}