Skip to content

Commit

Permalink
Added forwardQuery parameter support, increase minimum Shlink verison…
Browse files Browse the repository at this point in the history
…, and changed some parameter types +semver:minor
  • Loading branch information
codaamok committed Nov 20, 2021
1 parent 6ca2b21 commit 52f966e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Improved build pipeline to use [codaamok.build](https://github.com/codaamok/codaamok.build)
- New `-ForwardQuery` boolean parameter in `New-ShlinkUrl` and `Set-ShlinkUrl` (new in Shlink 2.9.0).

### Changed
- Minimum Shlink version updated to 2.9.0
- Renamed parameter `-DoNotValidateUrl` of switch type to `-ValidateUrl` of boolean type for both `New-ShlinkUrl` and `Set-ShlinkUrl`.
- Parameter `-FindIfExists` is now of type boolean instead of switch in `New-ShlinkUrl`. is now a switch and not a boolean`.
- Removed use of methods `SecureStringToBSTR` and `PtrToStringAuto` from Marshal .NET class for secure string handling in `InvokeShlinkRestMethod`, in favour of using `GetNetworkCredential` method from a PSCredential object.
- `Save-ShlinkUrlQrCode` no longer has hardcoded default parameter values (much like the API did) for size, margin, format, and error correction level.. Shlink 2.9.0 now lets you configure these defaults for QR codes, so by omitting values for these params, your server default values are used.

Expand Down
24 changes: 17 additions & 7 deletions PSShlink/Public/New-ShlinkUrl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ function New-ShlinkUrl {
Set the length of your new short code other than the default.
.PARAMETER FindIfExists
Specify this switch to first search and return the data about an existing short code that uses the same long URL if one exists.
.PARAMETER DoNotValidateUrl
Disables long URL validation while creating the short code.
.PARAMETER ValidateUrl
Control long URL validation while creating the short code.
.PARAMETER ForwardQuery
Forwards UTM query parameters to the long URL if any were passed to the short URL.
.PARAMETER Crawlable
Set short URLs as crawlable, making them be listed in the robots.txt as Allowed.
.PARAMETER ShlinkServer
Expand Down Expand Up @@ -78,10 +80,13 @@ function New-ShlinkUrl {
[Int]$ShortCodeLength,

[Parameter()]
[Switch]$FindIfExists,
[Bool]$FindIfExists,

[Parameter()]
[Switch]$DoNotValidateUrl,
[Bool]$ValidateUrl,

[Parameter()]
[Bool]$ForwardQuery,

[Parameter()]
[Bool]$Crawlable,
Expand All @@ -104,8 +109,7 @@ function New-ShlinkUrl {
Endpoint = "short-urls"
Method = "POST"
Body = @{
longUrl = $LongUrl
validateUrl = -not $DoNotValidateUrl.IsPresent
longUrl = $LongUrl
}
ErrorAction = "Stop"
}
Expand Down Expand Up @@ -136,7 +140,13 @@ function New-ShlinkUrl {
$Params["Body"]["shortCodeLength"] = $ShortCodeLength
}
"FindIfExists" {
$Params["Body"]["findIfExists"] = "true"
$Params["Body"]["findIfExists"] = $FindIfExists
}
"ValidateUrl" {
$Params["Body"]["validateUrl"] = $ValidateUrl
}
"ForwardQuery" {
$Params["Body"]["forwardQuery"] = $ForwardQuery
}
"Crawlable" {
$Params["Body"]["crawlable"] = $Crawlable
Expand Down
14 changes: 11 additions & 3 deletions PSShlink/Public/Set-ShlinkUrl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function Set-ShlinkUrl {
Define a title with the new short code.
.PARAMETER DoNotValidateUrl
Disables long URL validation while creating the short code.
.PARAMETER ForwardQuery
Forwards UTM query parameters to the long URL if any were passed to the short URL.
.PARAMETER Crawlable
Set short URLs as crawlable, making them be listed in the robots.txt as Allowed.
.PARAMETER ShlinkServer
Expand Down Expand Up @@ -78,7 +80,10 @@ function Set-ShlinkUrl {
[String]$Domain,

[Parameter()]
[Switch]$DoNotValidateUrl,
[Bool]$ValidateUrl,

[Parameter()]
[Bool]$ForwardQuery,

[Parameter()]
[Bool]$Crawlable,
Expand Down Expand Up @@ -137,8 +142,11 @@ function Set-ShlinkUrl {
$QueryString.Add("domain", $Domain)
}
}
"DoNotValidateUrl" {
$Params["Body"]["validateUrl"] = -not $DoNotValidateUrl.IsPresent
"ValidateUrl" {
$Params["Body"]["validateUrl"] = $ValidateUrl
}
"ForwardQuery" {
$Params["Body"]["forwardQuery"] = $ForwardQuery
}
"Crawlable" {
$Params["Body"]["crawlable"] = $Crawlable
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ An unofficial PowerShell module for Shlink (https://shlink.io), an open-source s
## Requirements

- PowerShell 5.1 or newer (including PowerShell Core, 7.0 or newer)
- Shlink 2.8.0 or newer
- Shlink 2.9.0 or newer
- If you need support for older versions of Shlink, you can still source older versions of PSShlink [here](https://github.com/codaamok/PSShlink/releases) or use the `-RequiredVersion` parameter of `Install-Module` when installed from the PowerShell Gallery

## Getting started
Expand Down

0 comments on commit 52f966e

Please sign in to comment.