Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Migration of .io to .com + sync/async/webhook methods #2

Open
wants to merge 138 commits into
base: master
Choose a base branch
from

Conversation

AJCJ1
Copy link
Collaborator

@AJCJ1 AJCJ1 commented Oct 14, 2024

Changes

Updates the occurrences of .io to .com in:

  • Urlbox.MsTest
  • Urlbox.xUnitTest
  • UrlGenerator.cs - Base url changed to .com
  • Urlbox.cs - updated error messages

It also prepares the repo for upload to nuget, by adding a license.txt, readme.md, and additional metadata to the core .csproj file.

Updates dotnet package from 2.0 to 6.0

The package has been update to target dotnet 6.0. This is to support the various security, performance, and language enhancements to c# and .NET. It has not been updated to 8.0 due to the current LTS for 6.0. It is presumed that a large number of users may not have upgraded their .NET projects to 8.0 just yet.

Refactors options to be typed class

The Urlbox options are now a class, with typed properties based on the Urlbox documentation.

Implements render and renderAsync

The render and render async methods have been implemented. These will make a POST request to Urlbox, which will be handled by the private method MakeUrlboxPostRequest(). This method returns the interface IUrlboxResponse, which is then cast to a SyncUrlboxResponse or AsyncUrlboxResponse depending on the endpoint called. These give the end user a type to handle when making requests to Render() or RenderAsync().

Tests have also been written for these method which depend on a genuine Urlbox key and secret. This requires the developer to set environment variables via dotnet user-secrets init and dotnet user-secrets set with the URLBOX_KEY and URLBOX_SECRET. Instructions for this are detailed in the readme under contributing. These secrets would be required if this were to be placed in a GH actions runner, but could simply be set via the settings page of the GH repo, because the tests utilise a fallback if the env vars are not found in the default local file for dotnet user-secrets.

Implements a webhook verification method

This method held within the new UrlboxWebhookValidator class, verifies the header of the Urlbox webhook POST request x-urlbox-signature. It does this by following the instructions from the docs.

Updates the download() method to throw with the x-urlbox-error-message for more meaningful debugging

Implements fromCredentials static

This is a static method to create an instance of Urlbox via a static method over the new keyword.

Implements subtypes in the SyncUrlboxResponse type for metadata, metadataUrl, markdownUrl, mhtmlUrl, htmlUrl

This includes a further subtype in the metadata class for OgImage.

Rename GenerateUrlboxUrl() to GenerateRenderLink()

The update also makes signing with the user's secret key optional. Passing sign: true will sign the render link.

Rename Namespace from Screenshots to UrlboxSDK

Implement error exception

If one of the render methods fails, a UrlboxException will be thrown, which takes the error body from the Urlbox API and deserialises it into a meaningful exception object.

Nice To haves:

Some potential nice to haves that we could add either now or in future:

  • Validation of enumerable style values on init (EG engine_version to be only one of 'latest' or 'stable, pdf_page_size to be one of A0 A1 A2 A3 A4 A5 A6 Legal Letter Ledger Tabloid etc)
  • Test runner on push
  • Eventually upgrade to Dotnet 8.0 when LTS runs out, and take advantage of new features like the deserialisation policy for snake casing instead of a custom policy.
  • nuget upload on merge to main using gh runner

Tests:

The test project files Urlbox.MsTest.csproj and Urlbox.xUnitTest.csproj were updated to .NET core v6.

Additionally, the paths to the Urlbox class in the test .csproj files, which used '', were replaced with '/' for compatibility with macOs development.

Tests have been written for each resource to ensure getters work appropriately + when nullable. Tests have also been written for each new method, testing each case where success and failure occur. Tests have also been written for the trickier options, such as cookie/header.

The tests have been primarily written into the MsTest project.

Passing Tests:

Screenshot 2024-11-21 at 09 30 22

@AJCJ1 AJCJ1 requested a review from cjroebuck October 14, 2024 15:30
@AJCJ1 AJCJ1 linked an issue Oct 14, 2024 that may be closed by this pull request
@AJCJ1 AJCJ1 changed the title Migration of .io to .com WIP Migration of .io to .com + sync/async/webhook methods Oct 16, 2024
@AJCJ1 AJCJ1 changed the title WIP Migration of .io to .com + sync/async/webhook methods Migration of .io to .com + sync/async/webhook methods Oct 18, 2024
@AJCJ1 AJCJ1 changed the title Migration of .io to .com + sync/async/webhook methods WIP - Migration of .io to .com + sync/async/webhook methods Oct 18, 2024
AJCJ1 added 30 commits December 16, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migration of .io to .com + Missing webhook/sync/async methods
1 participant