Files
MxWDB/MxWDB/JSON/AHUrl.cs

112 lines
3.4 KiB
C#

using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using static MxWDB.JSON.AHDump;
using static MxWDB.JSON.Token;
namespace MxWDB.JSON
{
class AHUrl
{
public class JSON
{
public string url { get; set; }
public long lastModified { get; set; }
}
public class RootObject
{
public List<JSON> files { get; set; }
}
public class Auction
{
public int id { get; set; }
public Item item { get; set; }
public Int64 buyout { get; set; }
public int quantity { get; set; }
public string time_left { get; set; }
}
public class Commodities
{
public string href { get; set; }
}
public class ConnectedRealm
{
public string href { get; set; }
}
public class Item
{
public int id { get; set; }
public int context { get; set; }
public List<int> bonus_lists { get; set; }
public List<Modifier> modifiers { get; set; }
}
public class Links
{
public Self self { get; set; }
}
public class Modifier
{
public int type { get; set; }
public int value { get; set; }
}
public class AuctionsRoot
{
public Links _links { get; set; }
public ConnectedRealm connected_realm { get; set; }
public List<Auction> auctions { get; set; }
public Commodities commodities { get; set; }
}
public class Self
{
public string href { get; set; }
}
private static readonly HttpClient client = new HttpClient();
public static async Task GetDump(string key, string secret, string token)
{
var ahRequest = new HttpRequestMessage(HttpMethod.Get, $"https://us.api.blizzard.com/data/wow/connected-realm/{Settings.GetRID()}/auctions?namespace=dynamic-us&locale=en_US");
// This is the critical part: Adding the token to the header
ahRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
var ahResponse = await client.SendAsync(ahRequest);
var content = await ahResponse.Content.ReadAsStringAsync();
string output = JsonConvert.SerializeObject(content, Formatting.Indented);
File.WriteAllText("json/ah.dump.json", output);
}
public static async Task GetDumpCom(string key, string secret, string token)
{
var ahRequest = new HttpRequestMessage(HttpMethod.Get, $"https://us.api.blizzard.com/data/wow/auctions/commodities?namespace=dynamic-us");
// This is the critical part: Adding the token to the header
ahRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
var ahResponse = await client.SendAsync(ahRequest);
var content = await ahResponse.Content.ReadAsStringAsync();
string output = JsonConvert.SerializeObject(content, Formatting.Indented);
File.WriteAllText("json/ah.com.dump.json", output);
}
}
}