Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
codaamok committed Mar 2, 2023
2 parents bb67b9e + 3ecc156 commit 42fd2cf
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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","$true"],
"args": ["-noprofile","-command","Invoke-Build","-File","./invoke.build.ps1","-Author","'codaamok'","-ModuleName","'PSShlink'","-UpdateDocs","$true","$true"],
"group": {
"kind": "build",
"isDefault": true
Expand Down Expand Up @@ -88,7 +88,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
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Deprecation warning added to `New-ShlinkUrl` for `-ValidateUrl`, which is true since Shlink 3.5.0
- Changed API permission to 3, from 2

## [0.10.2] - 2022-04-23
### Fixed
- Updated comment based help for `Get-ShlinkVisits` for new domain parameter set

## [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.

### Changed
- Minimum Shlink version updated 3.1.0

## [0.9.4] - 2022-02-26
### 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).
Expand Down Expand Up @@ -136,7 +147,9 @@ 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.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
[0.9.0]: https://github.com/codaamok/PSShlink/compare/0.8.2..0.9.0
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ branches:
regex: ^(hot)?fix(es)?[/-]
ignore:
sha: []
merge-message-formats: {}
merge-message-formats: {}
31 changes: 28 additions & 3 deletions docs/Get-ShlinkVisits.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Get-ShlinkVisits -Tag <String> [-Domain <String>] [-StartDate <DateTime>] [-EndD
[-ShlinkServer <String>] [-ShlinkApiKey <SecureString>] [<CommonParameters>]
```

### Domain
```
Get-ShlinkVisits -Domain <String> [-StartDate <DateTime>] [-EndDate <DateTime>] [-ExcludeBots]
[-ShlinkServer <String>] [-ShlinkApiKey <SecureString>] [<CommonParameters>]
```

## DESCRIPTION
Get details of visits for a Shlink server, short codes or tags.

Expand Down Expand Up @@ -62,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
Expand Down Expand Up @@ -112,12 +125,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
Expand All @@ -132,7 +157,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
Expand All @@ -147,7 +172,7 @@ Exclude visits from bots or crawlers.

```yaml
Type: SwitchParameter
Parameter Sets: ShortCode, Tag
Parameter Sets: ShortCode, Tag, Domain
Aliases:

Required: False
Expand Down
10 changes: 4 additions & 6 deletions src/PSShlink.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Adam Cook (@codaamok)
#
# Generated on: 02/26/2022
# Generated on: 04/23/2022
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSShlink.psm1'

# Version number of this module.
ModuleVersion = '0.9.4'
ModuleVersion = '0.10.2'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -107,10 +107,8 @@ PrivateData = @{
# IconUri = ''

# 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).
# Changed
- Renamed parameter -Tags to be -Tag for function Remove-ShlinkTag'
ReleaseNotes = '# Fixed
- Updated comment based help for Get-ShlinkVisits for new domain parameter set'

# Prerelease string of this module
# Prerelease = ''
Expand Down
24 changes: 20 additions & 4 deletions src/Public/Get-ShlinkVisits.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,18 +58,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 +100,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 +118,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 42fd2cf

Please sign in to comment.