Skip to content

Commit

Permalink
restsharp: Update to v107
Browse files Browse the repository at this point in the history
This is a breaking change because IRestResponse/IRestRequest was removed affecting IGiantBombRestClient.Execute(Async)
  • Loading branch information
chyyran committed Jan 24, 2022
1 parent d6d1fd4 commit 3adf04e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
25 changes: 13 additions & 12 deletions GiantBomb.Api/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using GiantBomb.Api.Model;
using GiantBomb.Api.Serialization;
using RestSharp;
using RestSharp.Serializers.SystemTextJson;
using RestSharp.Serializers.Json;

namespace GiantBomb.Api
{
Expand Down Expand Up @@ -40,25 +40,26 @@ public GiantBombRestClient(string apiToken, Uri baseUrl)

var version = typeof(GiantBombRestClient).GetTypeInfo().Assembly.GetName().Version;

_client = new RestClient
var clientOptions = new RestClientOptions(baseUrl)
{
UserAgent = "giantbomb-csharp/" + version,
BaseUrl = baseUrl
UserAgent = "giantbomb-csharp/" + version
};

_client = new RestClient(clientOptions);

// API token is used on every request
_client.AddDefaultParameter("api_key", ApiKey);
_client.AddDefaultParameter("format", "json");
var options = new System.Text.Json.JsonSerializerOptions()
var jsonOptions = new System.Text.Json.JsonSerializerOptions()
{
PropertyNamingPolicy = SnakeCaseNamingPolicy.SnakeCase,
DictionaryKeyPolicy = SnakeCaseNamingPolicy.SnakeCase,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
};

options.Converters.Add(new DateTimeConverter());
options.Converters.Add(new BoolConverter());
_client.UseSystemTextJson(options);
jsonOptions.Converters.Add(new DateTimeConverter());
jsonOptions.Converters.Add(new BoolConverter());
_client.UseSerializer(() => new SystemTextJsonSerializer(jsonOptions));
}

public GiantBombRestClient(string apiToken)
Expand All @@ -84,7 +85,7 @@ public virtual T Execute<T>(RestRequest request) where T : new()
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
public virtual async Task<T> ExecuteAsync<T>(RestRequest request) where T : new()
{
IRestResponse response = null;
RestResponse response = null;

try
{
Expand All @@ -97,7 +98,7 @@ public virtual async Task<T> ExecuteAsync<T>(RestRequest request) where T : new(
}

// Deserialize original requested type
IRestResponse<T> deserializedResponse = null;
RestResponse<T> deserializedResponse = null;
Exception deserializeEx = null;
try
{
Expand Down Expand Up @@ -154,7 +155,7 @@ public virtual async Task<T> ExecuteAsync<T>(RestRequest request) where T : new(
/// Execute a manual REST request
/// </summary>
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
public virtual IRestResponse Execute(RestRequest request)
public virtual RestResponse Execute(RestRequest request)
{
return ExecuteAsync(request).Result;
}
Expand All @@ -163,7 +164,7 @@ public virtual IRestResponse Execute(RestRequest request)
/// Execute a manual REST request (async)
/// </summary>
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
public virtual async Task<IRestResponse> ExecuteAsync(RestRequest request)
public virtual async Task<RestResponse> ExecuteAsync(RestRequest request)
{
return await _client.ExecuteAsync(request).ConfigureAwait(false);
}
Expand Down
5 changes: 2 additions & 3 deletions GiantBomb.Api/GiantBomb.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>GiantBomb.Api</AssemblyName>
<RootNamespace>GiantBomb.Api</RootNamespace>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.6.0</Version>
<Version>3.0.0</Version>
<Authors>kayub</Authors>
<Company>kayub</Company>
<Product>GiantBomb API (C#)</Product>
Expand All @@ -25,8 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RestSharp" Version="106.12.0" />
<PackageReference Include="RestSharp.Serializers.SystemTextJson" Version="106.12.0" />
<PackageReference Include="RestSharp" Version="107.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions GiantBomb.Api/IGiantBombRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ public interface IGiantBombRestClient
/// Execute a manual REST request
/// </summary>
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
IRestResponse Execute(RestRequest request);
RestResponse Execute(RestRequest request);

/// <summary>
/// Execute a manual REST request
/// </summary>
/// <param name="request">The RestRequest to execute (will use client credentials)</param>
Task<IRestResponse> ExecuteAsync(RestRequest request);
Task<RestResponse> ExecuteAsync(RestRequest request);
}
}

0 comments on commit 3adf04e

Please sign in to comment.