From 594790f450a28b5a7887d758d0d46172b033d2bc Mon Sep 17 00:00:00 2001 From: codaamok Date: Sat, 23 Apr 2022 13:38:04 +0100 Subject: [PATCH 1/5] Support for Shlink 3.1.0 +semver:minor --- .vscode/tasks.json | 2 +- CHANGELOG.md | 5 +++++ README.md | 2 +- src/Private/GetShlinkConnection.ps1 | 2 +- src/Public/Get-ShlinkVisits.ps1 | 20 +++++++++++++++---- .../Get-ShlinkVisits.Acceptance.Tests.ps1 | 14 +++++++++++++ 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8b72a06..7719c26 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -69,7 +69,7 @@ "description": "Please enter Shlink API key", "id": "ShlinkAPIKey", "type": "promptString", - "default": "18c65bc9-e4fb-449d-b3e0-c6427cbac735", + "default": "b4791888-68ac-4e2e-bf12-5f202dd4dd36", "password": true, }, { diff --git a/CHANGELOG.md b/CHANGELOG.md index 5911c7c..0ce1e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `Get-ShlinkVisits` has a new parameter set to enable you to retrieve all visits for just domains. This supports the new `GET /domains/{domain}/visits` endpoint in 3.1.0. + +### Changed +- Minimum Shlink version updated 3.1.0 ## [0.9.4] - 2022-02-26 ### Added diff --git a/README.md b/README.md index ea233f3..13a8cf6 100644 --- a/README.md +++ b/README.md @@ -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 3.0.0 or newer +- Shlink 3.1.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 diff --git a/src/Private/GetShlinkConnection.ps1 b/src/Private/GetShlinkConnection.ps1 index da7cf78..2956681 100644 --- a/src/Private/GetShlinkConnection.ps1 +++ b/src/Private/GetShlinkConnection.ps1 @@ -24,7 +24,7 @@ function GetShlinkConnection { } } - $Script:MinSupportedShlinkVersion = [Version]"3.0.0" + $Script:MinSupportedShlinkVersion = [Version]"3.1.0" if (-not ("System.Web.HttpUtility" -as [Type])) { Add-Type -AssemblyName "System.Web" -ErrorAction "Stop" diff --git a/src/Public/Get-ShlinkVisits.ps1 b/src/Public/Get-ShlinkVisits.ps1 index b7af9fc..892aff1 100644 --- a/src/Public/Get-ShlinkVisits.ps1 +++ b/src/Public/Get-ShlinkVisits.ps1 @@ -54,18 +54,22 @@ function Get-ShlinkVisits { [Parameter(ParameterSetName="ShortCode")] [Parameter(ParameterSetName="Tag")] + [Parameter(Mandatory, ParameterSetName="Domain")] [String]$Domain, [Parameter(ParameterSetName="ShortCode")] [Parameter(ParameterSetName="Tag")] + [Parameter(ParameterSetName="Domain")] [datetime]$StartDate, [Parameter(ParameterSetName="ShortCode")] [Parameter(ParameterSetName="Tag")] + [Parameter(ParameterSetName="Domain")] [datetime]$EndDate, [Parameter(ParameterSetName="ShortCode")] [Parameter(ParameterSetName="Tag")] + [Parameter(ParameterSetName="Domain")] [Switch]$ExcludeBots, [Parameter()] @@ -92,14 +96,11 @@ function Get-ShlinkVisits { "Server" { $Params["Endpoint"] = "visits" } - "ShortCode|Tag" { + "ShortCode|Tag|Domain" { $Params["PropertyTree"] += "data" $Params["PSTypeName"] = "PSShlinkVisits" switch ($PSBoundParameters.Keys) { - "Domain" { - $QueryString.Add("domain", $Domain) - } "StartDate" { $QueryString.Add("startDate", (Get-Date $StartDate -Format "yyyy-MM-ddTHH:mm:sszzzz")) } @@ -113,9 +114,20 @@ function Get-ShlinkVisits { } "ShortCode" { $Params["Endpoint"] = "short-urls/{0}/visits" -f $ShortCode + + if ($PSBoundParameters.Keys -contains "Domain") { + $QueryString.Add("domain", $Domain) + } } "Tag" { $Params["Endpoint"] = "tags/{0}/visits" -f $Tag + + if ($PSBoundParameters.Keys -contains "Domain") { + $QueryString.Add("domain", $Domain) + } + } + "Domain" { + $Params["Endpoint"] = "domains/{0}/visits" -f $Domain } } diff --git a/tests/Public/Get-ShlinkVisits.Acceptance.Tests.ps1 b/tests/Public/Get-ShlinkVisits.Acceptance.Tests.ps1 index dc38735..cf8d22d 100644 --- a/tests/Public/Get-ShlinkVisits.Acceptance.Tests.ps1 +++ b/tests/Public/Get-ShlinkVisits.Acceptance.Tests.ps1 @@ -22,6 +22,20 @@ Describe "Get-ShlinkVisits" { [int]$Object.visitsCount | Should -BeOfType [int] } + It "Get visit data for a specific domain" { + $Params = @{ + Domain = 'psshlink.codaamok' + ShlinkServer = $env:ShlinkServer + ShlinkApiKey = $env:ShlinkAPIKey | ConvertTo-SecureString + ErrorACtion = 'Stop' + } + $Object = Get-ShlinkVisits @Params + $Count = $Object.count + Invoke-WebRequest 'http://psshlink.codaamok/PSShlink-Test' -ErrorAction 'Stop' + $Object = Get-ShlinkVisits @Params + $Object.Count | Should -Be ($Count + 1) + } + It "Get visit data for a specific shortcode" { $Params = @{ ShortCode = 'PSShlink-Test' From 8c0ea0b59497880cd1ead1ac7f21d391166f11d5 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 23 Apr 2022 12:40:15 +0000 Subject: [PATCH 2/5] Released 0.10.0 --- CHANGELOG.md | 5 ++++- docs/Get-ShlinkVisits.md | 24 +++++++++++++++++++++--- src/PSShlink.psd1 | 8 ++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce1e92..34d57a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.10.0] - 2022-04-23 ### Added - `Get-ShlinkVisits` has a new parameter set to enable you to retrieve all visits for just domains. This supports the new `GET /domains/{domain}/visits` endpoint in 3.1.0. @@ -131,7 +133,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release -[Unreleased]: https://github.com/codaamok/PSShlink/compare/0.9.4..HEAD +[Unreleased]: https://github.com/codaamok/PSShlink/compare/0.10.0..HEAD +[0.10.0]: https://github.com/codaamok/PSShlink/compare/0.9.4..0.10.0 [0.9.4]: https://github.com/codaamok/PSShlink/compare/0.9.1..0.9.4 [0.9.1]: https://github.com/codaamok/PSShlink/compare/0.9.0..0.9.1 [0.9.0]: https://github.com/codaamok/PSShlink/compare/0.8.2..0.9.0 diff --git a/docs/Get-ShlinkVisits.md b/docs/Get-ShlinkVisits.md index 0a19869..045c5a5 100644 --- a/docs/Get-ShlinkVisits.md +++ b/docs/Get-ShlinkVisits.md @@ -29,6 +29,12 @@ Get-ShlinkVisits -Tag [-Domain ] [-StartDate ] [-EndD [-ShlinkServer ] [-ShlinkApiKey ] [] ``` +### Domain +``` +Get-ShlinkVisits -Domain [-StartDate ] [-EndDate ] [-ExcludeBots] + [-ShlinkServer ] [-ShlinkApiKey ] [] +``` + ## DESCRIPTION Get details of visits for a Shlink server, short codes or tags. @@ -112,12 +118,24 @@ Accept pipeline input: False Accept wildcard characters: False ``` +```yaml +Type: String +Parameter Sets: Domain +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -StartDate A datetime object to filter the visit data where the start date is equal or greater than this value. ```yaml Type: DateTime -Parameter Sets: ShortCode, Tag +Parameter Sets: ShortCode, Tag, Domain Aliases: Required: False @@ -132,7 +150,7 @@ A datetime object to filter the visit data where its end date is equal or less t ```yaml Type: DateTime -Parameter Sets: ShortCode, Tag +Parameter Sets: ShortCode, Tag, Domain Aliases: Required: False @@ -147,7 +165,7 @@ Exclude visits from bots or crawlers. ```yaml Type: SwitchParameter -Parameter Sets: ShortCode, Tag +Parameter Sets: ShortCode, Tag, Domain Aliases: Required: False diff --git a/src/PSShlink.psd1 b/src/PSShlink.psd1 index 57713d6..bfa228c 100644 --- a/src/PSShlink.psd1 +++ b/src/PSShlink.psd1 @@ -3,7 +3,7 @@ # # Generated by: Adam Cook (@codaamok) # -# Generated on: 02/26/2022 +# Generated on: 04/23/2022 # @{ @@ -12,7 +12,7 @@ RootModule = 'PSShlink.psm1' # Version number of this module. -ModuleVersion = '0.9.4' +ModuleVersion = '0.10.0' # Supported PSEditions CompatiblePSEditions = 'Core', 'Desktop' @@ -108,9 +108,9 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = '# Added -- New parameter -PassThru added to function Save-ShlinkUrlQrCode which will return a System.IO.FileSystemInfo object for each QR code image file it creates when used. Default behaviour has not changed (return no object if successful). +- Get-ShlinkVisits has a new parameter set to enable you to retrieve all visits for just domains. This supports the new GET /domains/{domain}/visits endpoint in 3.1.0. # Changed -- Renamed parameter -Tags to be -Tag for function Remove-ShlinkTag' +- Minimum Shlink version updated 3.1.0' # Prerelease string of this module # Prerelease = '' From 4071850e4f380142b06a1671b99375f3afb0986d Mon Sep 17 00:00:00 2001 From: codaamok Date: Sat, 23 Apr 2022 13:44:04 +0100 Subject: [PATCH 3/5] Updated comment based help for Get-ShlinkVisits --- .vscode/tasks.json | 2 +- docs/Get-ShlinkVisits.md | 7 +++++++ src/Public/Get-ShlinkVisits.ps1 | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7719c26..6758ed5 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -23,7 +23,7 @@ "label": "Build (with docs)", "type": "process", "command": "pwsh", - "args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSShlink'","-UpdateDocs"], + "args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSShlink'","-UpdateDocs","$true"], "group": { "kind": "build", "isDefault": true diff --git a/docs/Get-ShlinkVisits.md b/docs/Get-ShlinkVisits.md index 045c5a5..968e07d 100644 --- a/docs/Get-ShlinkVisits.md +++ b/docs/Get-ShlinkVisits.md @@ -68,6 +68,13 @@ Get-ShlinkVisits -ShortCode "profile" -StartDate (Get-Date "2020-11-01") -EndDat Returns all visit data associated with the short code "profile" for the whole of November 2020 +### EXAMPLE 5 +``` +Get-ShlinkVisits -Domain "contoso.com" +``` + +Returns all visit data associated with the domain "contoso.com" + ## PARAMETERS ### -ShortCode diff --git a/src/Public/Get-ShlinkVisits.ps1 b/src/Public/Get-ShlinkVisits.ps1 index 892aff1..81868ca 100644 --- a/src/Public/Get-ShlinkVisits.ps1 +++ b/src/Public/Get-ShlinkVisits.ps1 @@ -39,6 +39,10 @@ function Get-ShlinkVisits { PS C:\> Get-ShlinkVisits -ShortCode "profile" -StartDate (Get-Date "2020-11-01") -EndDate (Get-Date "2020-12-01") Returns all visit data associated with the short code "profile" for the whole of November 2020 + .EXAMPLE + PS C:\> Get-ShlinkVisits -Domain "contoso.com" + + Returns all visit data associated with the domain "contoso.com" .INPUTS This function does not accept pipeline input. .OUTPUTS From 772cbe7de49392763eca39e195ae4df95c972196 Mon Sep 17 00:00:00 2001 From: codaamok Date: Sat, 23 Apr 2022 13:48:53 +0100 Subject: [PATCH 4/5] Updated CHANGELOG.md +semver: skip --- CHANGELOG.md | 2 ++ GitVersion.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34d57a2..61fb7df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Updated comment based help for `Get-ShlinkVisits` for new domain parameter set ## [0.10.0] - 2022-04-23 ### Added diff --git a/GitVersion.yml b/GitVersion.yml index a9bb3d1..9763f72 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -5,4 +5,4 @@ branches: regex: ^(hot)?fix(es)?[/-] ignore: sha: [] -merge-message-formats: {} +merge-message-formats: {} \ No newline at end of file From 3ecc156d1a4cb2dd277210c6f1d058a17b247758 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 23 Apr 2022 12:50:43 +0000 Subject: [PATCH 5/5] Released 0.10.2 --- CHANGELOG.md | 5 ++++- src/PSShlink.psd1 | 8 +++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61fb7df..374dab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.10.2] - 2022-04-23 ### Fixed - Updated comment based help for `Get-ShlinkVisits` for new domain parameter set @@ -135,7 +137,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release -[Unreleased]: https://github.com/codaamok/PSShlink/compare/0.10.0..HEAD +[Unreleased]: https://github.com/codaamok/PSShlink/compare/0.10.2..HEAD +[0.10.2]: https://github.com/codaamok/PSShlink/compare/0.10.0..0.10.2 [0.10.0]: https://github.com/codaamok/PSShlink/compare/0.9.4..0.10.0 [0.9.4]: https://github.com/codaamok/PSShlink/compare/0.9.1..0.9.4 [0.9.1]: https://github.com/codaamok/PSShlink/compare/0.9.0..0.9.1 diff --git a/src/PSShlink.psd1 b/src/PSShlink.psd1 index bfa228c..66feb98 100644 --- a/src/PSShlink.psd1 +++ b/src/PSShlink.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSShlink.psm1' # Version number of this module. -ModuleVersion = '0.10.0' +ModuleVersion = '0.10.2' # Supported PSEditions CompatiblePSEditions = 'Core', 'Desktop' @@ -107,10 +107,8 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '# Added -- Get-ShlinkVisits has a new parameter set to enable you to retrieve all visits for just domains. This supports the new GET /domains/{domain}/visits endpoint in 3.1.0. -# Changed -- Minimum Shlink version updated 3.1.0' + ReleaseNotes = '# Fixed +- Updated comment based help for Get-ShlinkVisits for new domain parameter set' # Prerelease string of this module # Prerelease = ''