public static void CreateInventory(string barCode_, KeepaRecord useTheseDetails_) { var toAdd = new JObject( new JProperty("item", new JObject( new JProperty(InventoryFields.Name, useTheseDetails_.Title), new JProperty("description", useTheseDetails_.Description), new JProperty(InventoryFields.SKU, barCode_), new JProperty(InventoryFields.BarCode, barCode_), new JProperty("multiple", 1), new JProperty("threshold", 0), new JProperty(InventoryFields.Cost, 0.0), new JProperty(InventoryFields.Price, 0.0), new JProperty(InventoryFields.Quantity, 0), new JProperty("category_id", "5b1aafe1-ed18-43b2-b2dd-2ed40a8e0005"), new JProperty("item_details", new JArray { new JObject( new JProperty("custom_field_id", InventoryCustomFields.Author), new JProperty("value", useTheseDetails_.Author) ), new JObject( new JProperty("custom_field_id", InventoryCustomFields.Publisher), new JProperty("value", useTheseDetails_.Manufacturer) ), }) ))); var response = postJson("items.json", toAdd.ToString()); $"{JObject.Parse(response)}".ConsoleWriteLine(); }
private static KeepaRecord writeProductRecord(JToken product) { var p = KeepaRecord.Parse(product); if (!string.IsNullOrEmpty(p.Asin)) { $"Writing keepa record for asin identifier to '{recordPath(p.Asin)}'".ConsoleWriteLine(); File.WriteAllText(recordPath(p.Asin), product.ToString()); } p.EanList?.ForEach(x => { $"Writing record for ean identifier to '{recordPath(x)}'".ConsoleWriteLine(); File.WriteAllText(recordPath(x), product.ToString()); File.WriteAllText(lastLookupPath(x), DateTime.Now.ToString(LAST_CALL_DATEFORMAT)); }); return(p); }
private static void writeRecordsFromResponse(string response_, bool ensureImagesToo_) { var doc = JObject.Parse(response_); var productToken = doc["products"]; if (productToken == null) { return; } var productArray = (JArray)productToken; productArray.ForEach(product => { writeProductRecord(product); if (ensureImagesToo_) { KeepaRecord.Parse(product).DownloadImages(); } }); }
public static IEnumerable <KeepaRecord> AllLocalRecords() => Directory.GetFiles(RECORDS_DIR, "*.json").Select(x => KeepaRecord.Parse(JToken.Parse(File.ReadAllText(x))));
public static KeepaRecord GetRecordForIdentifier(string identifier_) { var path = recordPath(identifier_); return(File.Exists(recordPath(identifier_)) ? KeepaRecord.Parse(JToken.Parse(File.ReadAllText(path))) : null); }