diff --git a/Urlbox.MsTest/UrlboxTest.cs b/Urlbox.MsTest/UrlboxTest.cs
index d9260cca..235ddcb1 100644
--- a/Urlbox.MsTest/UrlboxTest.cs
+++ b/Urlbox.MsTest/UrlboxTest.cs
@@ -1,116 +1,236 @@
-using System.Diagnostics;
+using System.Diagnostics;
using System.Dynamic;
+using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Screenshots;
+
[TestClass]
public class UrlTests
{
+ UrlboxOptions urlboxAllOptions = new UrlboxOptions(url: "https://urlbox.com")
+ {
+ Html = "test",
+ Width = 123,
+ Height = 123,
+ FullPage = true,
+ Selector = "test",
+ Clip = "test",
+ Gpu = true,
+ ResponseType = "test",
+ BlockAds = true,
+ HideCookieBanners = true,
+ ClickAccept = true,
+ BlockUrls = true,
+ BlockImages = true,
+ BlockFonts = true,
+ BlockMedias = true,
+ BlockStyles = true,
+ BlockScripts = true,
+ BlockFrames = true,
+ BlockFetch = true,
+ BlockXhr = true,
+ BlockSockets = true,
+ HideSelector = "test",
+ Js = "test",
+ Css = "test",
+ DarkMode = true,
+ ReducedMotion = true,
+ Retina = true,
+ ThumbWidth = 123,
+ ThumbHeight = 123,
+ ImgFit = "test",
+ ImgPosition = "test",
+ ImgBg = "test",
+ ImgPad = 123,
+ Quality = 123,
+ Transparent = true,
+ MaxHeight = 123,
+ Download = "test",
+ PdfPageSize = "test",
+ PdfPageRange = "test",
+ PdfPageWidth = 123,
+ PdfPageHeight = 123,
+ PdfMargin = "test",
+ PdfMarginTop = 123,
+ PdfMarginRight = 123,
+ PdfMarginBottom = 123,
+ PdfMarginLeft = 123,
+ PdfAutoCrop = true,
+ PdfScale = 0.12,
+ PdfOrientation = "test",
+ PdfBackground = true,
+ DisableLigatures = true,
+ Media = "test",
+ PdfShowHeader = true,
+ PdfHeader = "test",
+ PdfShowFooter = true,
+ PdfFooter = "test",
+ Readable = true,
+ Force = true,
+ Unique = "test",
+ Ttl = 123,
+ Proxy = "test",
+ Header = "test",
+ Cookie = "test",
+ UserAgent = "test",
+ Platform = "test",
+ AcceptLang = "test",
+ Authorization = "test",
+ Tz = "test",
+ EngineVersion = "test",
+ Delay = 123,
+ Timeout = 123,
+ WaitUntil = "test",
+ WaitFor = "test",
+ WaitToLeave = "test",
+ WaitTimeout = 123,
+ FailIfSelectorMissing = true,
+ FailIfSelectorPresent = true,
+ FailOn4xx = true,
+ FailOn5xx = true,
+ ScrollTo = "test",
+ Click = "test",
+ ClickAll = "test",
+ Hover = "test",
+ BgColor = "test",
+ DisableJs = true,
+ FullPageMode = "test",
+ FullWidth = true,
+ AllowInfinite = true,
+ SkipScroll = true,
+ DetectFullHeight = true,
+ MaxSectionHeight = 123,
+ ScrollIncrement = "test",
+ ScrollDelay = 123,
+ Highlight = "test",
+ HighlightFg = "test",
+ HighlightBg = "test",
+ Latitude = 0.12,
+ Longitude = 0.12,
+ Accuracy = 123,
+ UseS3 = true,
+ S3Path = "test",
+ S3Bucket = "test",
+ S3Endpoint = "test",
+ S3Region = "test",
+ CdnHost = "test",
+ S3StorageClass = "test",
+ };
+
private Urlbox urlbox;
+ private UrlGenerator urlGenerator;
+
[TestInitialize]
public void TestInitialize()
{
- urlbox = new Urlbox("MY_API_KEY", "secret");
+ urlGenerator = new UrlGenerator("MY_API_KEY", "secret");
+ urlbox = new Urlbox("MY_API_KEY", "secret");
}
- //[TestMethod]
- //public void WithOptions()
- //{
- // dynamic options = new ExpandoObject();
- // options.url = "bbc.co.uk";
- // options.Width = 1280;
- // options.Thumb_Width = 500;
- // options.Full_Page = true;
+ [TestMethod]
+ public void GenerateUrlboxUrl_WithAllOptions()
+ {
+ var output = urlbox.GenerateUrlboxUrl(urlboxAllOptions);
+ Console.WriteLine(output);
- // var output = urlbox.GenerateUrlboxUrl(options);
- // Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/d6b5068716c19ba4556648ad9df047d5847cda0c/png?url=bbc.co.uk&width=1280&thumb_width=500&full_page=true",
- // output, "Not OK");
- //}
+ Assert.AreEqual(
+ "https://api.urlbox.com/v1/MY_API_KEY/1f11feec77221ee8e21911c342d6b3ba8d2b5153/png?url=https%3A%2F%2Furlbox.com&html=test&width=123&height=123&full_page=true&selector=test&clip=test&gpu=true&response_type=test&block_ads=true&hide_cookie_banners=true&click_accept=true&block_urls=true&block_images=true&block_fonts=true&block_medias=true&block_styles=true&block_scripts=true&block_frames=true&block_fetch=true&block_xhr=true&block_sockets=true&hide_selector=test&js=test&css=test&dark_mode=true&reduced_motion=true&retina=true&thumb_width=123&thumb_height=123&img_fit=test&img_position=test&img_bg=test&img_pad=123&quality=123&transparent=true&max_height=123&download=test&pdf_page_size=test&pdf_page_range=test&pdf_page_width=123&pdf_page_height=123&pdf_margin=test&pdf_margin_top=123&pdf_margin_right=123&pdf_margin_bottom=123&pdf_margin_left=123&pdf_auto_crop=true&pdf_scale=0.12&pdf_orientation=test&pdf_background=true&disable_ligatures=true&media=test&pdf_show_header=true&pdf_header=test&pdf_show_footer=true&pdf_footer=test&readable=true&force=true&unique=test&ttl=123&proxy=test&header=test&cookie=test&user_agent=test&platform=test&accept_lang=test&authorization=test&tz=test&engine_version=test&delay=123&timeout=123&wait_until=test&wait_for=test&wait_to_leave=test&wait_timeout=123&fail_if_selector_missing=true&fail_if_selector_present=true&fail_on4xx=true&fail_on5xx=true&scroll_to=test&click=test&click_all=test&hover=test&bg_color=test&disable_js=true&full_page_mode=test&full_width=true&allow_infinite=true&skip_scroll=true&detect_full_height=true&max_section_height=123&scroll_increment=test&scroll_delay=123&highlight=test&highlight_fg=test&highlight_bg=test&latitude=0.12&longitude=0.12&accuracy=123&use_s3=true&s3_path=test&s3_bucket=test&s3_endpoint=test&s3_region=test&cdn_host=test&s3_storage_class=test",
+ output
+ );
+ }
[TestMethod]
- public void WithUrlEncodedOptions()
+ public void GenerateUrlboxUrl_WithUrlEncodedOptions()
{
- dynamic options = new ExpandoObject();
- options.url = "bbc.co.uk";
+ var options = new UrlboxOptions(url: "urlbox.com");
options.Width = 1280;
- options.Thumb_Width = 500;
+ options.ThumbWidth = 500;
options.FullPage = true;
options.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
var output = urlbox.GenerateUrlboxUrl(options);
- Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/9c675714240421b50a9f76892d702cb0a5376ccf/png?url=bbc.co.uk&width=1280&thumb_width=500&full_page=true&user_agent=Mozilla%2F5.0%20%28Windows%20NT%206.1%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F41.0.2228.0%20Safari%2F537.36",
- output, "Not OK");
+ Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/5727321d7976d07d9f24649e6db556b2a6a71d9d/png?url=urlbox.com&width=1280&full_page=true&thumb_width=500&user_agent=Mozilla%2F5.0%20%28Windows%20NT%206.1%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F41.0.2228.0%20Safari%2F537.36",
+ output);
}
[TestMethod]
- public void UrlNeedsEncoding()
+ public void GenerateUrlboxUrl_UrlNeedsEncoding()
{
- dynamic options = new ExpandoObject();
- options.url = "https://www.hatchtank.io/markup/index.html?url2png=true&board=demo_1645_1430";
+ var options = new UrlboxOptions(url: "https://www.hatchtank.io/markup/index.html?url2png=true&board=demo_1645_1430");
var output = urlbox.GenerateUrlboxUrl(options);
Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/4b8ac501f3aaccbea2081a7105302593174ebc23/png?url=https%3A%2F%2Fwww.hatchtank.io%2Fmarkup%2Findex.html%3Furl2png%3Dtrue%26board%3Ddemo_1645_1430",
- output, "Not OK");
+ output, "Not OK");
}
[TestMethod]
- public void WithUserAgent()
+ public void GenerateUrlboxUrl_WithUserAgent()
{
- dynamic options = new ExpandoObject();
- options.Url = "https://bbc.co.uk";
- options.User_Agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36";
+ var options = new UrlboxOptions(url: "https://bbc.co.uk");
+ options.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36";
var output = urlbox.GenerateUrlboxUrl(options);
Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/c2708392a4d881b4816e61b3ed4d89ae4f2c4a57/png?url=https%3A%2F%2Fbbc.co.uk&user_agent=Mozilla%2F5.0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010_12_6%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F62.0.3202.94%20Safari%2F537.36", output);
}
[TestMethod]
- public void IgnoreEmptyValuesAndFormat()
+ public void GenerateUrlboxUrl_IgnoreEmptyValuesAndFormat()
{
- dynamic options = new ExpandoObject();
- options.Url = "https://bbc.com";
- options.Full_Page = false;
- options.ThumbWidth = "";
- options.Delay = null;
+ var options = new UrlboxOptions(url: "https://bbc.co.uk");
+ options.FullPage = false;
+ options.ThumbWidth = 0;
+ options.Delay = 0;
options.Format = "pdf";
options.Selector = "";
options.WaitFor = "";
var output = urlbox.GenerateUrlboxUrl(options);
- Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/ffb3bf33fe1cc481c33f78de7762134662b63dad/png?url=https%3A%2F%2Fbbc.com&full_page=false",
- output, "Not OK");
+ Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/8e00ad9a8d7c4abcd462a9b8ec041c3661f13995/png?url=https%3A%2F%2Fbbc.co.uk",
+ output);
}
[TestMethod]
- public void FormatWorks()
+ public void GenerateUrlboxUrl_FormatWorks()
{
- dynamic options = new ExpandoObject();
- options.url = "bbc.co.uk";
+ var options = new UrlboxOptions(url: "https://bbc.co.uk");
var output = urlbox.GenerateUrlboxUrl(options, "jpeg");
- Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/75c9016e7f98f90f5eabfd348f3091f7bf625153/jpeg?url=bbc.co.uk", output, "Not OK!");
+ Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/8e00ad9a8d7c4abcd462a9b8ec041c3661f13995/jpeg?url=https%3A%2F%2Fbbc.co.uk", output, "Not OK!");
}
[TestMethod]
- public void WithoutUrl()
+ public void GenerateUrlboxUrl_WithHtml()
{
- dynamic options = new ExpandoObject();
- //options.Width = 500;
- options.full_page = true;
+ var options = new UrlboxOptions(html: "
test
");
+ options.FullPage = true;
var output = urlbox.GenerateUrlboxUrl(options);
- Assert.IsTrue(true);
+
+ Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/6e911f299782a8de56b56f47d8670bd0f085f41b/png?html=%3Ch1%3Etest%3C%2Fh1%3E&full_page=true", output);
}
[TestMethod]
- public void SimpleURL()
+ public void GenerateUrlboxUrl_WithSimpleURL()
{
- dynamic options = new ExpandoObject();
- options.url = "bbc.co.uk";
+ var options = new UrlboxOptions(url: "bbc.co.uk");
var output = urlbox.GenerateUrlboxUrl(options);
Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/75c9016e7f98f90f5eabfd348f3091f7bf625153/png?url=bbc.co.uk",
output, "Not OK");
}
+
+ [TestMethod]
+ public void ToQueryString_ShouldRemoveFormatFromQueryString()
+ {
+ var options = new UrlboxOptions(url: "https://urlbox.com")
+ {
+ Format = "png",
+ FullPage = true
+ };
+ var output = urlGenerator.GenerateUrlboxUrl(options);
+
+ Assert.AreEqual("https://api.urlbox.com/v1/MY_API_KEY/bba10010e9ece486d34a82344170ae5b4dd5f347/png?url=https%3A%2F%2Furlbox.com&full_page=true", output);
+ }
}
[TestClass]
@@ -128,11 +248,11 @@ public void TestInitialize()
[TestMethod]
public async Task TestDownloadToFile()
{
- //Urlbox s = new Urlbox("MY_API_KEY", "secret");
var urlboxUrl = "https://api.urlbox.com/v1/ca482d7e-9417-4569-90fe-80f7c5e1c781/5ee277f206869517d00cf1951f30d48ef9c64bfe/png?url=google.com";
var result = await urlbox.DownloadToFile(urlboxUrl, "result.png");
- //Debug.WriteLine(result, "RESULT - Download");
- Assert.IsTrue(true);
+ Assert.IsNotNull(result);
+ Assert.IsInstanceOfType(result, typeof(String));
+ Assert.IsTrue(result.Length >= 0);
}
[TestMethod]
@@ -140,17 +260,50 @@ public async Task TestDownloadBase64()
{
var urlboxUrl = "https://api.urlbox.com/v1/ca482d7e-9417-4569-90fe-80f7c5e1c781/59148a4e454a2c7051488defdb8b246bdea61ace/jpeg?url=bbc.co.uk";
var base64result = await urlbox.DownloadAsBase64(urlboxUrl);
- //Debug.WriteLine(base64result, "RESULT - BASE64");
Assert.IsTrue(true);
}
[TestMethod]
public async Task TestDownloadFail()
{
- //Urlbox s = new Urlbox("MY_API_KEY", "secret");
var urlboxUrl = "https://api.urlbox.com/v1/ca482d7e-9417-4569-90fe-80f7c5e1c781/59148a4e454a2c7051488defdb8b246bdea61ac/jpeg?url=bbc.co.uk";
var base64result = await urlbox.DownloadAsBase64(urlboxUrl);
Debug.WriteLine(base64result, "RESULT - BASE64");
Assert.IsTrue(true);
- }
-}
+ }
+}
+
+
+[TestClass]
+public class UrlboxOptionsTest
+{
+ [TestMethod]
+ public void UrlboxOptions_MissingHTMLandURL()
+ {
+ Assert.ThrowsException(() => new UrlboxOptions());
+ }
+
+ [TestMethod]
+ public void UrlboxOptions_CreatesSuccess_URL()
+ {
+ string url = "https://urlbox.com";
+ var urlboxOptions = new UrlboxOptions(url: url);
+
+ Assert.IsNotNull(urlboxOptions);
+ Assert.IsInstanceOfType(urlboxOptions, typeof(UrlboxOptions));
+ Assert.AreEqual(url, urlboxOptions.Url);
+ Assert.IsNull(urlboxOptions.Html);
+ }
+
+ [TestMethod]
+ public void UrlboxOptions_CreatesSuccess_HTML()
+ {
+ string html = "test
";
+ var urlboxOptions = new UrlboxOptions(html: html);
+
+ Assert.IsNotNull(urlboxOptions);
+ Assert.IsInstanceOfType(urlboxOptions, typeof(UrlboxOptions));
+ Assert.AreEqual(html, urlboxOptions.Html);
+ Assert.IsNull(urlboxOptions.Url);
+ }
+}
diff --git a/Urlbox/Urlbox/UrlGenerator.cs b/Urlbox/Urlbox/UrlGenerator.cs
index 4487280f..f254a732 100644
--- a/Urlbox/Urlbox/UrlGenerator.cs
+++ b/Urlbox/Urlbox/UrlGenerator.cs
@@ -1,10 +1,10 @@
using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Security.Cryptography;
+using System.Collections.Generic;
+using System.IO;
+using System.Security.Cryptography;
using System.Text;
-using System.Linq;
-
+using System.Linq;
+
namespace Screenshots
{
public class UrlGenerator
@@ -12,43 +12,77 @@ public class UrlGenerator
private String key;
private String secret;
- public UrlGenerator(string key, string secret){
+ public UrlGenerator(string key, string secret)
+ {
this.key = key;
this.secret = secret;
}
+ // private string ToQueryString(IDictionary options)
+ // {
+ // var result = options
+ // .ToList()
+ // .Where(pair => !pair.Key.ToLower().Equals("format")) // skip format option if present
+ // .Select(pair => new KeyValuePair(pair.Key, ConvertToString(pair.Value))) // convert values to string
+ // .Where(pair => !String.IsNullOrEmpty(pair.Value)) // skip empty/null values
+ // .Select(pair => string.Format("{0}={1}", FormatKeyName(pair.Key), Uri.EscapeDataString(pair.Value)))
+ // .ToArray();
+ // return String.Join("&", result);
+ // }
- private string ToQueryString(IDictionary options)
+ private string ToQueryString(UrlboxOptions options)
{
- var result = options
- .ToList()
- .Where(pair => !pair.Key.ToLower().Equals("format")) // skip format option if present
- .Select(pair => new KeyValuePair(pair.Key, ConvertToString(pair.Value))) // convert values to string
- .Where(pair => !String.IsNullOrEmpty(pair.Value)) // skip empty/null values
+ // Filter by reflection class' props
+ var properties = options.GetType().GetProperties();
+ var result = properties
+ .Where(prop =>
+ {
+ var value = prop.GetValue(options, null);
+ return value != null &&
+ !(value is bool && (bool)value == false) && // skip false if bool
+ !(value is int && (int)value == 0) && // skip 0's if int
+ !(value is double && (double)value == 0.0) && // skip 0's if double
+ !(value is string && string.IsNullOrEmpty((string)value)); // skip empty strings if string
+ })
+ .Select(prop => new KeyValuePair(prop.Name, ConvertToString(prop.GetValue(options))))
+ // .Where(pair => !string.IsNullOrEmpty(pair.Value)) // Skip empty values
+ .Where(pair => !pair.Key.ToLower().Equals("format")) // Skip 'format' if present
.Select(pair => string.Format("{0}={1}", FormatKeyName(pair.Key), Uri.EscapeDataString(pair.Value)))
.ToArray();
- return String.Join("&", result);
+
+ return string.Join("&", result);
}
- private static string FormatKeyName(string input)
+ private static string FormatKeyName(string input)
{
- return string.Concat(input.Select((x, i) => i > 0 && char.IsUpper(x) && !input[i-1].Equals('_') ? "_" + x.ToString() : x.ToString())).ToLower();
+ return string.Concat(input.Select((x, i) => i > 0 && char.IsUpper(x) && !input[i - 1].Equals('_') ? "_" + x.ToString() : x.ToString())).ToLower();
}
-
- private static string ConvertToString(object value)
- {
-
- var result = Convert.ToString(value);
- if (result.Equals("False") || result.Equals("True"))
- {
- result = result.ToLower();
- }
+
+ private static string ConvertToString(object value)
+ {
+
+ var result = Convert.ToString(value);
+ if (result.Equals("False") || result.Equals("True"))
+ {
+ result = result.ToLower();
+ }
return result;
}
-
- public string GenerateUrlboxUrl(IDictionary options, string format = "png")
+
+ // public string GenerateUrlboxUrl(IDictionary options, string format = "png")
+ // {
+ // var qs = ToQueryString(options);
+ // return string.Format("https://api.urlbox.com/v1/{0}/{1}/{2}?{3}",
+ // this.key,
+ // generateToken(qs),
+ // format,
+ // qs
+ // );
+ // }
+
+ public string GenerateUrlboxUrl(UrlboxOptions options, string format = "png")
{
var qs = ToQueryString(options);
return string.Format("https://api.urlbox.com/v1/{0}/{1}/{2}?{3}",
@@ -59,6 +93,7 @@ public string GenerateUrlboxUrl(IDictionary options, string form
);
}
+
private string generateToken(string queryString)
{
HMACSHA1 sha = new HMACSHA1(Encoding.UTF8.GetBytes(this.secret));
diff --git a/Urlbox/Urlbox/Urlbox.cs b/Urlbox/Urlbox/Urlbox.cs
index 944e82c5..71f49637 100644
--- a/Urlbox/Urlbox/Urlbox.cs
+++ b/Urlbox/Urlbox/Urlbox.cs
@@ -42,7 +42,7 @@ public Urlbox(string key, string secret)
/// The options for the screenshot
/// The image format (e.g., "png", "jpg").
/// A Base64-encoded string of the screenshot.
- public async Task DownloadAsBase64(IDictionary options, string format = "png")
+ public async Task DownloadAsBase64(UrlboxOptions options, string format = "png")
{
var urlboxUrl = this.GenerateUrlboxUrl(options, format);
return await DownloadAsBase64(urlboxUrl);
@@ -72,7 +72,7 @@ public async Task DownloadAsBase64(string urlboxUrl)
/// The file path where the screenshot will be saved.
/// The image format (e.g., "png", "jpg"). Default is "png".
/// The contents of the downloaded file as a string.
- public async Task DownloadToFile(IDictionary options, string filename, string format = "png")
+ public async Task DownloadToFile(UrlboxOptions options, string filename, string format = "png")
{
var urlboxUrl = GenerateUrlboxUrl(options, format);
return await DownloadToFile(urlboxUrl, filename);
@@ -130,7 +130,7 @@ private async Task Download(string urlboxUrl, Func
/// The options for the screenshot.
/// A render link Url to render a PNG screenshot.
- public string GeneratePNGUrl(IDictionary options)
+ public string GeneratePNGUrl(UrlboxOptions options)
{
return GenerateUrlboxUrl(options, "png");
}
@@ -140,7 +140,7 @@ public string GeneratePNGUrl(IDictionary options)
///
/// The options for the screenshot.
/// A render link Url to render a JPEG screenshot.
- public string GenerateJPEGUrl(IDictionary options)
+ public string GenerateJPEGUrl(UrlboxOptions options)
{
return GenerateUrlboxUrl(options, "jpg");
}
@@ -150,7 +150,7 @@ public string GenerateJPEGUrl(IDictionary options)
///
/// The options for generating the PDF.
/// A render link Url to render a PDF file.
- public string GeneratePDFUrl(IDictionary options)
+ public string GeneratePDFUrl(UrlboxOptions options)
{
return GenerateUrlboxUrl(options, "pdf");
}
@@ -161,9 +161,136 @@ public string GeneratePDFUrl(IDictionary options)
/// The options for generating the screenshot or PDF.
/// The format of the output, e.g., "png", "jpg", "pdf".
/// A render link URL to render the content.
- public string GenerateUrlboxUrl(IDictionary options, string format = "png")
+ public string GenerateUrlboxUrl(UrlboxOptions options, string format = "png")
{
return urlGenerator.GenerateUrlboxUrl(options, format);
}
}
+
+ ///
+ /// Initializes a new instance of the UrlboxOptions. These are used as part of any Urlbox method which requires render options.
+ ///
+ /// Thrown when the Url OR Html option isn't passed in on init.
+ public class UrlboxOptions
+ {
+
+ public UrlboxOptions(string url = null, string html = null)
+ {
+ if (string.IsNullOrEmpty(url) && string.IsNullOrEmpty(html))
+ {
+ throw new ArgumentException("Either of options 'url' or 'html' must be provided.");
+ }
+ Url = url;
+ Html = html;
+ }
+
+ public string Url { get; set; }
+ public string Html { get; set; }
+ public string Format { get; set; }
+ public int Width { get; set; }
+ public int Height { get; set; }
+ public bool FullPage { get; set; }
+ public string Selector { get; set; }
+ public string Clip { get; set; }
+ public bool Gpu { get; set; }
+ public string ResponseType { get; set; }
+ public bool BlockAds { get; set; }
+ public bool HideCookieBanners { get; set; }
+ public bool ClickAccept { get; set; }
+ public bool BlockUrls { get; set; }
+ public bool BlockImages { get; set; }
+ public bool BlockFonts { get; set; }
+ public bool BlockMedias { get; set; }
+ public bool BlockStyles { get; set; }
+ public bool BlockScripts { get; set; }
+ public bool BlockFrames { get; set; }
+ public bool BlockFetch { get; set; }
+ public bool BlockXhr { get; set; }
+ public bool BlockSockets { get; set; }
+ public string HideSelector { get; set; }
+ public string Js { get; set; }
+ public string Css { get; set; }
+ public bool DarkMode { get; set; }
+ public bool ReducedMotion { get; set; }
+ public bool Retina { get; set; }
+ public int ThumbWidth { get; set; }
+ public int ThumbHeight { get; set; }
+ public string ImgFit { get; set; }
+ public string ImgPosition { get; set; }
+ public string ImgBg { get; set; }
+ public int ImgPad { get; set; }
+ public int Quality { get; set; }
+ public bool Transparent { get; set; }
+ public int MaxHeight { get; set; }
+ public string Download { get; set; }
+ public string PdfPageSize { get; set; }
+ public string PdfPageRange { get; set; }
+ public int PdfPageWidth { get; set; }
+ public int PdfPageHeight { get; set; }
+ public string PdfMargin { get; set; }
+ public int PdfMarginTop { get; set; }
+ public int PdfMarginRight { get; set; }
+ public int PdfMarginBottom { get; set; }
+ public int PdfMarginLeft { get; set; }
+ public bool PdfAutoCrop { get; set; }
+ public double PdfScale { get; set; }
+ public string PdfOrientation { get; set; }
+ public bool PdfBackground { get; set; }
+ public bool DisableLigatures { get; set; }
+ public string Media { get; set; }
+ public bool PdfShowHeader { get; set; }
+ public string PdfHeader { get; set; }
+ public bool PdfShowFooter { get; set; }
+ public string PdfFooter { get; set; }
+ public bool Readable { get; set; }
+ public bool Force { get; set; }
+ public string Unique { get; set; }
+ public int Ttl { get; set; }
+ public string Proxy { get; set; }
+ public string Header { get; set; }
+ public string Cookie { get; set; }
+ public string UserAgent { get; set; }
+ public string Platform { get; set; }
+ public string AcceptLang { get; set; }
+ public string Authorization { get; set; }
+ public string Tz { get; set; }
+ public string EngineVersion { get; set; }
+ public int Delay { get; set; }
+ public int Timeout { get; set; }
+ public string WaitUntil { get; set; }
+ public string WaitFor { get; set; }
+ public string WaitToLeave { get; set; }
+ public int WaitTimeout { get; set; }
+ public bool FailIfSelectorMissing { get; set; }
+ public bool FailIfSelectorPresent { get; set; }
+ public bool FailOn4xx { get; set; }
+ public bool FailOn5xx { get; set; }
+ public string ScrollTo { get; set; }
+ public string Click { get; set; }
+ public string ClickAll { get; set; }
+ public string Hover { get; set; }
+ public string BgColor { get; set; }
+ public bool DisableJs { get; set; }
+ public string FullPageMode { get; set; }
+ public bool FullWidth { get; set; }
+ public bool AllowInfinite { get; set; }
+ public bool SkipScroll { get; set; }
+ public bool DetectFullHeight { get; set; }
+ public int MaxSectionHeight { get; set; }
+ public string ScrollIncrement { get; set; }
+ public int ScrollDelay { get; set; }
+ public string Highlight { get; set; }
+ public string HighlightFg { get; set; }
+ public string HighlightBg { get; set; }
+ public double Latitude { get; set; }
+ public double Longitude { get; set; }
+ public int Accuracy { get; set; }
+ public bool UseS3 { get; set; }
+ public string S3Path { get; set; }
+ public string S3Bucket { get; set; }
+ public string S3Endpoint { get; set; }
+ public string S3Region { get; set; }
+ public string CdnHost { get; set; }
+ public string S3StorageClass { get; set; }
+ }
}
\ No newline at end of file