Skip to content

Commit

Permalink
Merge pull request #30 from ashakoor/main
Browse files Browse the repository at this point in the history
v0.7.2
  • Loading branch information
Cytraen authored Mar 15, 2021
2 parents 6dd33ee + c2a556f commit fda3201
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 865 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<Authors>ashakoor</Authors>
<Copyright>Copyright © 2020-2021 ashakoor</Copyright>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/ashakoor/BungieSharper</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>

<TargetFramework>net5.0</TargetFramework>
<Version>0.7.2-beta.1</Version>
<Version>0.7.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>ashakoor</Authors>
<Copyright>Copyright © 2020-2021 ashakoor</Copyright>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/ashakoor/BungieSharper</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>

<TargetFramework>net5.0</TargetFramework>
<Version>0.7.2-beta.1</Version>
<Version>0.7.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions BungieSharper.CodeGen/BungieSharper.CodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>ashakoor</Authors>
<Copyright>Copyright © 2020-2021 ashakoor</Copyright>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/ashakoor/BungieSharper</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>

<TargetFramework>net5.0</TargetFramework>
<Version>0.7.2-beta.1</Version>
<Version>0.7.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 12 additions & 13 deletions BungieSharper.CodeGen/JsonLongConverter.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
using System;
using System.Buffers;
using System.Buffers.Text;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace BungieSharper.CodeGen.Entities
namespace BungieSharper.CodeGen
{
public class JsonLongConverter : JsonConverter<long>
{
public override long Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
if (reader.TokenType != JsonTokenType.String)
{
ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
if (Utf8Parser.TryParse(span, out long number, out var bytesConsumed) && span.Length == bytesConsumed)
{
return number;
}
return reader.GetInt64();
}

var span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;

if (long.TryParse(reader.GetString(), out number))
{
return number;
}
if (Utf8Parser.TryParse(span, out long number, out var bytesConsumed) && span.Length == bytesConsumed)
{
return number;
}

return reader.GetInt64();
return long.TryParse(reader.GetString(), out number)
? number
: reader.GetInt64();
}

public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
Expand Down
5 changes: 0 additions & 5 deletions BungieSharper.CodeGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ private static void Main(string[] args)
combinedContent = combinedContent.Replace("System.DateTime", "DateTime");
}

if (!string.IsNullOrWhiteSpace(topFolder))
{
Directory.CreateDirectory(bungieSharperPath.TrimEnd('\\') + ".Schema\\" + topFolder);
}

WriteFileWithContent(
bungieSharperPath.TrimEnd('\\') + ".Entities\\" + topFolder,
("Entities." + location.Replace(bungieSharperPath, "").Replace('\\', '.') + ".cs").Replace("..", "."),
Expand Down
10 changes: 6 additions & 4 deletions BungieSharper.Entities/BungieSharper.Entities.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>ashakoor</Authors>
<Copyright>Copyright © 2020-2021 ashakoor</Copyright>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/ashakoor/BungieSharper</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>

<TargetFrameworks>net5.0</TargetFrameworks>
<Version>0.7.2-beta.1</Version>
<TargetFrameworks>net5.0;netcoreapp3.1;netstandard2.1</TargetFrameworks>
<Version>0.7.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down Expand Up @@ -42,6 +41,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />

<PackageReference Include="System.Text.Json" Version="5.0.1" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Include="System.Text.Json" Version="5.0.1" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions BungieSharper.Entities/_ApiResponses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ public class ApiResponse

public class ApiResponse<T> : ApiResponse
{
#if (NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_1)
public T Response { get; set; }
#else
public T? Response { get; set; }
#endif
}

public class TokenResponse
{
/// <summary>
/// The access token, to be sent with authenticated requests
/// </summary>
[JsonPropertyName("access_token")]
public string? AccessToken { get; set; }

Expand All @@ -41,6 +48,9 @@ public class TokenResponse
[JsonPropertyName("expires_in")]
public long? ExpiresIn { get; set; }

/// <summary>
/// The refresh token, to be used to refresh the <see cref="AccessToken"/> (for "confidential" clients only)
/// </summary>
[JsonPropertyName("refresh_token")]
public string? RefreshToken { get; set; }

Expand All @@ -56,9 +66,15 @@ public class TokenResponse
[JsonPropertyName("membership_id")]
public long? MembershipId { get; set; }

/// <summary>
/// The error, if there is one
/// </summary>
[JsonPropertyName("error")]
public string? Error { get; set; }

/// <summary>
/// A (hopefully) more detailed description of the error, if there is one
/// </summary>
[JsonPropertyName("error_description")]
public string? ErrorDescription { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions BungieSharper.Tests/BungieSharper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<Authors>ashakoor</Authors>
<Copyright>Copyright © 2020-2021 ashakoor</Copyright>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/ashakoor/BungieSharper</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>

<TargetFramework>net5.0</TargetFramework>
<Version>0.7.2-beta.1</Version>
<Version>0.7.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions BungieSharper.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bungie/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
7 changes: 3 additions & 4 deletions BungieSharper/BungieSharper.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>ashakoor</Authors>
<Copyright>Copyright © 2020-2021 ashakoor</Copyright>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/ashakoor/BungieSharper</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Nullable>enable</Nullable>

<TargetFrameworks>net5.0</TargetFrameworks>
<Version>0.7.2-beta.1</Version>
<TargetFrameworks>net5.0;netcoreapp3.1;netstandard2.1</TargetFrameworks>
<Version>0.7.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
30 changes: 26 additions & 4 deletions BungieSharper/Client/ApiAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ internal async Task<T> ApiRequestAsync<T>(Uri uri, HttpContent? httpContent, Htt
throw ContentNotJsonException.NewContentNotJsonException(httpResponseMessage);
}

#if (NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_1)
var apiResponse = JsonSerializer.Deserialize<Entities.ApiResponse<T>>(
await httpResponseMessage.Content.ReadAsStringAsync(cancelToken).ConfigureAwait(false), _serializerOptions
);
await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false),
_serializerOptions);
#else
var apiResponse = JsonSerializer.Deserialize<Entities.ApiResponse<T>>(
await httpResponseMessage.Content.ReadAsStringAsync(cancelToken).ConfigureAwait(false),
_serializerOptions);
#endif

if (apiResponse is null)
{
Expand Down Expand Up @@ -166,9 +172,15 @@ await httpResponseMessage.Content.ReadAsStringAsync(cancelToken).ConfigureAwait(
throw ContentNotJsonException.NewContentNotJsonException(httpResponseMessage);
}

#if (NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_1)
var apiResponse = JsonSerializer.Deserialize<Entities.TokenResponse>(
await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false),
_serializerOptions);
#else
var apiResponse = JsonSerializer.Deserialize<Entities.TokenResponse>(
await httpResponseMessage.Content.ReadAsStringAsync(cancelToken).ConfigureAwait(false), _serializerOptions
);
await httpResponseMessage.Content.ReadAsStringAsync(cancelToken).ConfigureAwait(false),
_serializerOptions);
#endif

if (apiResponse is null)
{
Expand All @@ -185,14 +197,24 @@ internal async Task<Stream> GetStream(Uri uri, CancellationToken cancelToken)
{
var requestMsg = HttpRequestGenerator.MakeApiRequestMessage(uri, null, HttpMethod.Get);
var response = await GetApiResponseAsync(requestMsg, cancelToken);

#if (NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_1)
return await response.Content.ReadAsStreamAsync();
#else
return await response.Content.ReadAsStreamAsync(cancelToken);
#endif
}

internal async Task<string> GetString(Uri uri, CancellationToken cancelToken)
{
var requestMsg = HttpRequestGenerator.MakeApiRequestMessage(uri, null, HttpMethod.Get);
var response = await GetApiResponseAsync(requestMsg, cancelToken);

#if (NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_1)
return await response.Content.ReadAsStringAsync();
#else
return await response.Content.ReadAsStringAsync(cancelToken);
#endif
}

private Task<HttpResponseMessage> GetApiResponseAsync(HttpRequestMessage request, CancellationToken cancelToken)
Expand Down
16 changes: 13 additions & 3 deletions BungieSharper/Endpoints/_OAuthRequests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BungieSharper.Client;
using BungieSharper.Client;
using System;
using System.Collections.Generic;
using System.Net.Http;
Expand Down Expand Up @@ -77,7 +77,12 @@ internal OAuthRequests(ApiAccessor apiAccessor)
/// <returns>The OAuth authorization URL.</returns>
public string GetOAuthAuthorizationUrl()
{
return OAuthAuthorizationUrl + _oAuthClientId;
if (!_oAuthClientId.HasValue)
{
throw new NullReferenceException(nameof(_oAuthClientId));
}

return OAuthAuthorizationUrl + _oAuthClientId.Value;
}

/// <summary>
Expand All @@ -87,7 +92,12 @@ public string GetOAuthAuthorizationUrl()
/// <returns>The OAuth authorization URL.</returns>
public string GetOAuthAuthorizationUrl(string state)
{
return OAuthAuthorizationUrl + _oAuthClientId + "&state=" + state;
if (string.IsNullOrWhiteSpace(state))
{
return GetOAuthAuthorizationUrl();
}

return GetOAuthAuthorizationUrl() + "&state=" + state;
}

internal void SetOAuthClientId(uint clientId)
Expand Down
Loading

0 comments on commit fda3201

Please sign in to comment.