Skip to content

Commit

Permalink
Support for Shlink 3.1.0 +semver:minor
Browse files Browse the repository at this point in the history
  • Loading branch information
codaamok committed Apr 23, 2022
1 parent 0508c9c commit 594790f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 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
Expand Down
2 changes: 1 addition & 1 deletion src/Private/GetShlinkConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 16 additions & 4 deletions src/Public/Get-ShlinkVisits.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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"))
}
Expand All @@ -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
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Public/Get-ShlinkVisits.Acceptance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 594790f

Please sign in to comment.