Skip to content

Commit

Permalink
Merge branch 'master' into 66-get-steamfriendlist-should-return-a-pso…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
hjorslev authored Apr 9, 2024
2 parents 0568864 + d36d858 commit ea36155
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ for server information and more.
| Cmdlet | Description |
| -------------------------------------------------------- | ------------------------------------------------------------------- |
| [Connect-SteamAPI](docs/Connect-SteamAPI.md) | Create or update the Steam Web API config file. |
| [Disconnect-SteamAPI](docs/Disconnect-SteamAPI.md) | Disconnects from the Steam API by removing the stored API key. |
| [Find-SteamAppID](docs/Find-SteamAppID.md) | Find a Steam AppID by searching the name of the application. |
| [Get-SteamFriendList](docs/Get-SteamFriendList.md) | Returns the friend list of any Steam user. |
| [Get-SteamNews](docs/Get-SteamNews.md) | Returns the latest news of a game specified by its AppID. |
Expand Down Expand Up @@ -159,4 +160,4 @@ Please see the wiki for further information: [Update Steam server automatically]

## Acknowledgements

Joystick icon by Delapouite. Available at [game-icons.net](https://game-icons.net/1x1/delapouite/joystick.html).
Joystick icon by Delapouite. Available at [game-icons.net](https://game-icons.net/1x1/delapouite/joystick.html).
62 changes: 62 additions & 0 deletions SteamPS/Public/API/Disconnect-SteamAPI.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Disconnect-SteamAPI {
<#
.SYNOPSIS
Disconnects from the Steam API by removing the stored API key.
.DESCRIPTION
The Disconnect-SteamAPI cmdlet removes the stored Steam API key from the system. This effectively disconnects the current session from the Steam API.
.PARAMETER Force
When the Force switch is used, the cmdlet will skip the confirmation prompt and directly remove the API key.
.EXAMPLE
Disconnect-SteamAPI -Force
This command will remove the stored Steam API key without asking for confirmation.
.INPUTS
None. You cannot pipe objects to Disconnect-SteamAPI.
.OUTPUTS
None. Nothing is returned when calling Disconnect-SteamAPI.
.NOTES
Author: Frederik Hjorslev Nylander
.LINK
https://hjorslev.github.io/SteamPS/Disconnect-SteamAPI.html
#>

[CmdletBinding()]
param (
[Parameter(Mandatory = $false,
HelpMessage = 'Skip the confirmation prompt.')][switch]$Force
)

begin {
Write-Verbose -Message "[BEGIN ] Starting: $($MyInvocation.MyCommand)"
$SteamAPIKey = "$env:AppData\SteamPS\SteamPSKey.json"
}

process {
if ($Force -or $PSCmdlet.ShouldContinue($SteamAPIKey, 'Do you want to continue removing the API key?')) {
if (Test-Path -Path $SteamAPIKey) {
Remove-Item -Path $SteamAPIKey -Force
Write-Verbose -Message "$SteamAPIKey were deleted."
} else {
$Exception = [Exception]::new("Steam Web API configuration file not found in '$env:AppData\SteamPS\SteamPSKey.json'.")
$ErrorRecord = [System.Management.Automation.ErrorRecord]::new(
$Exception,
'SteamAPIKeyNotFound',
[System.Management.Automation.ErrorCategory]::ObjectNotFound,
$SteamPSKey
)
$PSCmdlet.ThrowTerminatingError($ErrorRecord)
}
}
}

end {
Write-Verbose -Message "[END ] Ending: $($MyInvocation.MyCommand)"
}
}
11 changes: 11 additions & 0 deletions Tests/Unit/Public/Disconnect-SteamAPI.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Describe 'Disconnect-SteamAPI Tests' {
Context 'When Force is specified and API key is found' {
BeforeAll {
Mock -CommandName Test-Path -ModuleName SteamPS -MockWith { return $true } -Verifiable -ParameterFilter { $Path -eq "$env:AppData\SteamPS\SteamPSKey.json" }
Mock -CommandName Remove-Item -ModuleName SteamPS -MockWith {} -Verifiable -ParameterFilter { $Path -eq "$env:AppData\SteamPS\SteamPSKey.json" }
}
It 'Deletes the Steam API key file' {
Disconnect-SteamAPI -Force | Should -InvokeVerifiable
}
}
}
79 changes: 79 additions & 0 deletions docs/Disconnect-SteamAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
external help file: SteamPS-help.xml
Module Name: SteamPS
online version: https://hjorslev.github.io/SteamPS/Disconnect-SteamAPI.html
schema: 2.0.0
---

# Disconnect-SteamAPI

## SYNOPSIS
Disconnects from the Steam API by removing the stored API key.

## SYNTAX

```
Disconnect-SteamAPI [-Force] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

## DESCRIPTION
The Disconnect-SteamAPI cmdlet removes the stored Steam API key from the system.
This effectively disconnects the current session from the Steam API.

## EXAMPLES

### EXAMPLE 1
```
Disconnect-SteamAPI -Force
```

This command will remove the stored Steam API key without asking for confirmation.

## PARAMETERS

### -Force
When the Force switch is used, the cmdlet will skip the confirmation prompt and directly remove the API key.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### None. You cannot pipe objects to Disconnect-SteamAPI.
## OUTPUTS
### None. Nothing is returned when calling Disconnect-SteamAPI.
## NOTES
Author: Frederik Hjorslev Nylander
## RELATED LINKS
[https://hjorslev.github.io/SteamPS/Disconnect-SteamAPI.html](https://hjorslev.github.io/SteamPS/Disconnect-SteamAPI.html)

0 comments on commit ea36155

Please sign in to comment.