Skip to content

Commit 9043b72

Browse files
author
babelshift
committed
Added wrapper for GetRarities and GetItemIconPath from DOTA2 interface.
Removed some string replacements for JSON response for now because it's messing with some valid responses.
1 parent e587a85 commit 9043b72

8 files changed

Lines changed: 113 additions & 6 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class ItemIconPathResult
10+
{
11+
public string Path { get; set; }
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class ItemIconPathResultContainer
10+
{
11+
public ItemIconPathResult Result { get; set; }
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class Rarity
10+
{
11+
public string Name { get; set; }
12+
public int Id { get; set; }
13+
public int Order { get; set; }
14+
public string Color { get; set; }
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class RarityResult
10+
{
11+
public int Count { get; set; }
12+
public int Status { get; set; }
13+
public IList<Rarity> Rarities { get; set; }
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamWebAPI2.Models.DOTA2
8+
{
9+
public class RarityResultContainer
10+
{
11+
public RarityResult Result { get; set; }
12+
}
13+
}

SteamWebAPI2.Models/SteamWebAPI2.Models.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
<Compile Include="DOTA2\Hero.cs" />
6363
<Compile Include="DOTA2\HeroResult.cs" />
6464
<Compile Include="DOTA2\HeroResultContainer.cs" />
65+
<Compile Include="DOTA2\ItemIconPathResult.cs" />
66+
<Compile Include="DOTA2\ItemIconPathResultContainer.cs" />
6567
<Compile Include="DOTA2\League.cs" />
6668
<Compile Include="DOTA2\LeagueResult.cs" />
6769
<Compile Include="DOTA2\LeagueResultContainer.cs" />
@@ -95,6 +97,9 @@
9597
<Compile Include="DOTA2\PlayerOfficialInfoResultContainer.cs" />
9698
<Compile Include="DOTA2\ProPlayerInfo.cs" />
9799
<Compile Include="DOTA2\ProPlayerLeaderboard.cs" />
100+
<Compile Include="DOTA2\Rarity.cs" />
101+
<Compile Include="DOTA2\RarityResult.cs" />
102+
<Compile Include="DOTA2\RarityResultContainer.cs" />
98103
<Compile Include="DOTA2\TeamInfoResult.cs" />
99104
<Compile Include="DOTA2\TeamInfo.cs" />
100105
<Compile Include="DOTA2\TeamInfoResultContainer.cs" />

SteamWebAPI2/DOTA2Econ.cs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public async Task<IReadOnlyCollection<GameItem>> GetGameItemsAsync(string langua
3333

3434
AddToParametersIfHasValue("language", language, parameters);
3535

36-
var teamInfos = await CallMethodAsync<GameItemResultContainer>("GetGameItems", 1);
37-
return new ReadOnlyCollection<GameItem>(teamInfos.Result.Items);
36+
var gameItems = await CallMethodAsync<GameItemResultContainer>("GetGameItems", 1);
37+
return new ReadOnlyCollection<GameItem>(gameItems.Result.Items);
3838
}
3939

4040
public async Task<IReadOnlyCollection<Hero>> GetHeroesAsync(string language = "", bool itemizedOnly = false)
@@ -46,8 +46,40 @@ public async Task<IReadOnlyCollection<Hero>> GetHeroesAsync(string language = ""
4646
AddToParametersIfHasValue("language", language, parameters);
4747
AddToParametersIfHasValue("itemizedonly", itemizedOnlyValue, parameters);
4848

49-
var teamInfos = await CallMethodAsync<HeroResultContainer>("GetHeroes", 1);
50-
return new ReadOnlyCollection<Hero>(teamInfos.Result.Heroes);
49+
var heroes = await CallMethodAsync<HeroResultContainer>("GetHeroes", 1);
50+
return new ReadOnlyCollection<Hero>(heroes.Result.Heroes);
51+
}
52+
53+
/// <summary>
54+
/// It is important to note that the "items" this method is referring to are not the in game items. These are actually cosmetic items found in the DOTA 2 store and workshop.
55+
/// </summary>
56+
/// <param name="iconName"></param>
57+
/// <param name="iconType"></param>
58+
/// <returns></returns>
59+
public async Task<string> GetItemIconPathAsync(string iconName, string iconType = "")
60+
{
61+
if(String.IsNullOrEmpty(iconName))
62+
{
63+
throw new ArgumentNullException("iconName");
64+
}
65+
66+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
67+
68+
AddToParametersIfHasValue("iconname", iconName, parameters);
69+
AddToParametersIfHasValue("icontype", iconType, parameters);
70+
71+
var itemIconPath = await CallMethodAsync<ItemIconPathResultContainer>("GetItemIconPath", 1);
72+
return itemIconPath.Result.Path;
73+
}
74+
75+
public async Task<RarityResult> GetRaritiesAsync(string language = "")
76+
{
77+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
78+
79+
AddToParametersIfHasValue("language", language, parameters);
80+
81+
var raritiesContainer = await CallMethodAsync<RarityResultContainer>("GetRarities", 1);
82+
return raritiesContainer.Result;
5183
}
5284
}
5385
}

SteamWebAPI2/SteamWebRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public async Task<T> GetJsonAsync<T>(string interfaceName, string methodName, in
5959
response = response.Replace("\n", "");
6060
response = response.Replace("\t", "");
6161
//response = response.Replace("\\", "");
62-
response = response.Replace("\"{", "{");
63-
response = response.Replace("\"}", "}");
62+
//response = response.Replace("\"{", "{");
63+
//response = response.Replace("\"}", "}");
6464

6565
var deserializedResult = JsonConvert.DeserializeObject<T>(response);
6666
return deserializedResult;

0 commit comments

Comments
 (0)