Added basic REST service support and object types for Wise Old Man usage.
This commit is contained in:
150
osrs-toolbox/APIs/RestServices.cs
Normal file
150
osrs-toolbox/APIs/RestServices.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using System.IO;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides easy access to GET and POST functionality for REST services.
|
||||
/// </summary>
|
||||
internal static class RestServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends GET request to REST service and returns response asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="uri">Address to send request to.</param>
|
||||
/// <param name="APIKey">API key to use with the request.</param>
|
||||
/// <returns>JSON data as string.</returns>
|
||||
internal static async Task<string> GetResponseAsync(Uri uri, string APIKey)
|
||||
{
|
||||
//Create client to send GET request
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
//Add request headers
|
||||
client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome / 58.0.3029.110 Safari / 537.36");
|
||||
client.DefaultRequestHeaders.Add("X-Authorization", APIKey);
|
||||
//Send request and await response
|
||||
string response = await client.GetStringAsync(uri).ConfigureAwait(false);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends GET request to REST service and returns response asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="uri">Address to send request to.</param>
|
||||
/// <returns>JSON data as string.</returns>
|
||||
internal static async Task<string> GetResponseAsync(Uri uri)
|
||||
{
|
||||
//Create client to send GET request
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
//Add request headers
|
||||
client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome / 58.0.3029.110 Safari / 537.36");
|
||||
//Send request and await response
|
||||
string response = await client.GetStringAsync(uri).ConfigureAwait(false);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends GET request to REST service and returns response.
|
||||
/// </summary>
|
||||
/// <param name="uri">Address to send request to.</param>
|
||||
/// <param name="APIKey">API key to use with the request.</param>
|
||||
/// <returns>JSON data as string.</returns>
|
||||
internal static string GetResponse(Uri uri, string APIKey)
|
||||
{
|
||||
//Create client to send GET request
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
//Add request headers
|
||||
client.Headers.Add(string.Format("X-Authorization: {0}", APIKey));
|
||||
client.Headers.Add(HttpRequestHeader.Accept, "application/json");
|
||||
client.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US");
|
||||
//Send request and await response
|
||||
using (Stream ReqStream = client.OpenRead(uri))
|
||||
using (StreamReader Reader = new StreamReader(ReqStream))
|
||||
{
|
||||
string response = Reader.ReadToEnd();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends GET request to REST service and returns response.
|
||||
/// </summary>
|
||||
/// <param name="uri">Address to send request to.</param>
|
||||
/// <returns>JSON data as string.</returns>
|
||||
internal static string GetResponse(Uri uri)
|
||||
{
|
||||
//Create client to send GET request
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
//Add request headers
|
||||
client.Headers.Add(HttpRequestHeader.Accept, "application/json");
|
||||
client.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US");
|
||||
//Send request and await response
|
||||
using (Stream ReqStream = client.OpenRead(uri))
|
||||
using (StreamReader Reader = new StreamReader(ReqStream))
|
||||
{
|
||||
string response = Reader.ReadToEnd();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends POST request to REST service with JSON data and returns response asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="uri">Web address to send request.</param>
|
||||
/// <param name="Data">JSON data to send with request.</param>
|
||||
/// <param name="APIKey">API key to use with the request.</param>
|
||||
/// <returns>JSON data as string.</returns>
|
||||
internal static async Task<string> GetPostResponseAsync(Uri uri, string Data, string APIKey)
|
||||
{
|
||||
//Create Client to send and receive data from REST service
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
//Add headers for request
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome / 58.0.3029.110 Safari / 537.36");
|
||||
client.DefaultRequestHeaders.Add("X-Authorization", APIKey);
|
||||
client.DefaultRequestHeaders.Host = uri.Host;
|
||||
//Create content to send from JSON string
|
||||
HttpContent content = new StringContent(Data, Encoding.UTF8, @"application/json");
|
||||
//Send POST request and await response
|
||||
HttpResponseMessage response = await client.PostAsync(uri, content).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
//Return response JSON as string
|
||||
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends POST request to REST service with JSON data and returns response.
|
||||
/// </summary>
|
||||
/// <param name="uri">Web address to send request.</param>
|
||||
/// <param name="Data">JSON data to send with request.</param>
|
||||
/// <param name="APIKey">API key to use with the request.</param>
|
||||
/// <returns>JSON data as string.</returns>
|
||||
internal static string GetPostResponse(Uri uri, string Data, string APIKey)
|
||||
{
|
||||
//Create client to send POST request
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
//Add request headers
|
||||
client.Headers.Add(string.Format("X-Authorization: {0}", APIKey));
|
||||
client.Headers.Add(HttpRequestHeader.Accept, "application/json");
|
||||
client.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US");
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
//Send POST request and await response
|
||||
string response = client.UploadString(uri, Data);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
osrs-toolbox/APIs/WiseOldMan/Competition/Competition.cs
Normal file
20
osrs-toolbox/APIs/WiseOldMan/Competition/Competition.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class Competition
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string title { get; set; }
|
||||
public string metric { get; set; }
|
||||
public string type { get; set; }
|
||||
public DateTime startsAt { get; set; }
|
||||
public DateTime endsAt { get; set; }
|
||||
public int groupId { get; set; }
|
||||
public int score { get; set; }
|
||||
public bool visible { get; set; }
|
||||
public DateTime createdAt { get; set; }
|
||||
public DateTime updatedAt { get; set; }
|
||||
public Group group { get; set; }
|
||||
public int participantCount { get; set; }
|
||||
public CompetitionParticipation[] participations { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class CompetitionParticipation
|
||||
{
|
||||
public int playerId { get; set; }
|
||||
public int competitionId { get; set; }
|
||||
public string? teamName { get; set; }
|
||||
public DateTime createdAt { get; set; }
|
||||
public DateTime updatedAt { get; set; }
|
||||
public Player player { get; set; }
|
||||
public ParticipationInfo progress { get; set; }
|
||||
public ParticipationInfo levels { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class ParticipationInfo
|
||||
{
|
||||
public int gained { get; set; }
|
||||
public int start { get; set; }
|
||||
public int end { get; set; }
|
||||
}
|
||||
}
|
23
osrs-toolbox/APIs/WiseOldMan/Group/Group.cs
Normal file
23
osrs-toolbox/APIs/WiseOldMan/Group/Group.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string clanChat { get; set; }
|
||||
public string description { get; set; }
|
||||
public int homeworld { get; set; }
|
||||
public bool verified { get; set; }
|
||||
public bool patron { get; set; }
|
||||
public bool visible { get; set; }
|
||||
public object profileImage { get; set; }
|
||||
public object bannerImage { get; set; }
|
||||
public int score { get; set; }
|
||||
public DateTime createdAt { get; set; }
|
||||
public DateTime updatedAt { get; set; }
|
||||
public GroupMembership[]? memberships { get; set; }
|
||||
public GroupLinks? socialLinks { get; set; }
|
||||
public object[]? roleOrders { get; set; }
|
||||
public int memberCount { get; set; }
|
||||
}
|
||||
}
|
11
osrs-toolbox/APIs/WiseOldMan/Group/GroupLinks.cs
Normal file
11
osrs-toolbox/APIs/WiseOldMan/Group/GroupLinks.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class GroupLinks
|
||||
{
|
||||
public string website { get; set; }
|
||||
public string discord { get; set; }
|
||||
public string twitter { get; set; }
|
||||
public string youtube { get; set; }
|
||||
public string twitch { get; set; }
|
||||
}
|
||||
}
|
12
osrs-toolbox/APIs/WiseOldMan/Group/GroupMembership.cs
Normal file
12
osrs-toolbox/APIs/WiseOldMan/Group/GroupMembership.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class GroupMembership
|
||||
{
|
||||
public int playerId { get; set; }
|
||||
public int groupId { get; set; }
|
||||
public string role { get; set; }
|
||||
public DateTime createdAt { get; set; }
|
||||
public DateTime updatedAt { get; set; }
|
||||
public Player player { get; set; }
|
||||
}
|
||||
}
|
9
osrs-toolbox/APIs/WiseOldMan/Player/ActivityData.cs
Normal file
9
osrs-toolbox/APIs/WiseOldMan/Player/ActivityData.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class ActivityData
|
||||
{
|
||||
public string metric { get; set; }
|
||||
public int score { get; set; }
|
||||
public int rank { get; set; }
|
||||
}
|
||||
}
|
10
osrs-toolbox/APIs/WiseOldMan/Player/BossData.cs
Normal file
10
osrs-toolbox/APIs/WiseOldMan/Player/BossData.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class BossData
|
||||
{
|
||||
public string metric { get; set; }
|
||||
public int kills { get; set; }
|
||||
public int rank { get; set; }
|
||||
public double ehb { get; set; }
|
||||
}
|
||||
}
|
9
osrs-toolbox/APIs/WiseOldMan/Player/ComputedData.cs
Normal file
9
osrs-toolbox/APIs/WiseOldMan/Player/ComputedData.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class ComputedData
|
||||
{
|
||||
public string metric { get; set; }
|
||||
public double value { get; set; }
|
||||
public int rank { get; set; }
|
||||
}
|
||||
}
|
27
osrs-toolbox/APIs/WiseOldMan/Player/Player.cs
Normal file
27
osrs-toolbox/APIs/WiseOldMan/Player/Player.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class Player
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string username { get; set; }
|
||||
public string displayName { get; set; }
|
||||
public string type { get; set; }
|
||||
public string build { get; set; }
|
||||
public string status { get; set; }
|
||||
public string country { get; set; }
|
||||
public bool patron { get; set; }
|
||||
public int exp { get; set; }
|
||||
public double ehp { get; set; }
|
||||
public double ehb { get; set; }
|
||||
public double ttm { get; set; }
|
||||
public double tt200m { get; set; }
|
||||
public string registeredAt { get; set; }
|
||||
public string updatedAt { get; set; }
|
||||
public string lastChangedAt { get; set; }
|
||||
public string lastImportedAt { get; set; }
|
||||
public Snapshot? latestSnapshot { get; set; }
|
||||
public string[]? annotations { get; set; }
|
||||
public int? combatLevel { get; set; }
|
||||
public object? archive { get; set; }
|
||||
}
|
||||
}
|
22
osrs-toolbox/APIs/WiseOldMan/Player/PlayerActivities.cs
Normal file
22
osrs-toolbox/APIs/WiseOldMan/Player/PlayerActivities.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class PlayerActivities
|
||||
{
|
||||
public ActivityData league_points { get; set; }
|
||||
public ActivityData bounty_hunter_hunter { get; set; }
|
||||
public ActivityData bounty_hunter_rogue { get; set; }
|
||||
public ActivityData clue_scrolls_all { get; set; }
|
||||
public ActivityData clue_scrolls_beginner { get; set; }
|
||||
public ActivityData clue_scrolls_easy { get; set; }
|
||||
public ActivityData clue_scrolls_medium { get; set; }
|
||||
public ActivityData clue_scrolls_hard { get; set; }
|
||||
public ActivityData clue_scrolls_elite { get; set; }
|
||||
public ActivityData clue_scrolls_master { get; set; }
|
||||
public ActivityData last_man_standing { get; set; }
|
||||
public ActivityData pvp_arena { get; set; }
|
||||
public ActivityData soul_wars_zeal { get; set; }
|
||||
public ActivityData guardians_of_the_rift { get; set; }
|
||||
public ActivityData colosseum_glory { get; set; }
|
||||
public ActivityData collections_logged { get; set; }
|
||||
}
|
||||
}
|
72
osrs-toolbox/APIs/WiseOldMan/Player/PlayerBosses.cs
Normal file
72
osrs-toolbox/APIs/WiseOldMan/Player/PlayerBosses.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class PlayerBosses
|
||||
{
|
||||
public BossData abyssal_sire { get; set; }
|
||||
public BossData alchemical_hydra { get; set; }
|
||||
public BossData amoxliatl { get; set; }
|
||||
public BossData araxxor { get; set; }
|
||||
public BossData artio { get; set; }
|
||||
public BossData barrows_chests { get; set; }
|
||||
public BossData bryophyta { get; set; }
|
||||
public BossData callisto { get; set; }
|
||||
public BossData calvarion { get; set; }
|
||||
public BossData cerberus { get; set; }
|
||||
public BossData chambers_of_xeric { get; set; }
|
||||
public BossData chambers_of_xeric_challenge_mode { get; set; }
|
||||
public BossData chaos_elemental { get; set; }
|
||||
public BossData chaos_fanatic { get; set; }
|
||||
public BossData commander_zilyana { get; set; }
|
||||
public BossData corporeal_beast { get; set; }
|
||||
public BossData crazy_archaeologist { get; set; }
|
||||
public BossData dagannoth_prime { get; set; }
|
||||
public BossData dagannoth_rex { get; set; }
|
||||
public BossData dagannoth_supreme { get; set; }
|
||||
public BossData deranged_archaeologist { get; set; }
|
||||
public BossData duke_sucellus { get; set; }
|
||||
public BossData general_graardor { get; set; }
|
||||
public BossData giant_mole { get; set; }
|
||||
public BossData grotesque_guardians { get; set; }
|
||||
public BossData hespori { get; set; }
|
||||
public BossData kalphite_queen { get; set; }
|
||||
public BossData king_black_dragon { get; set; }
|
||||
public BossData kraken { get; set; }
|
||||
public BossData kreearra { get; set; }
|
||||
public BossData kril_tsutsaroth { get; set; }
|
||||
public BossData lunar_chests { get; set; }
|
||||
public BossData mimic { get; set; }
|
||||
public BossData nex { get; set; }
|
||||
public BossData nightmare { get; set; }
|
||||
public BossData phosanis_nightmare { get; set; }
|
||||
public BossData obor { get; set; }
|
||||
public BossData phantom_muspah { get; set; }
|
||||
public BossData sarachnis { get; set; }
|
||||
public BossData scorpia { get; set; }
|
||||
public BossData scurrius { get; set; }
|
||||
public BossData skotizo { get; set; }
|
||||
public BossData sol_heredit { get; set; }
|
||||
public BossData spindel { get; set; }
|
||||
public BossData tempoross { get; set; }
|
||||
public BossData the_gauntlet { get; set; }
|
||||
public BossData the_corrupted_gauntlet { get; set; }
|
||||
public BossData the_hueycoatl { get; set; }
|
||||
public BossData the_leviathan { get; set; }
|
||||
public BossData the_royal_titans { get; set; }
|
||||
public BossData the_whisperer { get; set; }
|
||||
public BossData theatre_of_blood { get; set; }
|
||||
public BossData theatre_of_blood_hard_mode { get; set; }
|
||||
public BossData thermonuclear_smoke_devil { get; set; }
|
||||
public BossData tombs_of_amascut { get; set; }
|
||||
public BossData tombs_of_amascut_expert { get; set; }
|
||||
public BossData tzkal_zuk { get; set; }
|
||||
public BossData tztok_jad { get; set; }
|
||||
public BossData vardorvis { get; set; }
|
||||
public BossData venenatis { get; set; }
|
||||
public BossData vetion { get; set; }
|
||||
public BossData vorkath { get; set; }
|
||||
public BossData wintertodt { get; set; }
|
||||
public BossData yama { get; set; }
|
||||
public BossData zalcano { get; set; }
|
||||
public BossData zulrah { get; set; }
|
||||
}
|
||||
}
|
8
osrs-toolbox/APIs/WiseOldMan/Player/PlayerComputed.cs
Normal file
8
osrs-toolbox/APIs/WiseOldMan/Player/PlayerComputed.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class PlayerComputed
|
||||
{
|
||||
public ComputedData ehp { get; set; }
|
||||
public ComputedData ehb { get; set; }
|
||||
}
|
||||
}
|
30
osrs-toolbox/APIs/WiseOldMan/Player/PlayerSkills.cs
Normal file
30
osrs-toolbox/APIs/WiseOldMan/Player/PlayerSkills.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class PlayerSkills
|
||||
{
|
||||
public SkillData overall { get; set; }
|
||||
public SkillData attack { get; set; }
|
||||
public SkillData defence { get; set; }
|
||||
public SkillData strength { get; set; }
|
||||
public SkillData hitpoints { get; set; }
|
||||
public SkillData ranged { get; set; }
|
||||
public SkillData prayer { get; set; }
|
||||
public SkillData magic { get; set; }
|
||||
public SkillData cooking { get; set; }
|
||||
public SkillData woodcutting { get; set; }
|
||||
public SkillData fletching { get; set; }
|
||||
public SkillData fishing { get; set; }
|
||||
public SkillData firemaking { get; set; }
|
||||
public SkillData crafting { get; set; }
|
||||
public SkillData smithing { get; set; }
|
||||
public SkillData mining { get; set; }
|
||||
public SkillData herblore { get; set; }
|
||||
public SkillData agility { get; set; }
|
||||
public SkillData thieving { get; set; }
|
||||
public SkillData slayer { get; set; }
|
||||
public SkillData farming { get; set; }
|
||||
public SkillData runecrafting { get; set; }
|
||||
public SkillData hunter { get; set; }
|
||||
public SkillData construction { get; set; }
|
||||
}
|
||||
}
|
11
osrs-toolbox/APIs/WiseOldMan/Player/SkillData.cs
Normal file
11
osrs-toolbox/APIs/WiseOldMan/Player/SkillData.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class SkillData
|
||||
{
|
||||
public string metric { get; set; }
|
||||
public int experience { get; set; }
|
||||
public int rank { get; set; }
|
||||
public int level { get; set; }
|
||||
public double ehp { get; set; }
|
||||
}
|
||||
}
|
11
osrs-toolbox/APIs/WiseOldMan/Player/Snapshot.cs
Normal file
11
osrs-toolbox/APIs/WiseOldMan/Player/Snapshot.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class Snapshot
|
||||
{
|
||||
public int id { get; set; }
|
||||
public int playerId { get; set; }
|
||||
public string createdAt { get; set; }
|
||||
public string importedAt { get; set; }
|
||||
public SnapshotData data { get; set; }
|
||||
}
|
||||
}
|
10
osrs-toolbox/APIs/WiseOldMan/Player/SnapshotData.cs
Normal file
10
osrs-toolbox/APIs/WiseOldMan/Player/SnapshotData.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace osrs_toolbox
|
||||
{
|
||||
public class SnapshotData
|
||||
{
|
||||
public PlayerSkills skills { get; set; }
|
||||
public PlayerBosses bosses { get; set; }
|
||||
public PlayerActivities activities { get; set; }
|
||||
public PlayerComputed computed { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user