Skip to content

Commit 817ba64

Browse files
committed
Address CodeRabbit review feedback (round 2)
1 parent 46d9eec commit 817ba64

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ using Gotenberg.Sharp.API.Client;
154154
using Gotenberg.Sharp.API.Client.Domain.Builders;
155155
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
156156
using Gotenberg.Sharp.API.Client.Domain.Requests.Facets; // For Cookie, etc.
157+
using Gotenberg.Sharp.API.Client.Domain.ValueObjects; // For ScreenshotFormat, etc.
157158
```
158159

159160
### HTML To PDF

examples/Screenshot/Program.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
var destinationDirectory = args.Length > 0 ? args[0] : Path.Combine(Directory.GetCurrentDirectory(), "output");
1818
Directory.CreateDirectory(destinationDirectory);
1919

20+
var sharpClient = CreateClient(options);
21+
2022
// Screenshot from HTML
21-
var htmlPath = await ScreenshotFromHtml(destinationDirectory, options);
23+
var htmlPath = await ScreenshotFromHtml(destinationDirectory, sharpClient);
2224
Console.WriteLine($"HTML screenshot: {htmlPath}");
2325

2426
// Screenshot from URL
25-
var urlPath = await ScreenshotFromUrl(destinationDirectory, options);
27+
var urlPath = await ScreenshotFromUrl(destinationDirectory, sharpClient);
2628
Console.WriteLine($"URL screenshot: {urlPath}");
2729

28-
static async Task<string> ScreenshotFromHtml(string destinationDirectory, GotenbergSharpClientOptions options)
30+
static async Task<string> ScreenshotFromHtml(string destinationDirectory, GotenbergSharpClient sharpClient)
2931
{
30-
var sharpClient = CreateClient(options);
31-
3232
var builder = new ScreenshotHtmlRequestBuilder()
3333
.AddDocument(doc => doc.SetBody(@"
3434
<html>
@@ -41,18 +41,16 @@ static async Task<string> ScreenshotFromHtml(string destinationDirectory, Gotenb
4141
.SetSize(1280, 720)
4242
.SetFormat(ScreenshotFormat.Png));
4343

44-
var response = await sharpClient.ScreenshotHtmlAsync(builder);
44+
await using var response = await sharpClient.ScreenshotHtmlAsync(builder);
4545

4646
var resultPath = Path.Combine(destinationDirectory, $"ScreenshotHtml-{DateTime.Now:yyyyMMddHHmmss}.png");
4747
await using var file = File.Create(resultPath);
4848
await response.CopyToAsync(file);
4949
return resultPath;
5050
}
5151

52-
static async Task<string> ScreenshotFromUrl(string destinationDirectory, GotenbergSharpClientOptions options)
52+
static async Task<string> ScreenshotFromUrl(string destinationDirectory, GotenbergSharpClient sharpClient)
5353
{
54-
var sharpClient = CreateClient(options);
55-
5654
var builder = new ScreenshotUrlRequestBuilder()
5755
.SetUrl("https://example.com")
5856
.WithScreenshotProperties(p => p
@@ -61,7 +59,7 @@ static async Task<string> ScreenshotFromUrl(string destinationDirectory, Gotenbe
6159
.SetQuality(90)
6260
.SetClip());
6361

64-
var response = await sharpClient.ScreenshotUrlAsync(builder);
62+
await using var response = await sharpClient.ScreenshotUrlAsync(builder);
6563

6664
var resultPath = Path.Combine(destinationDirectory, $"ScreenshotUrl-{DateTime.Now:yyyyMMddHHmmss}.jpg");
6765
await using var file = File.Create(resultPath);

src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected override IEnumerable<HttpContent> ToHttpContent()
2929
{
3030
return this.ScreenshotProperties.ToHttpContent()
3131
.Concat(this.ConversionBehaviors.ToHttpContent())
32-
.Concat(this.Config.IfNullEmptyContent())
33-
.Concat(base.ToHttpContent());
32+
.Concat(this.Config.IfNullEmptyContent());
3433
}
3534
}

test/GotenbergSharpClient.Tests/ScreenshotTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public async Task ScreenshotHtml_ReturnsImage()
149149
.SetSize(800, 600)
150150
.SetFormat(ScreenshotFormat.Png));
151151

152-
var result = await client.ScreenshotHtmlAsync(builder);
152+
using var result = await client.ScreenshotHtmlAsync(builder);
153153

154154
result.Should().NotBeNull();
155155
result.Length.Should().BeGreaterThan(0);
@@ -177,7 +177,7 @@ public async Task ScreenshotUrl_ReturnsImage()
177177
.SetFormat(ScreenshotFormat.Jpeg)
178178
.SetQuality(90));
179179

180-
var result = await client.ScreenshotUrlAsync(builder);
180+
using var result = await client.ScreenshotUrlAsync(builder);
181181

182182
result.Should().NotBeNull();
183183
result.Length.Should().BeGreaterThan(0);

0 commit comments

Comments
 (0)