66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PoEco.Net.Web
|
|
{
|
|
internal class PoEPrices
|
|
{
|
|
public static void GetItemJson(string iid, string b64)
|
|
{
|
|
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
|
string url = $"https://www.poeprices.info/api?l={JSON.Settings.GetLeague()}&i={b64}";
|
|
WebClient webClient = new WebClient();
|
|
try
|
|
{
|
|
webClient.DownloadFile(url, "tmp/" + iid + ".json");
|
|
}
|
|
catch (WebException ex)
|
|
{
|
|
if (ex.Message.Contains("The remote server returned an error: (504) Gateway Time-out."))
|
|
{
|
|
Utilities.Message.CMW("Failed. Retrying...", true, 3);
|
|
GetItemJson(iid, b64);
|
|
}
|
|
//Utilities.Message.CMW(ex.Message, true, 3);
|
|
//Utilities.Message.CMW("URL: " + url, true, 3);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utilities.Message.CMW(ex.Message, true, 3);
|
|
}
|
|
}
|
|
|
|
public static double GetMin(string iid)
|
|
{
|
|
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).min;
|
|
}
|
|
|
|
public static double GetMax(string iid)
|
|
{
|
|
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).max;
|
|
}
|
|
|
|
public static string GetCurType(string iid)
|
|
{
|
|
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).currency;
|
|
}
|
|
|
|
public class PoEPricesRoot
|
|
{
|
|
public double min { get; set; }
|
|
|
|
public double max { get; set; }
|
|
|
|
public string currency { get; set; }
|
|
}
|
|
}
|
|
}
|