-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jackofdiamond5/bpenkov/1.0.2
Bpenkov/1.0.2
- Loading branch information
Showing
7 changed files
with
218 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/BackpackTfApi/Exceptions/ClassifiedCreationFailureException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace BackpackTfApi.Exceptions | ||
{ | ||
public class ClassifiedCreationFailureException : Exception | ||
{ | ||
public ClassifiedCreationFailureException(string message) | ||
: base(message) { } | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/BackpackTfApi/Exceptions/ItemCreationFailureException.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 107 additions & 1 deletion
108
src/BackpackTfApi/SteamUser/UserInventory/Models/InventoryItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,121 @@ | ||
namespace BackpackTfApi.SteamUser.UserInventory.Models | ||
using System; | ||
using System.Linq; | ||
|
||
using BackpackTfApi.Static; | ||
using BackpackTfApi.Exceptions; | ||
|
||
namespace BackpackTfApi.SteamUser.UserInventory.Models | ||
{ | ||
/// <summary> | ||
/// A Steam inventory item. | ||
/// </summary> | ||
public class InventoryItem | ||
{ | ||
private const string TargetTag = "quality"; | ||
|
||
public InventoryItem(Asset asset, Description description) | ||
{ | ||
this.Asset = asset; | ||
this.Description = description; | ||
} | ||
|
||
/// <summary> | ||
/// The name of the item. | ||
/// </summary> | ||
public string Name | ||
{ | ||
get | ||
{ | ||
if (string.IsNullOrWhiteSpace(this.Description.MarketHashName)) | ||
{ | ||
throw new ItemNotFoundException(Messages.ItemNotFoundError); | ||
} | ||
|
||
return this.Description.MarketHashName; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The quality name of the specified item. | ||
/// </summary> | ||
public string QualityName | ||
{ | ||
get | ||
{ | ||
try | ||
{ | ||
return this.Description | ||
.Tags | ||
.Where(t => t.Category.ToLower() == TargetTag) | ||
.First() | ||
.InternalName; | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
throw new ItemNotFoundException(Messages.ItemNotFoundError); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The quality index of the specified item. | ||
/// </summary> | ||
public string QualityIndex => this.GetItemQualityIndex(); | ||
|
||
/// <summary> | ||
/// The Steam inventory's asset object. | ||
/// </summary> | ||
public Asset Asset { get; internal set; } | ||
|
||
/// <summary> | ||
/// The Steam inventory's description object. | ||
/// </summary> | ||
public Description Description { get; internal set; } | ||
|
||
private string GetItemQualityIndex() | ||
{ | ||
try | ||
{ | ||
return this.GetIndex(this.QualityName); | ||
} | ||
catch (ItemNotFoundException) | ||
{ | ||
return this.GetIndex(this.Name); | ||
} | ||
} | ||
|
||
private string GetIndex(string value) | ||
{ | ||
var quality = value.Split().Take(1).ToArray()[0].ToLower(); | ||
switch (quality) | ||
{ | ||
case "normal": | ||
return "0"; | ||
case "genuine": | ||
return "1"; | ||
case "vintage": | ||
return "3"; | ||
case "unusual": | ||
return "5"; | ||
case "unique": | ||
return "6"; | ||
case "community": | ||
return "7"; | ||
case "valve": | ||
return "8"; | ||
case "self-made": | ||
return "9"; | ||
case "strange": | ||
return "11"; | ||
case "haunted": | ||
return "13"; | ||
case "collector's": | ||
return "14"; | ||
case "decorated": | ||
return "15"; | ||
default: | ||
throw new ArgumentException(Messages.ItemQualityError); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters