From a4e6de29e1bff624c959881249a6d547abf6632c Mon Sep 17 00:00:00 2001 From: Kamran Ayub Date: Mon, 26 Jan 2015 15:01:09 +0100 Subject: [PATCH] [Closes #15, Closes #14, Closes #13] --- .../GiantBomb.Api.Tests.csproj | 8 +++---- GiantBomb.Api.Tests/packages.config | 4 ++-- GiantBomb.Api/Core.cs | 22 ++++++++++++------- GiantBomb.Api/GiantBomb.Api.csproj | 6 +++-- GiantBomb.Api/GiantBomb.Api.nuspec | 2 +- GiantBomb.Api/GiantBombApiException.cs | 15 +++++++++++++ GiantBomb.Api/Model/Franchise.cs | 21 ++++++++++++++++++ GiantBomb.Api/Model/Game.cs | 1 + GiantBomb.Api/Model/GiantBombBase.cs | 5 +++++ GiantBomb.Api/Model/Platform.cs | 4 ++++ GiantBomb.Api/Model/Release.cs | 1 + GiantBomb.Api/Properties/AssemblyInfo.cs | 8 +++---- GiantBomb.Api/packages.config | 2 +- GiantBomb.Api/readme.txt | 14 ++++++++++++ Readme.md | 14 ++++++++++++ 15 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 GiantBomb.Api/GiantBombApiException.cs create mode 100644 GiantBomb.Api/Model/Franchise.cs diff --git a/GiantBomb.Api.Tests/GiantBomb.Api.Tests.csproj b/GiantBomb.Api.Tests/GiantBomb.Api.Tests.csproj index 3b95e80..5081626 100644 --- a/GiantBomb.Api.Tests/GiantBomb.Api.Tests.csproj +++ b/GiantBomb.Api.Tests/GiantBomb.Api.Tests.csproj @@ -33,13 +33,13 @@ 4 - + False - ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - + False - ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll + ..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll diff --git a/GiantBomb.Api.Tests/packages.config b/GiantBomb.Api.Tests/packages.config index 61913e4..7733ef3 100644 --- a/GiantBomb.Api.Tests/packages.config +++ b/GiantBomb.Api.Tests/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/GiantBomb.Api/Core.cs b/GiantBomb.Api/Core.cs index c39d543..50913bd 100644 --- a/GiantBomb.Api/Core.cs +++ b/GiantBomb.Api/Core.cs @@ -32,11 +32,11 @@ public GiantBombRestClient(string apiToken, Uri baseUrl) { var assembly = Assembly.GetExecutingAssembly(); var version = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion; - + _client = new RestClient { - UserAgent = "giantbomb-csharp/" + version, - BaseUrl = BaseUrl + UserAgent = "giantbomb-csharp/" + version, + BaseUrl = baseUrl }; // API token is used on every request @@ -58,7 +58,7 @@ public GiantBombRestClient(string apiToken) /// /// The type of object to create and populate with the returned data. /// The RestRequest to execute (will use client credentials) - public T Execute(RestRequest request) where T : new() { + public virtual T Execute(RestRequest request) where T : new() { var response = _client.Execute(request); return response.Data; } @@ -67,7 +67,7 @@ public GiantBombRestClient(string apiToken) /// Execute a manual REST request /// /// The RestRequest to execute (will use client credentials) - public IRestResponse Execute(RestRequest request) { + public virtual IRestResponse Execute(RestRequest request) { return _client.Execute(request); } #endif @@ -77,13 +77,13 @@ public virtual RestRequest GetListResource(string resource, int page = 1, int pa throw new ArgumentOutOfRangeException("pageSize", "Page size cannot be greater than " + GiantBombBase.DefaultLimit + "."); var request = new RestRequest { - Resource = resource + "//", + Resource = resource + "/", DateFormat = "yyyy-MM-dd HH:mm:ss" }; if (page > 1) { - // HACK: Giant Bomb uses `page` for search instead of `offset`, assholes + // HACK: Giant Bomb uses `page` for search instead of `offset` if (resource == "search") { request.AddParameter("page", page); } @@ -131,12 +131,15 @@ private string BuildKeyValueListForUrl(IEnumerable ..\Dependencies\fastJSON.dll - + False - ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll + ..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll @@ -51,6 +51,8 @@ + + diff --git a/GiantBomb.Api/GiantBomb.Api.nuspec b/GiantBomb.Api/GiantBomb.Api.nuspec index 34f1289..444ae43 100644 --- a/GiantBomb.Api/GiantBomb.Api.nuspec +++ b/GiantBomb.Api/GiantBomb.Api.nuspec @@ -9,7 +9,7 @@ http://github.com/kamranayub/GiantBomb-CSharp false RestSharp-based API wrapper for the GiantBomb games database public API - Copyright © kayub 2012 + Copyright © kayub 2015 Updated with fixes, see README. diff --git a/GiantBomb.Api/GiantBombApiException.cs b/GiantBomb.Api/GiantBombApiException.cs new file mode 100644 index 0000000..026ffd5 --- /dev/null +++ b/GiantBomb.Api/GiantBombApiException.cs @@ -0,0 +1,15 @@ +using System; + +namespace GiantBomb.Api +{ + public class GiantBombApiException : Exception + { + public int StatusCode { get; private set; } + + public GiantBombApiException(int statusCode, string error) + : base("GiantBomb API Error: " + statusCode + ": " + error) + { + StatusCode = statusCode; + } + } +} \ No newline at end of file diff --git a/GiantBomb.Api/Model/Franchise.cs b/GiantBomb.Api/Model/Franchise.cs new file mode 100644 index 0000000..9d2252d --- /dev/null +++ b/GiantBomb.Api/Model/Franchise.cs @@ -0,0 +1,21 @@ +using System; + +namespace GiantBomb.Api.Model +{ + public class Franchise + { + /// + /// Newline-delimited list of aliases + /// + public string Aliases { get; set; } + public int Id { get; set; } + public string Name { get; set; } + public string SiteDetailUrl { get; set; } + public string ApiDetailUrl { get; set; } + public DateTime DateAdded { get; set; } + public DateTime DateLastUpdated { get; set; } + public string Deck { get; set; } + public string Description { get; set; } + public Image Image { get; set; } + } +} \ No newline at end of file diff --git a/GiantBomb.Api/Model/Game.cs b/GiantBomb.Api/Model/Game.cs index ffee699..252b3c6 100644 --- a/GiantBomb.Api/Model/Game.cs +++ b/GiantBomb.Api/Model/Game.cs @@ -21,6 +21,7 @@ public class Game { public int? ExpectedReleaseMonth { get; set; } public int? ExpectedReleaseQuarter { get; set; } public int? ExpectedReleaseYear { get; set; } + public List Franchises { get; set; } public List Genres { get; set; } public Image Image { get; set; } public List Images { get; set; } diff --git a/GiantBomb.Api/Model/GiantBombBase.cs b/GiantBomb.Api/Model/GiantBombBase.cs index 0414c8c..0182adb 100644 --- a/GiantBomb.Api/Model/GiantBombBase.cs +++ b/GiantBomb.Api/Model/GiantBombBase.cs @@ -13,6 +13,11 @@ public abstract class GiantBombBase { public string Version { get; set; } public const int StatusOk = 1; + public const int StatusApiKeyInvalid = 100; + public const int StatusObjectNotFound = 101; + public const int StatusErrorUrlFormat = 102; + public const int StatusFilterError = 104; + public const int StatusRateLimitExceeded = 107; public const int DefaultLimit = 100; } diff --git a/GiantBomb.Api/Model/Platform.cs b/GiantBomb.Api/Model/Platform.cs index 8f3b4df..5abf0f3 100644 --- a/GiantBomb.Api/Model/Platform.cs +++ b/GiantBomb.Api/Model/Platform.cs @@ -6,6 +6,7 @@ namespace GiantBomb.Api.Model { public class Platform { public int Id { get; set; } + public string Aliases { get; set; } public string Name { get; set; } public string ApiDetailUrl { get; set; } public string SiteDetailUrl { get; set; } @@ -15,6 +16,9 @@ public class Platform { public string Deck { get; set; } public string Description { get; set; } public Image Image { get; set; } + public int? InstallBase { get; set; } + public bool OnlineSupport { get; set; } + public decimal? OriginalPrice { get; set; } public DateTime? ReleaseDate { get; set; } } } diff --git a/GiantBomb.Api/Model/Release.cs b/GiantBomb.Api/Model/Release.cs index 25bfea7..c3277aa 100644 --- a/GiantBomb.Api/Model/Release.cs +++ b/GiantBomb.Api/Model/Release.cs @@ -18,6 +18,7 @@ public class Release { public int? ExpectedReleaseMonth { get; set; } public int? ExpectedReleaseQuarter { get; set; } public int? ExpectedReleaseYear { get; set; } + public Game Game { get; set; } public DateTime? ReleaseDate { get; set; } public Rating Rating { get; set; } public Image Image { get; set; } diff --git a/GiantBomb.Api/Properties/AssemblyInfo.cs b/GiantBomb.Api/Properties/AssemblyInfo.cs index d86d5a1..c3ef4bf 100644 --- a/GiantBomb.Api/Properties/AssemblyInfo.cs +++ b/GiantBomb.Api/Properties/AssemblyInfo.cs @@ -6,12 +6,12 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("kayub")] [assembly: AssemblyProduct("GiantBomb.Api")] -[assembly: AssemblyCopyright("Copyright © kayub 2012")] +[assembly: AssemblyCopyright("Copyright © kayub 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("5d910805-e5ae-48f0-8e39-d37104d7a91e")] -[assembly: AssemblyVersion("2.0.3")] -[assembly: AssemblyFileVersion("2.0.3")] -[assembly: AssemblyInformationalVersion("2.0.3")] \ No newline at end of file +[assembly: AssemblyVersion("2.1.0")] +[assembly: AssemblyFileVersion("2.1.0")] +[assembly: AssemblyInformationalVersion("2.1.0")] \ No newline at end of file diff --git a/GiantBomb.Api/packages.config b/GiantBomb.Api/packages.config index 6b04fa8..46fa071 100644 --- a/GiantBomb.Api/packages.config +++ b/GiantBomb.Api/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/GiantBomb.Api/readme.txt b/GiantBomb.Api/readme.txt index 93f5b4a..4ed10b0 100644 --- a/GiantBomb.Api/readme.txt +++ b/GiantBomb.Api/readme.txt @@ -1,6 +1,20 @@ GiantBomb C# ------------ +## 2.1.0 + +- Add new fields: + - `Platform.Aliases` + - `Platform.InstallBase` + - `Platform.OnlineOnly` + - `Platform.OriginalPrice` + - `Game.Franchises` + - `Release.Game` +- Add exception handling and wrapping for GiantBomb API errors (`GiantBombApiException` class) + - For example, exceeding the 400 requests in 15 minutes rate limit +- Allow overriding `Execute` methods +- Update RestSharp to 105 (fixes #13) + ## 2.0.3 - Fixes issue with search paging (`offset` vs. `page` parameter) diff --git a/Readme.md b/Readme.md index 93f5b4a..4ed10b0 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,20 @@ GiantBomb C# ------------ +## 2.1.0 + +- Add new fields: + - `Platform.Aliases` + - `Platform.InstallBase` + - `Platform.OnlineOnly` + - `Platform.OriginalPrice` + - `Game.Franchises` + - `Release.Game` +- Add exception handling and wrapping for GiantBomb API errors (`GiantBombApiException` class) + - For example, exceeding the 400 requests in 15 minutes rate limit +- Allow overriding `Execute` methods +- Update RestSharp to 105 (fixes #13) + ## 2.0.3 - Fixes issue with search paging (`offset` vs. `page` parameter)