Skip to content

Commit 6813c91

Browse files
committed
Added "version" support -- renaming all to "SetX" and deprecating old methods.
1 parent e0d6289 commit 6813c91

File tree

14 files changed

+259
-118
lines changed

14 files changed

+259
-118
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public void ConfigureServices(IServiceCollection services)
6565
var builder = new HtmlRequestBuilder()
6666
.AddDocument(doc =>
6767
doc.SetBody(GetBody()).SetFooter(GetFooter())
68-
).WithDimensions(dims =>
68+
).WithPageProperties(pp =>
6969
{
70-
dims.SetPaperSize(PaperSizes.A3)
70+
pp.SetPaperSize(PaperSizes.A3)
7171
.SetMargins(Margins.None)
7272
.SetScale(.99);
7373
}).WithAsyncAssets(async assets => assets.AddItem("some-image.jpg", await GetImageBytes()));
@@ -95,12 +95,12 @@ public async Task<Stream> CreateFromUrl(string headerPath, string footerPath)
9595
.AddAsyncHeaderFooter(async
9696
doc => doc.SetHeader(await File.ReadAllTextAsync(headerPath))
9797
.SetFooter(await File.ReadAllBytesAsync(footerPath)
98-
)).WithDimensions(dims =>
98+
)).WithPageProperties(pp =>
9999
{
100-
dims.SetPaperSize(PaperSizes.A4)
100+
pp.SetPaperSize(PaperSizes.A4)
101101
.SetMargins(Margins.None)
102102
.SetScale(.90)
103-
.LandScape();
103+
.SetLandscape();
104104
});
105105

106106
var request = await builder.BuildAsync();
@@ -130,11 +130,11 @@ public async Task<Stream> CreateFromMarkdown()
130130
.AddAsyncDocument(async
131131
doc => doc.SetHeader(await this.GetHeaderAsync())
132132
.SetBody(await GetBodyAsync())
133-
.ContainsMarkdown()
133+
.SetContainsMarkdown()
134134
.SetFooter(await GetFooterAsync())
135-
).WithDimensions(dims =>
135+
).WithPageProperties(pp =>
136136
{
137-
dims.UseChromeDefaults().LandScape().SetScale(.90);
137+
pp.UseChromeDefaults().SetLandscape().SetScale(.90);
138138
}).WithAsyncAssets(async
139139
a => a.AddItems(await GetMarkdownAssets())
140140
);
@@ -169,7 +169,7 @@ public async Task<Stream> CreateFromMarkdown()
169169
dimBuilder.SetPaperSize(PaperSizes.A4)
170170
.SetMargins(Margins.None)
171171
.SetScale(.90)
172-
.LandScape();
172+
.SetLandscape();
173173
});
174174

175175
var request = await builder.BuildAsync();
@@ -217,9 +217,9 @@ IEnumerable<UrlRequestBuilder> CreateBuilders(IEnumerable<Uri> uris)
217217
{
218218
dimBuilder.UseChromeDefaults()
219219
.SetScale(.90)
220-
.LandScape()
221-
.MarginLeft(.5)
222-
.MarginRight(.5);
220+
.SetLandscape()
221+
.SetMarginLeft(.5)
222+
.SetMarginRight(.5);
223223
});
224224
}
225225

lib/Domain/Builders/Faceted/DocumentBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ public DocumentBuilder(FullDocument content, Action<bool> setContainsMarkdown)
3434

3535
#region body
3636

37+
[Obsolete("Use SetContainsMarkdown()")]
3738
public DocumentBuilder ContainsMarkdown(bool containsMarkdown = true)
3839
{
3940
this._setContainsMarkdown(containsMarkdown);
4041
return this;
4142
}
4243

44+
public DocumentBuilder SetContainsMarkdown(bool containsMarkdown = true)
45+
{
46+
this._setContainsMarkdown(containsMarkdown);
47+
return this;
48+
}
49+
4350
public DocumentBuilder SetBody(ContentItem body)
4451
{
4552
this._content.Body = body ?? throw new ArgumentNullException(nameof(body));

lib/Domain/Builders/Faceted/PagePropertyBuilder.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,85 @@ public PagePropertyBuilder SetScale(double scale)
5656
return this;
5757
}
5858

59+
[Obsolete("Use SetPaperWidth")]
5960
public PagePropertyBuilder PaperWidth(double width)
6061
{
6162
this._pageProperties.PaperWidth = width;
6263
return this;
6364
}
6465

66+
[Obsolete("Use SetPaperHeight")]
6567
public PagePropertyBuilder PaperHeight(double height)
6668
{
6769
this._pageProperties.PaperHeight = height;
6870
return this;
6971
}
7072

73+
[Obsolete("Use SetMarginTop")]
7174
public PagePropertyBuilder MarginTop(double marginTop)
7275
{
7376
this._pageProperties.MarginTop = marginTop;
7477
return this;
7578
}
7679

80+
[Obsolete("Use SetMarginBottom")]
7781
public PagePropertyBuilder MarginBottom(double marginBottom)
7882
{
7983
this._pageProperties.MarginBottom = marginBottom;
8084
return this;
8185
}
8286

87+
[Obsolete("Use SetMarginLeft")]
8388
public PagePropertyBuilder MarginLeft(double marginLeft)
8489
{
8590
this._pageProperties.MarginLeft = marginLeft;
8691
return this;
8792
}
8893

94+
[Obsolete("Use SetMarginRight")]
8995
public PagePropertyBuilder MarginRight(double marginRight)
9096
{
9197
this._pageProperties.MarginRight = marginRight;
9298
return this;
9399
}
94100

95-
[Obsolete("Use Landscape()")]
101+
public PagePropertyBuilder SetPaperWidth(double width)
102+
{
103+
this._pageProperties.PaperWidth = width;
104+
return this;
105+
}
106+
107+
public PagePropertyBuilder SetPaperHeight(double height)
108+
{
109+
this._pageProperties.PaperHeight = height;
110+
return this;
111+
}
112+
113+
public PagePropertyBuilder SetMarginTop(double marginTop)
114+
{
115+
this._pageProperties.MarginTop = marginTop;
116+
return this;
117+
}
118+
119+
public PagePropertyBuilder SetMarginBottom(double marginBottom)
120+
{
121+
this._pageProperties.MarginBottom = marginBottom;
122+
return this;
123+
}
124+
125+
public PagePropertyBuilder SetMarginLeft(double marginLeft)
126+
{
127+
this._pageProperties.MarginLeft = marginLeft;
128+
return this;
129+
}
130+
131+
public PagePropertyBuilder SetMarginRight(double marginRight)
132+
{
133+
this._pageProperties.MarginRight = marginRight;
134+
return this;
135+
}
136+
137+
[Obsolete("Use SetLandscape()")]
96138
public PagePropertyBuilder LandScape(bool landscape = true)
97139
{
98140
this._pageProperties.Landscape = landscape;
@@ -104,7 +146,7 @@ public PagePropertyBuilder LandScape(bool landscape = true)
104146
/// </summary>
105147
/// <param name="landscape"></param>
106148
/// <returns></returns>
107-
public PagePropertyBuilder Landscape(bool landscape = true)
149+
public PagePropertyBuilder SetLandscape(bool landscape = true)
108150
{
109151
this._pageProperties.Landscape = landscape;
110152
return this;
@@ -115,7 +157,7 @@ public PagePropertyBuilder Landscape(bool landscape = true)
115157
/// </summary>
116158
/// <param name="prefer"></param>
117159
/// <returns></returns>
118-
public PagePropertyBuilder PreferCssPageSize(bool prefer = true)
160+
public PagePropertyBuilder SetPreferCssPageSize(bool prefer = true)
119161
{
120162
this._pageProperties.PreferCssPageSize = prefer;
121163
return this;
@@ -126,7 +168,7 @@ public PagePropertyBuilder PreferCssPageSize(bool prefer = true)
126168
/// </summary>
127169
/// <param name="omitBackground"></param>
128170
/// <returns></returns>
129-
public PagePropertyBuilder OmitBackground(bool omitBackground = true)
171+
public PagePropertyBuilder SetOmitBackground(bool omitBackground = true)
130172
{
131173
this._pageProperties.OmitBackground = omitBackground;
132174
return this;
@@ -137,7 +179,7 @@ public PagePropertyBuilder OmitBackground(bool omitBackground = true)
137179
/// </summary>
138180
/// <param name="printBackground"></param>
139181
/// <returns></returns>
140-
public PagePropertyBuilder PrintBackground(bool printBackground = true)
182+
public PagePropertyBuilder SetPrintBackground(bool printBackground = true)
141183
{
142184
this._pageProperties.PrintBackground = printBackground;
143185
return this;
@@ -148,7 +190,7 @@ public PagePropertyBuilder PrintBackground(bool printBackground = true)
148190
/// </summary>
149191
/// <param name="generateDocumentOutline"></param>
150192
/// <returns></returns>
151-
public PagePropertyBuilder GenerateDocumentOutline(bool generateDocumentOutline = true)
193+
public PagePropertyBuilder SetGenerateDocumentOutline(bool generateDocumentOutline = true)
152194
{
153195
this._pageProperties.GenerateDocumentOutline = generateDocumentOutline;
154196
return this;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2019-2025 Chris Mohan, Jaben Cargman
2+
// and GotenbergSharpApiClient Contributors
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
namespace Gotenberg.Sharp.API.Client.Domain.Requests.ApiRequests;
17+
18+
internal sealed class GetApiRequestImpl : IApiRequest
19+
{
20+
internal GetApiRequestImpl(string apiPath, ILookup<string, string?>? headers = null, bool isWebhookRequest = false)
21+
{
22+
this.ApiPath = apiPath;
23+
this.IsWebhookRequest = isWebhookRequest;
24+
this.Headers = headers;
25+
}
26+
27+
public string ApiPath { get; }
28+
29+
public ILookup<string, string?>? Headers { get; }
30+
31+
private const string BoundaryPrefix = Constants.HttpContent.MultipartData.BoundaryPrefix;
32+
33+
public bool IsWebhookRequest { get; }
34+
35+
public HttpRequestMessage ToApiRequestMessage()
36+
{
37+
var message = new HttpRequestMessage(HttpMethod.Get, this.ApiPath);
38+
39+
foreach (var header in this.Headers.IfNullEmpty())
40+
{
41+
message.Headers.Add(header.Key, header);
42+
}
43+
44+
return message;
45+
}
46+
}

lib/Domain/Requests/IApiRequest.cs renamed to lib/Domain/Requests/ApiRequests/IApiRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
namespace Gotenberg.Sharp.API.Client.Domain.Requests;
16+
namespace Gotenberg.Sharp.API.Client.Domain.Requests.ApiRequests;
1717

1818
public interface IApiRequest
1919
{
Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2024 Chris Mohan, Jaben Cargman
1+
// Copyright 2019-2025 Chris Mohan, Jaben Cargman
22
// and GotenbergSharpApiClient Contributors
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,53 +13,46 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
namespace Gotenberg.Sharp.API.Client.Domain.Requests;
16+
namespace Gotenberg.Sharp.API.Client.Domain.Requests.ApiRequests;
1717

18-
internal sealed class ApiRequestImplementation : IApiRequest, IConvertToHttpContent
18+
internal sealed class PostApiRequestImpl : IApiRequest, IConvertToHttpContent
1919
{
2020
private readonly Func<IEnumerable<HttpContent>> _toHttpContent;
2121

22-
internal ApiRequestImplementation(
22+
internal PostApiRequestImpl(
2323
Func<IEnumerable<HttpContent>> toHttpContent,
2424
string apiPath,
25-
ILookup<string, string?> headers,
25+
ILookup<string, string?>? headers,
2626
bool isWebhookRequest)
2727
{
28-
this._toHttpContent = toHttpContent;
29-
this.ApiPath = apiPath;
30-
this.IsWebhookRequest = isWebhookRequest;
31-
this.Headers = headers;
32-
}
33-
34-
public IEnumerable<HttpContent> ToHttpContent()
35-
{
36-
return this._toHttpContent();
28+
_toHttpContent = toHttpContent;
29+
ApiPath = apiPath;
30+
IsWebhookRequest = isWebhookRequest;
31+
Headers = headers;
3732
}
3833

3934
public string ApiPath { get; }
4035

41-
public bool IsWebhookRequest { get; }
42-
43-
public ILookup<string, string?> Headers { get; }
36+
public ILookup<string, string?>? Headers { get; }
4437

4538
private const string BoundaryPrefix = Constants.HttpContent.MultipartData.BoundaryPrefix;
4639

40+
public bool IsWebhookRequest { get; }
41+
4742
public HttpRequestMessage ToApiRequestMessage()
4843
{
49-
var formContent =
50-
new MultipartFormDataContent($"{BoundaryPrefix}{DateTime.Now.Ticks}");
44+
var formContent = new MultipartFormDataContent($"{BoundaryPrefix}{DateTime.Now.Ticks}");
5145

52-
foreach (var item in this.ToHttpContent()) formContent.Add(item);
46+
foreach (var item in ToHttpContent()) formContent.Add(item);
5347

54-
var message = new HttpRequestMessage(HttpMethod.Post, this.ApiPath)
55-
{
56-
Content = formContent
57-
};
48+
var message = new HttpRequestMessage(HttpMethod.Post, ApiPath) { Content = formContent };
5849

59-
if (this.Headers.Any())
60-
foreach (var header in this.Headers)
50+
if (Headers?.Any() ?? false)
51+
foreach (var header in Headers)
6152
message.Headers.Add(header.Key, header);
6253

6354
return message;
6455
}
56+
57+
public IEnumerable<HttpContent> ToHttpContent() => _toHttpContent();
6558
}

lib/Domain/Requests/BuildRequestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
16+
using Gotenberg.Sharp.API.Client.Domain.Requests.ApiRequests;
1717

1818
namespace Gotenberg.Sharp.API.Client.Domain.Requests;
1919

@@ -56,6 +56,6 @@ public virtual IApiRequest CreateApiRequest()
5656
var headers = (this.Config?.GetHeaders()).IfNullEmpty()
5757
.ToLookup(s => s.Name, s => s.Value);
5858

59-
return new ApiRequestImplementation(this.ToHttpContent, this.ApiPath, headers, isWebHook);
59+
return new PostApiRequestImpl(this.ToHttpContent, this.ApiPath, headers, isWebHook);
6060
}
6161
}

0 commit comments

Comments
 (0)