/// <summary> /// Places a bulk order.</summary> /// <remarks>Please do not place orders one at a time. It is best to send multiple orders /// together in a batch and submit the batch a few times per day, for example, at 6am, 11am, and 2pm. /// The API uses your default credit card for payment. You can add or modify your credit card from My Account > Payment section.</remarks> /// <param name="bulkOrder">A BulkOrder object</param> /// <returns>A BulkOrderResult object</returns> /// <exception cref="FrgxPublicApiSDK.Exceptions.EmptyFeildException">Thrown if missing a feild in bulkOrder</exception> /// <exception cref="FrgxPublicApiSDK.Exceptions.InvalidArgumentException">Thrown if a arumgment or feild is not valid</exception> public BulkOrderResult PlaceBulkOrder(BulkOrder bulkOrder) { if (bulkOrder == null) { throw new EmptyFeildException(@"Field ""BulkOrder"" field cannot be empty."); } if (bulkOrder.Orders == null || bulkOrder.Orders.Count == 0) { throw new EmptyFeildException(@"Field ""Orders"" cannot be empty."); } foreach (var o in bulkOrder.Orders) { if (o.OrderItems == null || o.OrderItems.Count.Equals(0)) { throw (new EmptyFeildException("No items found in order {\n" + o + "}\n")); } } var json = JObject.FromObject(bulkOrder); var jsonStringContent = new StringContent(json.ToString(), Encoding.UTF8, "application/json"); var response = FrgxApicallHelper.PostApi(Constants.FrgxapiBulkOrder, jsonStringContent).Result; var j = JObject.Parse(response); var bulkOrderResult = JsonConvert.DeserializeObject <BulkOrderResult>(j.ToString()); return(bulkOrderResult); }
/// <summary> /// Private utility method that makes call to server using the FrgxApicallHelper object and casts response into a Product object /// </summary> /// <param name="url">Url the get request is sent to</param> /// <returns>A product object</returns> /// <exception cref="FrgxPublicApiSDK.Exceptions.InvalidArgumentException">Thrown if given invald id or upcCode</exception> private Product GetProduct(string url) { string response = FrgxApicallHelper.GetApi(url).Result; //If bad ID or UPC code if (response.ToLower().StartsWith("{\"message\":\"") || response.ToLower().StartsWith("<!doctype")) { throw (new InvalidArgumentException("Id or upcCode is Invalid!")); } return(ProductMapper.Map(JObject.Parse(response))); }
/// <summary> /// Constructor will set up a shared static FrgxApicallHelper and if already made update id and key /// </summary> /// <param name="accessId">Access ID sent to server when requesting an access token</param> /// <param name="accessKey">Access key sent to server when requesting an access token</param> protected FrgxApiClient(string accessId, string accessKey) { if (FrgxApicallHelper == null) { FrgxApicallHelper = new FrgxApicallHelper(accessId, accessKey); FrgxApicallHelper.Authenticate(); } else if (FrgxApicallHelper.AccessId != accessId || FrgxApicallHelper.AccessKey != accessKey) { FrgxApicallHelper.AccessId = accessId; FrgxApicallHelper.AccessKey = accessKey; FrgxApicallHelper.Authenticate(); } }
//Public Methods /// <summary> /// Retrieves the tracking information for a given order id. /// </summary> /// <param name="orderId">Either the FragranceX order ID or external ID that you want to retrieve the tracking information for.</param> /// <returns>An object of basic tracking information</returns> /// <exception cref="FrgxPublicApiSDK.Exceptions.EmptyFeildException">Thrown if missing order id</exception> /// <exception cref="FrgxPublicApiSDK.Exceptions.InvalidArgumentException">Thrown if invalid order id</exception> public TrackingInfo GetTracking(string orderId) { if (string.IsNullOrEmpty(orderId)) { throw (new EmptyFeildException("No orderId given")); } var response = FrgxApicallHelper.GetApi(Constants.FrgxapiTracking + orderId).Result; var jResponse = JObject.Parse(response); if (jResponse.GetValue("Carrier").ToString() == "") { throw (new InvalidArgumentException("Invalid order id: " + orderId)); } return(TrackingMapper.Map(jResponse)); }
/// <summary> /// Helper method for creating a HTTP request. /// The result of the request is then parsed and returned. /// </summary> /// <param name="url">URL of the HTTP request</param> /// <returns>A list of Product objects</returns> private List <Product> GetList(string url) { var response = FrgxApicallHelper.GetApi(url).Result; if (response.ToLower().StartsWith("{\"message\":\"") || response.ToLower().StartsWith("<!doctype")) { return(new List <Product>()); } var jList = JArray.Parse(response); var prodList = new List <Product>(); foreach (JObject jProd in jList.Children()) { prodList.Add(ProductMapper.Map(jProd)); } return(prodList); }