Skip to content

Commit a3b0e99

Browse files
committed
Merge branch 'release/1.1.0'
2 parents e38c731 + 1e6cb03 commit a3b0e99

14 files changed

Lines changed: 77 additions & 56 deletions

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# <img src="https://github.com/ChangemakerStudios/GotenbergSharpApiClient/raw/master/lib/Resources/gotenbergSharpClient.PNG" width="24" height="24" /> Gotenberg.Sharp.Api.Client
22

3-
[![NuGet version](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client.svg)](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client) [![Build status](https://ci.appveyor.com/api/projects/status/s8lvj93xewlsylxh/branch/master?svg=true)](https://ci.appveyor.com/project/Jaben/gotenbergsharpapiclient/branch/master)
3+
[![NuGet version](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client.svg)](https://badge.fury.io/nu/Gotenberg.Sharp.Api.Client) [![Build status](https://ci.appveyor.com/api/projects/status/s8lvj93xewlsylxh/branch/master?svg=true)](https://ci.appveyor.com/project/Jaben/gotenbergsharpapiclient/branch/master) [![Downloads](https://img.shields.io/nuget/dt/Gotenberg.Sharp.API.Client.svg?logo=nuget&color=purple)](https://www.nuget.org/packages/Gotenberg.Sharp.API.Client)
44

55
.NET C# Client for interacting with the [Gotenberg](https://thecodingmachine.github.io/gotenberg) micro-service's API. [Gotenberg](https://github.com/thecodingmachine/gotenberg) is a [Docker-powered stateless API](https://hub.docker.com/r/thecodingmachine/gotenberg) for converting & merging HTML, Markdown and Office documents to PDF. The client supports a configurable [Polly](http://www.thepollyproject.org/) **retry policy** with exponential backoff for handling transient exceptions.
66

@@ -38,14 +38,14 @@ public void ConfigureServices(IServiceCollection services)
3838
{
3939
.....
4040
services.AddOptions<GotenbergSharpClientOptions>()
41-
.Bind(Configuration.GetSection("GotenbergSharpClient"));
41+
.Bind(Configuration.GetSection(nameof(GotenbergSharpClient)));
4242
services.AddGotenbergSharpClient();
4343
.....
4444
}
4545

4646
```
4747
# Using GotenbergSharpClient
48-
*See the [linqPad folder](linqpad/)* for complete examples
48+
*See the [linqPad folder](linqpad/)* for complete examples.
4949

5050
## Html To Pdf
5151
*With embedded assets:*
@@ -85,23 +85,23 @@ public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
8585
{
8686
var builder = new UrlRequestBuilder()
8787
.SetUrl("https://www.cnn.com")
88-
.ConfigureRequest(b =>
88+
.ConfigureRequest(config =>
8989
{
90-
b.PageRanges("1-2").ChromeRpccBufferSize(1048576);
90+
config.PageRanges("1-2").ChromeRpccBufferSize(1048576);
9191
})
9292
.AddAsyncHeaderFooter(async
93-
b => b.SetHeader(await File.ReadAllTextAsync(headerPath))
93+
doc => doc.SetHeader(await File.ReadAllTextAsync(headerPath))
9494
.SetFooter(await File.ReadAllBytesAsync(footerPath)
95-
)).WithDimensions(b =>
95+
)).WithDimensions(dims =>
9696
{
97-
b.SetPaperSize(PaperSizes.A4)
97+
dims.SetPaperSize(PaperSizes.A4)
9898
.SetMargins(Margins.None)
9999
.SetScale(.90)
100100
.LandScape();
101101
});
102102

103103
var request = await builder.BuildAsync();
104-
return await sharpClient.UrlToPdfAsync(request);
104+
return await _sharpClient.UrlToPdfAsync(request);
105105
}
106106
```
107107
## Merge Office Docs
@@ -111,14 +111,14 @@ public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
111111
public async Task<Stream> DoOfficeMerge(string sourceDirectory)
112112
{
113113
var builder = new MergeOfficeBuilder()
114-
.WithAsyncAssets(async b => b.AddItems(await GetDocsAsync(sourceDirectory)))
115-
.ConfigureRequest(b =>
114+
.WithAsyncAssets(async a => a.AddItems(await GetDocsAsync(sourceDirectory)))
115+
.ConfigureRequest(config =>
116116
{
117-
b.TimeOut(100);
117+
config.TimeOut(100);
118118
});
119119

120120
var request = await builder.BuildAsync();
121-
return await sharpClient.MergeOfficeDocsAsync(request);
121+
return await _sharpClient.MergeOfficeDocsAsync(request);
122122
}
123123
```
124124
## Markdown to Pdf
@@ -129,22 +129,22 @@ public async Task<Stream> CreateFromMarkdown()
129129
{
130130
var builder = new HtmlRequestBuilder()
131131
.AddAsyncDocument(async
132-
b => b.SetHeader(await this.GetHeaderAsync())
132+
doc => doc.SetHeader(await this.GetHeaderAsync())
133133
.SetBody(await GetBodyAsync())
134134
.ContainsMarkdown()
135135
.SetFooter(await GetFooterAsync())
136-
).WithDimensions(b =>
136+
).WithDimensions(dims =>
137137
{
138-
b.UseChromeDefaults().LandScape().SetScale(.90);
138+
dims.UseChromeDefaults().LandScape().SetScale(.90);
139139
}).WithAsyncAssets(async
140-
b => b.AddItems(await GetMarkdownAssets())
141-
).ConfigureRequest(b =>
140+
a => a.AddItems(await GetMarkdownAssets())
141+
).ConfigureRequest(req =>
142142
{
143-
b.ChromeRpccBufferSize(1048555);
143+
req.ChromeRpccBufferSize(1048555);
144144
});
145145

146146
var request = await builder.BuildAsync();
147-
return await sharpClient.HtmlToPdfAsync(request);
147+
return await _sharpClient.HtmlToPdfAsync(request);
148148
}
149149
```
150150
## Webhook
@@ -179,7 +179,7 @@ public async Task<Stream> CreateFromMarkdown()
179179

180180
var request = await builder.BuildAsync();
181181

182-
await new sharpClient.FireWebhookAndForgetAsync(request);
182+
await _sharpClient.FireWebhookAndForgetAsync(request);
183183
}
184184

185185
```
@@ -236,7 +236,7 @@ IEnumerable<UrlRequestBuilder> CreateBuilders(IEnumerable<Uri> uris)
236236

237237
async Task<Stream> ExecuteRequestsAndMerge(IEnumerable<UrlRequest> requests)
238238
{
239-
var tasks = requests.Select(r => sharpClient.UrlToPdfAsync(r));
239+
var tasks = requests.Select(r => _sharpClient.UrlToPdfAsync(r));
240240
var results = await Task.WhenAll(tasks);
241241

242242
var mergeBuilder = new MergeBuilder()
@@ -245,6 +245,6 @@ async Task<Stream> ExecuteRequestsAndMerge(IEnumerable<UrlRequest> requests)
245245
).ConfigureRequest(b => b.TimeOut(1799));
246246

247247
var request = mergeBuilder.Build();
248-
return await sharpClient.MergePdfsAsync(request);
248+
return await _sharpClient.MergePdfsAsync(request);
249249
}
250250
```

lib/Domain/Builders/Faceted/AssetBuilder.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ public AssetBuilder AddItem(string name, ContentItem value)
3737
}
3838

3939
[PublicAPI]
40-
public AssetBuilder AddItem(string name, string value) => AddItem(name, new ContentItem(value));
40+
public AssetBuilder AddItem(string name, string value) =>
41+
AddItem(name, new ContentItem(value));
4142

4243
[PublicAPI]
43-
public AssetBuilder AddItem(string name, byte[] value) => AddItem(name, new ContentItem(value));
44+
public AssetBuilder AddItem(string name, byte[] value) =>
45+
AddItem(name, new ContentItem(value));
4446

4547
[PublicAPI]
46-
public AssetBuilder AddItem(string name, Stream value) => AddItem(name, new ContentItem(value));
48+
public AssetBuilder AddItem(string name, Stream value) =>
49+
AddItem(name, new ContentItem(value));
4750

4851
#endregion
4952

@@ -94,15 +97,13 @@ public AssetBuilder AddItems(IEnumerable<KeyValuePair<string, string>> assets) =
9497

9598
[PublicAPI]
9699
public AssetBuilder AddItems(IEnumerable<KeyValuePair<string, byte[]>> assets) =>
97-
AddItems(new Dictionary<string, ContentItem>(
98-
assets?.ToDictionary(a => a.Key, a => new ContentItem(a.Value)) ??
99-
throw new ArgumentNullException(nameof(assets))));
100+
AddItems(assets?.ToDictionary(a => a.Key, a => new ContentItem(a.Value)) ??
101+
throw new ArgumentNullException(nameof(assets)));
100102

101103
[PublicAPI]
102104
public AssetBuilder AddItems(IEnumerable<KeyValuePair<string, Stream>> assets) =>
103-
AddItems(new Dictionary<string, ContentItem>(
104-
assets?.ToDictionary(s => s.Key, a => new ContentItem(a.Value)) ??
105-
throw new ArgumentNullException(nameof(assets))));
105+
AddItems(assets?.ToDictionary(s => s.Key, a => new ContentItem(a.Value)) ??
106+
throw new ArgumentNullException(nameof(assets)));
106107

107108
#endregion
108109

lib/Domain/Requests/Facets/Dimensions.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Net.Http;
56
using System.Net.Http.Headers;
@@ -164,14 +165,30 @@ public IEnumerable<HttpContent> ToHttpContent()
164165

165166
if (value == null) return null;
166167

167-
var contentItem = new StringContent(value.ToString());
168-
contentItem.Headers.ContentDisposition =
169-
new ContentDispositionHeaderValue(item.Attrib.ContentDisposition) { Name = item.Attrib.Name };
168+
var contentItem = new StringContent(GetValueAsUsString(value));
169+
170+
contentItem.Headers.ContentDisposition = new ContentDispositionHeaderValue(item.Attrib.ContentDisposition) { Name = item.Attrib.Name };
170171

171172
return contentItem;
172173
}).WhereNotNull();
173174
}
174175

176+
static string GetValueAsUsString(object value)
177+
{
178+
var cultureInfo = CultureInfo.GetCultureInfo("en-US");
179+
180+
return value switch
181+
{
182+
float f => f.ToString(cultureInfo),
183+
double d => d.ToString(cultureInfo),
184+
decimal c => c.ToString(cultureInfo),
185+
int i => i.ToString(cultureInfo),
186+
long l => l.ToString(cultureInfo),
187+
DateTime date => date.ToString(cultureInfo),
188+
_ => value?.ToString()
189+
};
190+
}
191+
175192
#endregion
176193
}
177-
}
194+
}

lib/Domain/Settings/RetryOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class RetryOptions
1111
public int RetryCount { get; set; } = 3;
1212

1313
/// <summary>
14-
/// Configures the sleep duration provider with an exponential wait time backoff between retries. Based on the current retry attempt.
14+
/// Configures the sleep duration provider with an exponential wait time between retries.
1515
/// E.G. sleepDurationProvider: retryCount => TimeSpan.FromSeconds(Math.Pow(retryOps.BackoffPower, retryCount))
1616
/// </summary>
1717
[UsedImplicitly]

lib/Extensions/TypedClientServiceCollectionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ public static IHttpClientBuilder AddGotenbergSharpClient(this IServiceCollection
4242

4343
static GotenbergSharpClientOptions GetOptions(IServiceProvider sp) =>
4444
sp.GetRequiredService<IOptions<GotenbergSharpClientOptions>>()?.Value;
45-
4645
}
4746
}

lib/Gotenberg.Sharp.Api.Client.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<Authors>CaptiveAire Systems</Authors>
2121
<Company>CaptiveAire Systems</Company>
2222
<PackageTags>Gotenberg pdf C# ApiClient unoconv</PackageTags>
23-
<Description>A C# api client for the Gotenberg micro-service v6.x, a docker-powered stateless API for converting HTML, Markdown and Office documents to PDF.</Description>
23+
<Description>A C# API client for interacting with the Gotenberg micro-service's API, a docker-powered stateless API for converting &amp; merging HTML, Markdown and Office documents to PDF. The client supports a configurable Polly retry policy with exponential back-off for handling transient exceptions.</Description>
2424
<IncludeSymbols>True</IncludeSymbols>
2525
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
2626
<PackageProjectUrl>https://github.com/ChangemakerStudios/GotenbergSharpApiClient</PackageProjectUrl>
@@ -36,9 +36,9 @@
3636
<ItemGroup>
3737
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
3838
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
39-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
40-
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4" />
41-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="3.1.4" />
39+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.5" />
40+
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.5" />
41+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="3.1.5" />
4242
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
4343
</ItemGroup>
4444

lib/Infrastructure/Pipeline/PolicyFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public static IAsyncPolicy<HttpResponseMessage> CreatePolicyFromSettings(IServic
4444
logger?.LogWarning(
4545
"{name} delaying for {delay} ms, then making retry # {retry} of {retryAttempts}. Retry reason: '{reason}'",
4646
context.PolicyKey, delay.TotalMilliseconds, retryCount, retryOps.RetryCount,
47-
outcome?.Exception?.Message ?? "No exception, check the gotenberg container logs for errors");
47+
outcome?.Exception?.Message ??
48+
"No exception, check the gotenberg container logs for errors");
4849
})
4950
.WithPolicyKey(nameof(GotenbergSharpClient));
5051
}

linqpad/HtmlConvert.linq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Query Kind="Program">
2-
<Reference Relative="..\lib\bin\Debug\netstandard2.1\Gotenberg.Sharp.API.Client.dll">lib\bin\Debug\netstandard2.1\Gotenberg.Sharp.API.Client.dll</Reference>
2+
<NuGetReference Version="1.0.0">Gotenberg.Sharp.API.Client</NuGetReference>
33
<Namespace>Gotenberg.Sharp.API.Client</Namespace>
44
<Namespace>Gotenberg.Sharp.API.Client.Domain.Builders</Namespace>
55
<Namespace>Gotenberg.Sharp.API.Client.Extensions</Namespace>

linqpad/HtmlWithMarkdown.linq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Query Kind="Program">
2-
<Reference Relative="..\lib\bin\Debug\netstandard2.1\Gotenberg.Sharp.API.Client.dll">lib\bin\Debug\netstandard2.1\Gotenberg.Sharp.API.Client.dll</Reference>
2+
<NuGetReference Version="1.0.0">Gotenberg.Sharp.API.Client</NuGetReference>
33
<Namespace>Gotenberg.Sharp.API.Client</Namespace>
44
<Namespace>Gotenberg.Sharp.API.Client.Domain.Builders</Namespace>
55
<Namespace>Gotenberg.Sharp.API.Client.Extensions</Namespace>

linqpad/OfficeMerge.linq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Query Kind="Program">
2-
<Reference Relative="..\lib\bin\Debug\netstandard2.1\Gotenberg.Sharp.API.Client.dll">lib\bin\Debug\netstandard2.1\Gotenberg.Sharp.API.Client.dll</Reference>
2+
<NuGetReference Version="1.0.0">Gotenberg.Sharp.API.Client</NuGetReference>
33
<Namespace>Gotenberg.Sharp.API.Client</Namespace>
44
<Namespace>Gotenberg.Sharp.API.Client.Domain.Builders</Namespace>
55
<Namespace>Gotenberg.Sharp.API.Client.Domain.Requests</Namespace>

0 commit comments

Comments
 (0)