public CustomFields GetCustomFields(string parent)
{
if (String.IsNullOrEmpty(parent))
throw new ApplicationException("Parent cannot be empty.");
string[] allowedParents = { "carrier", "customer", "shipment" };
int pos = Array.IndexOf(allowedParents, parent);
if (pos <= -1)
throw new ApplicationException("Parent can only be 'carrier', 'customer' or 'shipment'");
var client = GetRestClient();
var request = new RestRequest
{
Resource = "api/customfield/" + parent,
RequestFormat = DataFormat.Json,
RootElement = "Carrier"
};
var response = client.Execute<CustomFields>(request);
if (response.ErrorException != null)
{
if (response.StatusCode == System.Net.HttpStatusCode.NotFound) {
// no custom fields defined for object, so return a blank object
CustomFields blank = new CustomFields();
blank._id = "";
blank.fields = new System.Collections.Generic.List<Field>();
blank.parent = parent;
return blank;
} else {
throw new ApplicationException("Error retrieving custom fields", response.ErrorException);
}
}
var customFields = response.Data;
return customFields;
}