feat(Network): implement full listing deletion process

This commit is contained in:
karashiiro 2021-07-24 23:59:31 -07:00
parent 6eb9dfefe1
commit 89314e0c0e
5 changed files with 63 additions and 17 deletions

View file

@ -22,7 +22,7 @@ namespace Dalamud.Game.Network.MarketBoardUploaders
/// <summary>
/// Upload information about a purchase this client has made.
/// </summary>
/// <param name="purchase">That thing with Louisiana.</param>
void UploadPurchase(MarketBoardPurchase purchase);
/// <param name="purchaseHandler">The purchase handler data associated with the sale.</param>
void UploadPurchase(MarketBoardPurchaseHandler purchaseHandler);
}
}

View file

@ -0,0 +1,46 @@
using Newtonsoft.Json;
namespace Dalamud.Game.Network.MarketBoardUploaders.Universalis
{
/// <summary>
/// Request payload for market board purchases.
/// </summary>
public class UniversalisItemListingDeleteRequest
{
/// <summary>
/// Gets or sets the object ID of the retainer associated with the sale.
/// </summary>
[JsonProperty("retainerID")]
public ulong RetainerId { get; set; }
/// <summary>
/// Gets or sets the object ID of the item listing.
/// </summary>
[JsonProperty("listingID")]
public ulong ListingId { get; set; }
/// <summary>
/// Gets or sets the item ID of the item that was purchased.
/// </summary>
[JsonProperty("itemID")]
public uint ItemId { get; set; }
/// <summary>
/// Gets or sets the quantity of the item that was purchased.
/// </summary>
[JsonProperty("quantity")]
public uint Quantity { get; set; }
/// <summary>
/// Gets or sets the unit price of the item.
/// </summary>
[JsonProperty("pricePerUnit")]
public uint PricePerUnit { get; set; }
/// <summary>
/// Gets or sets the uploader ID.
/// </summary>
[JsonProperty("uploaderID")]
public string UploaderId { get; set; }
}
}

View file

@ -1,9 +0,0 @@
namespace Dalamud.Game.Network.MarketBoardUploaders.Universalis
{
/// <summary>
/// Request payload for market board purchases.
/// </summary>
public class UniversalisMarketBoardPurchaseRequest
{
}
}

View file

@ -138,21 +138,30 @@ namespace Dalamud.Game.Network.Universalis.MarketBoardUploaders
}
/// <inheritdoc/>
public void UploadPurchase(MarketBoardPurchase purchase)
public void UploadPurchase(MarketBoardPurchaseHandler purchaseHandler)
{
using var client = new WebClient();
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
client.Headers.Add(HttpRequestHeader.Authorization, ApiKey);
var purchaseRequest = new UniversalisMarketBoardPurchaseRequest();
var itemId = purchaseHandler.CatalogId;
var worldId = this.dalamud.ClientState.LocalPlayer?.CurrentWorld.Id ?? 0;
var purchaseRequest = new UniversalisItemListingDeleteRequest
{
ItemId = itemId,
PricePerUnit = purchaseHandler.PricePerUnit,
Quantity = purchaseHandler.ItemQuantity,
ListingId = purchaseHandler.ListingId,
RetainerId = purchaseHandler.RetainerId,
UploaderId = this.dalamud.ClientState.LocalContentId.ToString(),
};
var purchaseUpload = JsonConvert.SerializeObject(purchaseRequest);
client.UploadString(ApiBase + $"/{purchase.CatalogId}/{worldId}/delete", "POST", purchaseUpload);
client.UploadString(ApiBase + $"/{itemId}/{worldId}/delete", "POST", purchaseUpload);
Log.Verbose(purchaseUpload);
Log.Verbose("Universalis tax upload completed.");
Log.Verbose("Universalis purchase upload completed.");
}
}
}

View file

@ -282,7 +282,7 @@ namespace Dalamud.Game.Network
|| purchase.CatalogId == this.marketBoardPurchaseHandler.CatalogId + 1000000))
{ // HQ
Log.Information("Bought " + purchase.ItemQuantity + "x " + this.marketBoardPurchaseHandler.CatalogId + " for " + (this.marketBoardPurchaseHandler.PricePerUnit * purchase.ItemQuantity) + " gils, listing id is " + this.marketBoardPurchaseHandler.ListingId);
Task.Run(() => this.uploader.UploadPurchase(purchase));
Task.Run(() => this.uploader.UploadPurchase(this.marketBoardPurchaseHandler));
}
this.marketBoardPurchaseHandler = null;