Skip to content

Commit

Permalink
[Closes #15, Closes #14, Closes #13]
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranayub committed Jan 26, 2015
1 parent 4364d22 commit a4e6de2
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 22 deletions.
8 changes: 4 additions & 4 deletions GiantBomb.Api.Tests/GiantBomb.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=104.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="RestSharp, Version=105.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
<HintPath>..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
4 changes: 2 additions & 2 deletions GiantBomb.Api.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="RestSharp" version="104.1" targetFramework="net40" />
<package id="NUnit" version="2.6.4" targetFramework="net40" />
<package id="RestSharp" version="105.0.1" targetFramework="net40" />
</packages>
22 changes: 14 additions & 8 deletions GiantBomb.Api/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public partial class GiantBombRestClient : IGiantBombRestClient {

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
Expand All @@ -58,7 +58,7 @@ public GiantBombRestClient(string apiToken)
/// </summary>
/// <typeparam name="T">The type of object to create and populate with the returned data.</typeparam>
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
public T Execute<T>(RestRequest request) where T : new() {
public virtual T Execute<T>(RestRequest request) where T : new() {
var response = _client.Execute<T>(request);
return response.Data;
}
Expand All @@ -67,7 +67,7 @@ public GiantBombRestClient(string apiToken)
/// Execute a manual REST request
/// </summary>
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
public IRestResponse Execute(RestRequest request) {
public virtual IRestResponse Execute(RestRequest request) {
return _client.Execute(request);
}
#endif
Expand All @@ -77,13 +77,13 @@ public GiantBombRestClient(string apiToken)
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);
}
Expand Down Expand Up @@ -131,12 +131,15 @@ private string BuildKeyValueListForUrl(IEnumerable<KeyValuePair<string, SortDire
if (results != null && results.StatusCode == GiantBombBase.StatusOk)
return results.Results;

if (results != null && results.StatusCode != GiantBombBase.StatusOk)
throw new GiantBombApiException(results.StatusCode, results.Error);

return null;
}

public virtual RestRequest GetSingleResource(string resource, int resourceId, int id, string[] fieldList = null) {
var request = new RestRequest {
Resource = resource + "/{ResourceId}-{Id}//",
Resource = resource + "/{ResourceId}-{Id}/",
DateFormat = "yyyy-MM-dd HH:mm:ss"
};

Expand All @@ -156,6 +159,9 @@ private string BuildKeyValueListForUrl(IEnumerable<KeyValuePair<string, SortDire
if (result != null && result.StatusCode == GiantBombBase.StatusOk)
return result.Results;

if (result != null && result.StatusCode != GiantBombBase.StatusOk)
throw new GiantBombApiException(result.StatusCode, result.Error);

return null;
}
}
Expand Down
6 changes: 4 additions & 2 deletions GiantBomb.Api/GiantBomb.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
<Reference Include="fastJSON">
<HintPath>..\Dependencies\fastJSON.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=104.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="RestSharp, Version=105.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
<HintPath>..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -51,6 +51,8 @@
<ItemGroup>
<Compile Include="Core.cs" />
<Compile Include="FastJsonDeserializer.cs" />
<Compile Include="GiantBombApiException.cs" />
<Compile Include="Model\Franchise.cs" />
<Compile Include="ResourceTypes.cs" />
<Compile Include="Resources\Games.cs" />
<Compile Include="IGiantBombRestClient.cs" />
Expand Down
2 changes: 1 addition & 1 deletion GiantBomb.Api/GiantBomb.Api.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<projectUrl>http://github.com/kamranayub/GiantBomb-CSharp</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>RestSharp-based API wrapper for the GiantBomb games database public API</description>
<copyright>Copyright © kayub 2012</copyright>
<copyright>Copyright © kayub 2015</copyright>
<releaseNotes>
Updated with fixes, see README.
</releaseNotes>
Expand Down
15 changes: 15 additions & 0 deletions GiantBomb.Api/GiantBombApiException.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
21 changes: 21 additions & 0 deletions GiantBomb.Api/Model/Franchise.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace GiantBomb.Api.Model
{
public class Franchise
{
/// <summary>
/// Newline-delimited list of aliases
/// </summary>
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; }
}
}
1 change: 1 addition & 0 deletions GiantBomb.Api/Model/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Game {
public int? ExpectedReleaseMonth { get; set; }
public int? ExpectedReleaseQuarter { get; set; }
public int? ExpectedReleaseYear { get; set; }
public List<Franchise> Franchises { get; set; }
public List<Genre> Genres { get; set; }
public Image Image { get; set; }
public List<Image> Images { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions GiantBomb.Api/Model/GiantBombBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions GiantBomb.Api/Model/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
}
}
1 change: 1 addition & 0 deletions GiantBomb.Api/Model/Release.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 4 additions & 4 deletions GiantBomb.Api/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("2.1.0")]
[assembly: AssemblyFileVersion("2.1.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
2 changes: 1 addition & 1 deletion GiantBomb.Api/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="RestSharp" version="104.1" targetFramework="net40" />
<package id="RestSharp" version="105.0.1" targetFramework="net40" />
</packages>
14 changes: 14 additions & 0 deletions GiantBomb.Api/readme.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
14 changes: 14 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit a4e6de2

Please sign in to comment.