-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #779 from tmenier/dev
Flurl.Http.Newtonsoft
- Loading branch information
Showing
15 changed files
with
457 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ jobs: | |
run: dotnet build -c Release --no-restore | ||
|
||
- name: Test | ||
run: dotnet test --no-build -c Release /p:CollectCoverage=true /p:Threshold=80 /p:Include=\"[Flurl]*,[Flurl.Http]*\" /p:Exclude="[*]*.GeneratedExtensions" | ||
run: dotnet test --no-build -c Release /p:CollectCoverage=true /p:Threshold=80 /p:Include=\"[Flurl]*,[Flurl.Http]*,[Flurl.Http.Newtonsoft]*\" /p:Exclude="[*]*.GeneratedExtensions" | ||
|
||
# Compare version from csproj with latest release tag. | ||
# If different, create a draft release. | ||
|
@@ -57,12 +57,28 @@ jobs: | |
releases-only: true | ||
regex: '^Flurl\.Http\.\d+' | ||
|
||
- name: Get Flurl.Http.Newtonsoft csproj version | ||
id: csproj_ver_flurl_newtonsoft | ||
uses: KageKirin/[email protected] | ||
with: | ||
file: src/Flurl.Http.Newtonsoft/Flurl.Http.Newtonsoft.csproj | ||
|
||
- name: Get Flurl.Http.Newtonsoft latest release tag | ||
id: release_ver_flurl_newtonsoft | ||
uses: oprypin/[email protected] | ||
with: | ||
repository: tmenier/Flurl | ||
releases-only: true | ||
regex: '^Flurl\.Http\.Newtonsoft\.\d+' | ||
|
||
- name: Output versions | ||
run: | | ||
echo "Flurl csproj version: ${{ steps.csproj_ver_flurl.outputs.version }}" | ||
echo "Flurl latest release tag: ${{ steps.release_ver_flurl.outputs.tag }}" | ||
echo "Flurl.Http csproj version: ${{ steps.csproj_ver_flurl_http.outputs.version }}" | ||
echo "Flurl.Http latest release tag: ${{ steps.release_ver_flurl_http.outputs.tag }}" | ||
echo "Flurl.Http.Newtonsoft csproj version: ${{ steps.csproj_ver_flurl_newtonsoft.outputs.version }}" | ||
echo "Flurl.Http.Newtonsoft latest release tag: ${{ steps.release_ver_flurl_newtonsoft.outputs.tag }}" | ||
- name: Draft Flurl release | ||
env: | ||
|
@@ -91,3 +107,17 @@ jobs: | |
generateReleaseNotes: true | ||
artifacts: "**/${{ env.NEXT_TAG }}.nupkg,**/${{ env.NEXT_TAG }}.snupkg" | ||
draft: true | ||
|
||
- name: Draft Flurl.Http.Newtonsoft release | ||
env: | ||
CURRENT_TAG: ${{ steps.release_ver_flurl_newtonsoft.outputs.tag }} | ||
NEXT_TAG: "Flurl.Http.${{ steps.csproj_ver_flurl_newtonsoft.outputs.version }}" | ||
RELEASE_NAME: "Flurl.Http ${{ steps.csproj_ver_flurl_newtonsoft.outputs.version }}" | ||
if: env.NEXT_TAG != env.CURRENT_TAG | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
name: ${{ env.RELEASE_NAME }} | ||
tag: ${{ env.NEXT_TAG }} | ||
generateReleaseNotes: true | ||
artifacts: "**/${{ env.NEXT_TAG }}.nupkg,**/${{ env.NEXT_TAG }}.snupkg" | ||
draft: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
using System.Threading.Tasks; | ||
using Flurl.Http.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Flurl.Http.Newtonsoft | ||
{ | ||
/// <summary> | ||
/// Extensions to Flurl objects that use Newtonsoft.Json. | ||
/// </summary> | ||
public static class ExtensionMethods | ||
{ | ||
/// <summary> | ||
/// Deserializes JSON-formatted HTTP response body to a dynamic object. | ||
/// </summary> | ||
/// <returns>A Task whose result is a dynamic object containing data in the response body.</returns> | ||
public static async Task<dynamic> GetJsonAsync(this IFlurlResponse resp) { | ||
dynamic d = await resp.GetJsonAsync<ExpandoObject>().ConfigureAwait(false); | ||
return d; | ||
} | ||
|
||
/// <summary> | ||
/// Deserializes JSON-formatted HTTP response body to a list of dynamic objects. | ||
/// </summary> | ||
/// <returns>A Task whose result is a list of dynamic objects containing data in the response body.</returns> | ||
public static async Task<IList<dynamic>> GetJsonListAsync(this IFlurlResponse resp) { | ||
dynamic[] d = await resp.GetJsonAsync<ExpandoObject[]>().ConfigureAwait(false); | ||
return d; | ||
} | ||
|
||
/// <summary> | ||
/// Deserializes JSON-formatted HTTP response body to a dynamic object. Intended to chain off an async call. | ||
/// </summary> | ||
/// <returns>A Task whose result is a dynamic object containing data in the response body.</returns> | ||
public static async Task<dynamic> ReceiveJson(this Task<IFlurlResponse> response) { | ||
using var resp = await response.ConfigureAwait(false); | ||
if (resp == null) return null; | ||
return await resp.GetJsonAsync().ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Deserializes JSON-formatted HTTP response body to a list of dynamic objects. Intended to chain off an async call. | ||
/// </summary> | ||
/// <returns>A Task whose result is a list of dynamic objects containing data in the response body.</returns> | ||
public static async Task<IList<dynamic>> ReceiveJsonList(this Task<IFlurlResponse> response) { | ||
using var resp = await response.ConfigureAwait(false); | ||
if (resp == null) return null; | ||
return await resp.GetJsonListAsync().ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Shortcut to use NewtonsoftJsonSerializer with this IFlurlClientBuilder. | ||
/// </summary> | ||
/// <param name="builder">This IFlurlClientBuilder.</param> | ||
/// <param name="settings">Optional custom JsonSerializerSettings.</param> | ||
/// <returns></returns> | ||
public static IFlurlClientBuilder UseNewtonsoft(this IFlurlClientBuilder builder, JsonSerializerSettings settings = null) => | ||
builder.WithSettings(fs => fs.JsonSerializer = new NewtonsoftJsonSerializer(settings)); | ||
|
||
/// <summary> | ||
/// Shortcut to use NewtonsoftJsonSerializer with all FlurlClients registered in this cache. | ||
/// </summary> | ||
/// <param name="cache">This IFlurlClientCache.</param> | ||
/// <param name="settings">Optional custom JsonSerializerSettings.</param> | ||
/// <returns></returns> | ||
public static IFlurlClientCache UseNewtonsoft(this IFlurlClientCache cache, JsonSerializerSettings settings = null) => | ||
cache.WithDefaults(builder => builder.UseNewtonsoft(settings)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;netstandard2.0;net461</TargetFrameworks> | ||
<LangVersion>9.0</LangVersion> | ||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
<PackageId>Flurl.Http.Newtonsoft</PackageId> | ||
<Version>0.9.0-pre1</Version> | ||
<Authors>Todd Menier</Authors> | ||
<Description>A Newtonsoft-based JSON serializer for Flurl.Http 4.0 and above.</Description> | ||
<PackageProjectUrl>https://flurl.dev</PackageProjectUrl> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<RepositoryUrl>https://github.com/tmenier/Flurl.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageTags>flurl http json</PackageTags> | ||
<PackageReleaseNotes>https://github.com/tmenier/Flurl/releases</PackageReleaseNotes> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\icon.png" Pack="true" PackagePath="\" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<ProjectReference Include="..\Flurl.Http\Flurl.Http.csproj" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)'=='net461'"> | ||
<Reference Include="System.Net.Http" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.