Skip to content

Commit

Permalink
Merge pull request #47 from MagicTheGathering/new-target
Browse files Browse the repository at this point in the history
Added netstandard2.0 as a target
  • Loading branch information
jregnier authored Nov 29, 2020
2 parents d0d6a23 + fb7a13d commit e438290
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
50 changes: 27 additions & 23 deletions src/MtgApiManager.Lib/Core/MtgApiServiceAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@ internal class MtgApiServiceAdapter : IMtgApiServiceAdapter
{
public static async Task<T> WebGetAsyncInternal<T>(Uri requestUri) where T : IMtgResponse
{
using var client = new HttpClient();
using var response = await client.GetAsync(requestUri).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
using (var client = new HttpClient())
{
MtgApiController.ParseHeaders(response.Headers);
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializer.DeserializeAsync<T>(stream).ConfigureAwait(false);
}
else
{
switch ((int)response.StatusCode)
using (var response = await client.GetAsync(requestUri).ConfigureAwait(false))
{
case (int)MtgApiError.BadRequest:
throw new MtgApiException<BadRequestException>(MtgApiError.BadRequest.GetDescription());
case (int)MtgApiError.Forbidden:
throw new MtgApiException<ForbiddenException>(MtgApiError.Forbidden.GetDescription());
case (int)MtgApiError.InternalServerError:
throw new MtgApiException<InternalServerErrorException>(MtgApiError.InternalServerError.GetDescription());
case (int)MtgApiError.NotFound:
throw new MtgApiException<NotFoundException>(MtgApiError.NotFound.GetDescription());
case (int)MtgApiError.ServiceUnavailable:
throw new MtgApiException<ServiceUnavailableException>(MtgApiError.ServiceUnavailable.GetDescription());
default:
response.EnsureSuccessStatusCode();
return default;
if (response.IsSuccessStatusCode)
{
MtgApiController.ParseHeaders(response.Headers);
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializer.DeserializeAsync<T>(stream).ConfigureAwait(false);
}
else
{
switch ((int)response.StatusCode)
{
case (int)MtgApiError.BadRequest:
throw new MtgApiException<BadRequestException>(MtgApiError.BadRequest.GetDescription());
case (int)MtgApiError.Forbidden:
throw new MtgApiException<ForbiddenException>(MtgApiError.Forbidden.GetDescription());
case (int)MtgApiError.InternalServerError:
throw new MtgApiException<InternalServerErrorException>(MtgApiError.InternalServerError.GetDescription());
case (int)MtgApiError.NotFound:
throw new MtgApiException<NotFoundException>(MtgApiError.NotFound.GetDescription());
case (int)MtgApiError.ServiceUnavailable:
throw new MtgApiException<ServiceUnavailableException>(MtgApiError.ServiceUnavailable.GetDescription());
default:
response.EnsureSuccessStatusCode();
return default;
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MtgApiManager.Lib/Model/Card/ICard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface ICard
/// <summary>
/// Gets a value indicating whether the card has more than a single color.
/// </summary>
bool IsMultiColor => Colors?.Length > 1;
bool IsMultiColor { get; }

/// <summary>
/// Gets the card layout. Possible values: normal, split, flip, double-faced, token, plane, scheme, phenomenon, leveler, vanguard
Expand Down
4 changes: 2 additions & 2 deletions src/MtgApiManager.Lib/Model/Card/IRuling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public interface IRuling
/// <summary>
/// Gets or sets the date of the ruling.
/// </summary>
public string Date { get; }
string Date { get; }

/// <summary>
/// Gets or sets the text of the ruling.
/// </summary>
public string Text { get; }
string Text { get; }
}
}
2 changes: 1 addition & 1 deletion src/MtgApiManager.Lib/MtgApiManager.Lib.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
<PackageId>MtgApiManager.Lib</PackageId>
<Authors>Jason Regnier</Authors>
<Company>Jason Regnier</Company>
Expand Down
4 changes: 3 additions & 1 deletion src/MtgApiManager.Lib/MtgApiManager.Lib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/MtgApiManager.Lib/Service/ServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace MtgApiManager.Lib.Service
public class MtgServiceProvider : IMtgServiceProvider
{
private readonly ApiVersion _apiVersion;
private readonly IMtgApiServiceAdapter _serviceAdapter;
private readonly IModelMapper _modelMapper;
private readonly bool _rateLimitOn;
private readonly IMtgApiServiceAdapter _serviceAdapter;
private ICardService _cardService;
private ISetService _setService;

Expand All @@ -35,14 +35,13 @@ internal MtgServiceProvider(
/// <inheritdoc />
public ICardService GetCardService()
{
return _cardService ??= new CardService(_serviceAdapter, _modelMapper, _apiVersion, _rateLimitOn);
return _cardService ?? (_cardService = new CardService(_serviceAdapter, _modelMapper, _apiVersion, _rateLimitOn));
}

/// <inheritdoc />
public ISetService GetSetService()
{
return _setService ??= new SetService(_serviceAdapter, _modelMapper, _apiVersion, _rateLimitOn);
return _setService ?? (_setService = new SetService(_serviceAdapter, _modelMapper, _apiVersion, _rateLimitOn));
}
}

}

0 comments on commit e438290

Please sign in to comment.