Skip to content

Commit

Permalink
Deprecating GetSchema in favor of GetSchemaItems and GetSchemaOverview.
Browse files Browse the repository at this point in the history
  • Loading branch information
babelshift committed Dec 18, 2019
1 parent cb6702f commit 742c956
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 83 deletions.
5 changes: 0 additions & 5 deletions src/SteamWebAPI2/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public static void Initialize()
CreateSteamWebResponseMap<MatchHistoryBySequenceNumberResultContainer, IReadOnlyCollection<MatchHistoryMatchModel>>(x);
CreateSteamWebResponseMap<TeamInfoResultContainer, IReadOnlyCollection<TeamInfoModel>>(x);
CreateSteamWebResponseMap<EconItemResultContainer, EconItemResultModel>(x);
CreateSteamWebResponseMap<SchemaResultContainer, Steam.Models.TF2.SchemaModel>(x);
CreateSteamWebResponseMap<SchemaUrlResultContainer, string>(x);
CreateSteamWebResponseMap<StoreMetaDataResultContainer, StoreMetaDataModel>(x);
CreateSteamWebResponseMap<StoreStatusResultContainer, uint>(x);
Expand Down Expand Up @@ -139,7 +138,6 @@ public static void Initialize()

x.CreateMap<ItemIconPathResultContainer, string>().ConvertUsing(src => src.Result != null ? src.Result.Path : null);

x.CreateMap<SchemaResult, Steam.Models.TF2.SchemaModel>();
x.CreateMap<SchemaQualities, Steam.Models.TF2.SchemaQualitiesModel>();
x.CreateMap<SchemaOriginName, Steam.Models.TF2.SchemaOriginNameModel>();
x.CreateMap<SchemaItem, Steam.Models.TF2.SchemaItemModel>();
Expand All @@ -159,9 +157,6 @@ public static void Initialize()
x.CreateMap<SchemaKillEaterScoreType, Steam.Models.TF2.SchemaKillEaterScoreTypeModel>();
x.CreateMap<SchemaStringLookup, Steam.Models.TF2.SchemaStringLookupModel>();
x.CreateMap<SchemaString, Steam.Models.TF2.SchemaStringModel>();
x.CreateMap<SchemaResultContainer, Steam.Models.TF2.SchemaModel>().ConvertUsing(
src => Mapper.Map<SchemaResult, Steam.Models.TF2.SchemaModel>(src.Result)
);

// TODO: Rework the way Schema models are used for different games (TF2 / DOTA2)
//x.CreateMap<SchemaQualities, Steam.Models.DOTA2.SchemaQualityModel>()
Expand Down
26 changes: 11 additions & 15 deletions src/SteamWebAPI2/Interfaces/EconItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,32 @@ public async Task<ISteamWebResponse<EconItemResultModel>> GetPlayerItemsAsync(ul
}

/// <summary>
/// Returns the economy / item schema for a specific App ID.
/// Returns the item schema for TF2 specifically.
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
public async Task<ISteamWebResponse<Steam.Models.DOTA2.SchemaModel>> GetSchemaAsync(string language = "en_us")
public async Task<ISteamWebResponse<SchemaItemsResultContainer>> GetSchemaItemsForTF2Async(string language = "en_us")
{
if (!validSchemaAppIds.Contains(appId))
if (this.appId != (int)EconItemsAppId.TeamFortress2)
{
throw new InvalidOperationException(String.Format("AppId {0} is not valid for the GetSchema method.", appId));
throw new InvalidOperationException(String.Format("AppId {0} is not valid for the GetSchemaTF2 method.", appId));
}

List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();

parameters.AddIfHasValue(language, "language");

var steamWebResponse = await steamWebInterface.GetAsync<SchemaResultContainer>("GetSchema", 1, parameters);
var steamWebResponse = await steamWebInterface.GetAsync<SchemaItemsResultContainer>("GetSchemaItems", 1, parameters);

var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<ISteamWebResponse<SchemaResultContainer>, ISteamWebResponse<Steam.Models.DOTA2.SchemaModel>>(steamWebResponse);

return steamWebResponseModel;
return steamWebResponse;
}

/// <summary>
/// Returns the economy / item schema for TF2 specifically.
/// <summary>
/// Returns the schema overview for TF2 specifically.
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
public async Task<ISteamWebResponse<Steam.Models.TF2.SchemaModel>> GetSchemaForTF2Async(string language = "en_us")
public async Task<ISteamWebResponse<SchemaOverviewResultContainer>> GetSchemaOverviewForTF2Async(string language = "en_us")
{
if (this.appId != (int)EconItemsAppId.TeamFortress2)
{
Expand All @@ -124,11 +122,9 @@ public async Task<ISteamWebResponse<EconItemResultModel>> GetPlayerItemsAsync(ul

parameters.AddIfHasValue(language, "language");

var steamWebResponse = await steamWebInterface.GetAsync<SchemaResultContainer>("GetSchema", 1, parameters);

var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<ISteamWebResponse<SchemaResultContainer>, ISteamWebResponse<Steam.Models.TF2.SchemaModel>>(steamWebResponse);
var steamWebResponse = await steamWebInterface.GetAsync<SchemaOverviewResultContainer>("GetSchemaOverview", 1, parameters);

return steamWebResponseModel;
return steamWebResponse;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/SteamWebAPI2/Interfaces/IEconItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public interface IEconItems
{
Task<ISteamWebResponse<EconItemResultModel>> GetPlayerItemsAsync(ulong steamId);

Task<ISteamWebResponse<Steam.Models.DOTA2.SchemaModel>> GetSchemaAsync(string language = "en_us");
Task<ISteamWebResponse<SteamWebAPI2.Models.GameEconomy.SchemaItemsResultContainer>> GetSchemaItemsForTF2Async(string language = "en_us");

Task<ISteamWebResponse<Steam.Models.TF2.SchemaModel>> GetSchemaForTF2Async(string language = "en_us");
Task<ISteamWebResponse<SteamWebAPI2.Models.GameEconomy.SchemaOverviewResultContainer>> GetSchemaOverviewForTF2Async(string language = "en_us");

Task<ISteamWebResponse<string>> GetSchemaUrlAsync();

Expand Down
23 changes: 23 additions & 0 deletions src/SteamWebAPI2/Models/GameEconomy/SchemaItemResultContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace SteamWebAPI2.Models.GameEconomy
{
public class SchemaItemsResult
{
[JsonProperty("status")]
public uint Status { get; set; }
[JsonProperty("items_game_url")]
public string ItemsGameUrl { get; set; }
[JsonProperty("items")]
public IList<SchemaItem> Items { get; set; }
[JsonProperty("next")]
public uint Next { get; set; }
}

public class SchemaItemsResultContainer
{
[JsonProperty("result")]
public SchemaItemsResult Result { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace SteamWebAPI2.Models.GameEconomy
{
public class SchemaOverviewResult
{
[JsonProperty("status")]
public uint Status { get; set; }
[JsonProperty("items_game_url")]
public string ItemsGameUrl { get; set; }
[JsonProperty("qualities")]
public SchemaQualities Qualities { get; set; }
[JsonProperty("originNames")]
public IList<SchemaOriginName> OriginNames { get; set; }
[JsonProperty("attributes")]
public IList<SchemaAttribute> Attributes { get; set; }
[JsonProperty("item_sets")]
public IList<SchemaItemSet> ItemSets { get; set; }
[JsonProperty("attribute_controlled_attached_particles")]
public IList<SchemaAttributeControlledAttachedParticle> AttributeControlledAttachedParticles { get; set; }
[JsonProperty("item_levels")]
public IList<SchemaItemLevel> ItemLevels { get; set; }
[JsonProperty("kill_eater_score_types")]
public IList<SchemaKillEaterScoreType> KillEaterScoreTypes { get; set; }
[JsonProperty("string_lookups")]
public IList<SchemaStringLookup> StringLookups { get; set; }
}

public class SchemaOverviewResultContainer
{
[JsonProperty("result")]
public SchemaOverviewResult Result { get; set; }
}
}
80 changes: 19 additions & 61 deletions src/SteamWebAPI2/Models/GameEconomy/SchemaResultContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace SteamWebAPI2.Models.GameEconomy
{
internal class SchemaQualities
public class SchemaQualities
{
/// <summary>
/// Normal item rarity: https://wiki.teamfortress.com/wiki/Normal
Expand Down Expand Up @@ -99,7 +99,7 @@ internal class SchemaQualities
public uint PaintKitWeapon { get; set; }
}

internal class SchemaOriginName
public class SchemaOriginName
{
[JsonProperty("origin")]
public uint Origin { get; set; }
Expand All @@ -108,7 +108,7 @@ internal class SchemaOriginName
public string Name { get; set; }
}

internal class SchemaCapabilities
public class SchemaCapabilities
{
[JsonProperty("nameable")]
public bool Nameable { get; set; }
Expand Down Expand Up @@ -171,7 +171,7 @@ internal class SchemaCapabilities
public bool? Decodable { get; set; }
}

internal class SchemaAdditionalHiddenBodygroups
public class SchemaAdditionalHiddenBodygroups
{
[JsonProperty("hat")]
public uint Hat { get; set; }
Expand All @@ -183,7 +183,7 @@ internal class SchemaAdditionalHiddenBodygroups
public uint? Head { get; set; }
}

internal class SchemaStyle
public class SchemaStyle
{
[JsonProperty("name")]
public string Name { get; set; }
Expand All @@ -192,7 +192,7 @@ internal class SchemaStyle
public SchemaAdditionalHiddenBodygroups AdditionalHiddenBodygroups { get; set; }
}

internal class SchemaItemAttribute
public class SchemaItemAttribute
{
[JsonProperty("name")]
public string Name { get; set; }
Expand All @@ -204,7 +204,7 @@ internal class SchemaItemAttribute
public double Value { get; set; }
}

internal class SchemaPerClassLoadoutSlots
public class SchemaPerClassLoadoutSlots
{
[JsonProperty("Soldier")]
public string Soldier { get; set; }
Expand All @@ -222,7 +222,7 @@ internal class SchemaPerClassLoadoutSlots
public string Demoman { get; set; }
}

internal class SchemaUsageCapabilities
public class SchemaUsageCapabilities
{
[JsonProperty("nameable")]
public bool Nameable { get; set; }
Expand Down Expand Up @@ -264,7 +264,7 @@ internal class SchemaUsageCapabilities
public bool? CanConsume { get; set; }
}

internal class SchemaTool
public class SchemaTool
{
[JsonProperty("type")]
public string Type { get; set; }
Expand All @@ -279,7 +279,7 @@ internal class SchemaTool
public string Restriction { get; set; }
}

internal class SchemaItem
public class SchemaItem
{
[JsonProperty("defindex")]
public uint DefIndex { get; set; }
Expand Down Expand Up @@ -363,7 +363,7 @@ internal class SchemaItem
public SchemaTool Tool { get; set; }
}

internal class SchemaAttribute
public class SchemaAttribute
{
[JsonProperty("name")]
public string Name { get; set; }
Expand All @@ -390,7 +390,7 @@ internal class SchemaAttribute
public bool StoredAsInteger { get; set; }
}

internal class SchemaItemSetAttribute
public class SchemaItemSetAttribute
{
[JsonProperty("name")]
public string Name { get; set; }
Expand All @@ -402,7 +402,7 @@ internal class SchemaItemSetAttribute
public double Value { get; set; }
}

internal class SchemaItemSet
public class SchemaItemSet
{
[JsonProperty("item_set")]
public string ItemSet { get; set; }
Expand All @@ -420,7 +420,7 @@ internal class SchemaItemSet
public string StoreBundleName { get; set; }
}

internal class SchemaAttributeControlledAttachedParticle
public class SchemaAttributeControlledAttachedParticle
{
[JsonProperty("system")]
public string System { get; set; }
Expand All @@ -438,7 +438,7 @@ internal class SchemaAttributeControlledAttachedParticle
public string Attachment { get; set; }
}

internal class SchemaLevel
public class SchemaLevel
{
[JsonProperty("level")]
public uint Level { get; set; }
Expand All @@ -450,7 +450,7 @@ internal class SchemaLevel
public string Name { get; set; }
}

internal class SchemaItemLevel
public class SchemaItemLevel
{
[JsonProperty("name")]
public string Name { get; set; }
Expand All @@ -459,7 +459,7 @@ internal class SchemaItemLevel
public IList<SchemaLevel> Levels { get; set; }
}

internal class SchemaKillEaterScoreType
public class SchemaKillEaterScoreType
{
[JsonProperty("type")]
public uint Type { get; set; }
Expand All @@ -471,7 +471,7 @@ internal class SchemaKillEaterScoreType
public string LevelData { get; set; }
}

internal class SchemaString
public class SchemaString
{
[JsonProperty("index")]
public uint Index { get; set; }
Expand All @@ -480,54 +480,12 @@ internal class SchemaString
public string String { get; set; }
}

internal class SchemaStringLookup
public class SchemaStringLookup
{
[JsonProperty("table_name")]
public string TableName { get; set; }

[JsonProperty("strings")]
public IList<SchemaString> Strings { get; set; }
}

internal class SchemaResult
{
[JsonProperty("status")]
public uint Status { get; set; }

[JsonProperty("items_game_url")]
public string ItemsGameUrl { get; set; }

[JsonProperty("qualities")]
public SchemaQualities Qualities { get; set; }

[JsonProperty("originNames")]
public IList<SchemaOriginName> OriginNames { get; set; }

[JsonProperty("items")]
public IList<SchemaItem> Items { get; set; }

[JsonProperty("attributes")]
public IList<SchemaAttribute> Attributes { get; set; }

[JsonProperty("item_sets")]
public IList<SchemaItemSet> ItemSets { get; set; }

[JsonProperty("attribute_controlled_attached_particles")]
public IList<SchemaAttributeControlledAttachedParticle> AttributeControlledAttachedParticles { get; set; }

[JsonProperty("item_levels")]
public IList<SchemaItemLevel> ItemLevels { get; set; }

[JsonProperty("kill_eater_score_types")]
public IList<SchemaKillEaterScoreType> KillEaterScoreTypes { get; set; }

[JsonProperty("string_lookups")]
public IList<SchemaStringLookup> StringLookups { get; set; }
}

internal class SchemaResultContainer
{
[JsonProperty("result")]
public SchemaResult Result { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/SteamWebAPI2/Utilities/SteamWebInterfaceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public T CreateSteamWebInterface<T>(HttpClient httpClient)
return (T)Activator.CreateInstance(typeof(T), steamWebRequest, null);
}

/// <summary>
/// Creates a web interface object connected to a specific Steam Web API interfac endpoint
/// </summary>
/// <param name="httpClient">Custom http client injected with your customization (if necessary)</param>
/// <typeparam name="T">Type of the web interface to create</typeparam>
/// <returns>Instance of the web interface</returns>
public T CreateSteamWebInterface<T>(HttpClient httpClient, EconItemsAppId appId)
{
var steamWebRequest = CreateSteamWebRequest(httpClient);
return (T)Activator.CreateInstance(typeof(T), steamWebRequest, appId, null);
}

private ISteamWebRequest CreateSteamWebRequest(HttpClient httpClient)
{
SteamWebHttpClient steamWebHttpClient = new SteamWebHttpClient(httpClient);
Expand Down

0 comments on commit 742c956

Please sign in to comment.