Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,4 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk
/.vs
11 changes: 11 additions & 0 deletions ShippingEasy.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@ static void Main(string[] args)
var apiKey = appSettings["ShippingEasy.ApiKey"];
var apiSecret = appSettings["ShippingEasy.ApiSecret"];
var baseUrl = appSettings["ShippingEasy.BaseUrl"];
string orderId = "1111";

try
{
var client = new Client(apiKey, apiSecret, baseUrl);
HttpResponse response;
const string storeApiKey = "c71dc6da574eea04e2c926906bcb4eab";
switch (command)
{
case "STORES":
response = client.GetStores().HttpResponse;
break;
case "ORDERS_ID":
response = client.GetOrder(orderId).HttpResponse;
break;
case "ORDERS":
response = client.GetOrders().HttpResponse;
break;
case "ORDERSBYNUMBER":
response = client.GetOrders(new OrderQuery() { OrderNumber = "1", Status = "ready_for_shipment,shipped" }).HttpResponse;
break;
case "STORE_ORDERS":
response = client.GetOrders(new OrderQuery
{
Expand Down
13 changes: 13 additions & 0 deletions ShippingEasy/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public CancelOrderResponse CancelOrder(string storeApiKey, string externalOrderI
return _responseHandler.Build<CancelOrderResponse>(response);
}

public StoreQueryResponse GetStores()
{
var response = Connection.GetAllStoresJson();
return _responseHandler.Build<StoreQueryResponse>(response);
}

/// <summary>
/// Downloads orders from your ShippingEasy account
/// </summary>
Expand All @@ -76,6 +82,13 @@ public OrderQueryResponse GetOrders(OrderQuery query = null)
return _responseHandler.Build<OrderQueryResponse>(response);
}

public OrderResponse GetOrder(string id)
{
var response = Connection.GetOrderJson(id);
return _responseHandler.Build<OrderResponse>(response);

}

public static string OrderToJson(Order order)
{
return JsonConvert.SerializeObject(order, Formatting.Indented, Serialization.Settings);
Expand Down
12 changes: 11 additions & 1 deletion ShippingEasy/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,22 @@ public HttpResponse CreateOrderFromJson(string storeApiKey, string jsonBody)
return MakeRequest("POST", String.Format("/api/stores/{0}/orders", storeApiKey), jsonBody);
}

public HttpResponse GetAllStoresJson()
{
return MakeRequest("GET", String.Format("/api/stores"));
}

public HttpResponse CancelOrderJson(string storeApiKey, string externalOrderIdentifier)
{
return MakeRequest("POST",
String.Format("/api/stores/{0}/orders/{1}/cancellations", storeApiKey, externalOrderIdentifier));
}


public HttpResponse GetOrderJson(string id)
{
return MakeRequest("GET", String.Format("/api/orders/{0}", id));
}

/// <summary>
/// A hook to override the method that takes a fully-constructed WebRequest and returns a response string
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions ShippingEasy/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace ShippingEasy
{
public class Order
{
public Order()
{
Shipments = new List<Shipment>();
Tags = new List<string>();
}

private readonly List<Recipient> _recipients = new List<Recipient>();

/// <summary>
Expand Down Expand Up @@ -59,6 +65,18 @@ public List<Recipient> Recipients
public string BillingEmail { get; set; }
[JsonProperty]
public string StoreApiKey { get; private set; }
public List<Shipment> Shipments { get; set; }
public List<string> Tags { get; set; }
public string Notes { get; set; }
[JsonProperty("custom_1")]
public string Custom1 { get; set; }
[JsonProperty("custom_2")]
public string Custom2 { get; set; }
[JsonProperty("custom_3")]
public string Custom3 { get; set; }
[JsonProperty("internal_notes")]
public string InternalNotes { get; set; }

}

public class Recipient
Expand Down Expand Up @@ -94,6 +112,10 @@ public class Recipient
public string ShippingMethod { get; set; }
public int? ItemsShipped { get; set; }
public int? ExtShippingDetailId { get; set; }
[JsonProperty("internal_notes")]
public string InternalNotes { get; set; }
[JsonProperty("original_order")]
public OriginalOrder OriginalOrder { get; set; }
}

public class LineItem
Expand Down
13 changes: 12 additions & 1 deletion ShippingEasy/OrderQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace ShippingEasy
{
public class OrderQuery
{
/// <summary>
/// The external_order_identifier to search for
/// <remarks>Search for sales by order number</remarks>
/// </summary>
public string OrderNumber { get; set; }
/// <summary>
/// The status of the orders you would like to return. 'shipped' or 'ready_for_shipment'
/// <remarks>You can specify multiple states by separating with a comma. Ex: 'shipped,ready_for_shipment'</remarks>
Expand Down Expand Up @@ -45,7 +50,13 @@ public IDictionary<string, string> ToDictionary()
}
if (LastUpdated.HasValue)
{
options.Add("last_updated_at", LastUpdated.Value.ToString("O"));
options.Add("last_updated_at", LastUpdated.Value.ToString("u"));
}

if(!String.IsNullOrEmpty(OrderNumber))
{
options.Clear();
options.Add("order_number", OrderNumber);
}
return options;
}
Expand Down
14 changes: 14 additions & 0 deletions ShippingEasy/OrderResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ShippingEasy.Responses;

namespace ShippingEasy
{
public class OrderResponse : ApiResponse
{
private readonly Order _order = new Order();

public Order Order
{
get { return _order; }
}
}
}
21 changes: 21 additions & 0 deletions ShippingEasy/OriginalOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;

namespace ShippingEasy
{
public class OriginalOrder
{
public OriginalOrder()
{

}

[JsonProperty("custom_1")]
public string Custom1 { get; set; }
[JsonProperty("custom_2")]
public string Custom2 { get; set; }
[JsonProperty("custom_3")]
public string Custom3 { get; set; }
[JsonProperty("internal_notes")]
public string InternalNotes { get; set; }
}
}
4 changes: 2 additions & 2 deletions ShippingEasy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
[assembly: Guid("ea7b2ec4-35c4-4c63-b7cf-ab2a5591cc54")]

// AssemblyVersion should be manually updated for an official release
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]

internal static class AssemblyInfo
{
Expand Down
14 changes: 14 additions & 0 deletions ShippingEasy/Responses/StoreQueryResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;

namespace ShippingEasy.Responses
{
public class StoreQueryResponse : ApiResponse
{
private readonly IList<Store> _stores = new List<Store>();

public IList<Store> Stores
{
get { return _stores; }
}
}
}
33 changes: 33 additions & 0 deletions ShippingEasy/Shipment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Newtonsoft.Json;
using System;

namespace ShippingEasy
{
public class Shipment
{
public string ID { get; set; }
[JsonProperty("tracking_number")]
public string TrackingNumber { get; set; }
[JsonProperty("carrier_key")]
public string CarrierKey { get; set; }
[JsonProperty("carrier_service_key")]
public string CarrierServiceKey { get; set; }
[JsonProperty("shipment_cost")]
public decimal? ShipmentCost { get; set; }
[JsonProperty("ship_date")]
public DateTime? ShipDate { get; set; }
[JsonProperty("workflow_state")]
public string WorkflowState { get; set; }
[JsonProperty("cloned_from_shipment_id")]
public string ClonedFromShipmentID { get; set; }
[JsonProperty("weight_in_ounces")]
public decimal? WeightInOunches { get; set; }
[JsonProperty("length_in_ounces")]
public decimal? LengthInInches { get; set; }
[JsonProperty("width_in_ounces")]
public decimal? WidthInInches { get; set; }
[JsonProperty("height_in_ounces")]
public decimal? HeightInInches { get; set; }

}
}
6 changes: 5 additions & 1 deletion ShippingEasy/ShippingEasy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Authenticator.cs" />
<Compile Include="Properties\BuildInfo.cs" />
<Compile Include="OrderResponse.cs" />
<Compile Include="OriginalOrder.cs" />
<Compile Include="Responses\ApiResponse.cs" />
<Compile Include="Client.cs" />
<Compile Include="Connection.cs" />
Expand All @@ -53,8 +54,11 @@
<Compile Include="ResponseHandler.cs" />
<Compile Include="Responses\CancelOrderResponse.cs" />
<Compile Include="Responses\CreateOrderResponse.cs" />
<Compile Include="Responses\StoreQueryResponse.cs" />
<Compile Include="Serialization.cs" />
<Compile Include="Shipment.cs" />
<Compile Include="Signature.cs" />
<Compile Include="Store.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
Expand Down
2 changes: 1 addition & 1 deletion ShippingEasy/ShippingEasy.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<summary>ShippingEasy API Client</summary>
<copyright>Copyright 2015</copyright>
<copyright>Copyright 2015-2020</copyright>
</metadata>
</package>
13 changes: 13 additions & 0 deletions ShippingEasy/Store.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace ShippingEasy
{
public class Store
{
[JsonProperty("api_key")]
public string ApiKey { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Url { get; set; }
}
}
13 changes: 13 additions & 0 deletions Tests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ public void GetOrdersReturnsAListOfOrders()
Assert.AreEqual("ABC-789", response.Orders[1].ExternalOrderIdentifier);
}

[Test]
public void GetOrdersReturnsAListOfOrdersShipments()
{
var client = new Client(ResponseFromFile("get_orders_success_shipment"));

var response = client.GetOrders();
Assert.IsTrue(response.Success);
Assert.AreEqual(1, response.Orders.Count);
Assert.AreEqual("8888888888888888888888", response.Orders[0].Shipments[0].TrackingNumber);
Assert.AreEqual("internal order notes", response.Orders[0].Recipients[0].InternalNotes);
}


[Test]
public void GetOrdersReturnsCountAndPagingDetails()
{
Expand Down
3 changes: 2 additions & 1 deletion Tests/OrderQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public class OrderQueryTests
[Test]
public void BuildsDictionaryForPropertiesWithValues()
{
var orderQuery = new OrderQuery {Page = 2, Status = "shipped"};
var orderQuery = new OrderQuery {Page = 2, Status = "shipped", OrderNumber = "1"};
var options = orderQuery.ToDictionary();
Assert.That(options.Keys, Is.EquivalentTo(new[] { "page", "status" }));
Assert.AreEqual("2", options["page"]);
Assert.AreEqual("1", options["order_number"]);
Assert.AreEqual("shipped", options["status"]);
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<Content Include="fixtures\invalid_json_response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="fixtures\get_orders_success_shipment.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading