Skip to content

Commit

Permalink
Rename demo to WoW + fixes (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Feb 28, 2024
1 parent 98cdcac commit 1f28730
Show file tree
Hide file tree
Showing 118 changed files with 902 additions and 1,719 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Process-PSModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@main
secrets: inherit
with:
Name: WoWManager
Name: WoW
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- For any bug fix.
- For any bugfix.

### Security

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Demo

Demo repo for actions
Demo repository for a PSModule
13 changes: 13 additions & 0 deletions src/WoW/WoW.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@{
ModuleVersion = '0.0.1'
Description = 'This module is for working with settings and addons in WoW with PowerShell'
PrivateData = @{
PSData = @{
Tags = 'WoW', 'retail', 'Games', 'Multiboxing'
LicenseUri = 'https://dev.azure.com/PSModule/WoW/'
ProjectUri = 'https://dev.azure.com/PSModule/WoW/'
IconUri = 'https://dev.azure.com/PSModule/WoW/icons/icon.png'
}
}
}

File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/WoW/attributes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains long links.')]
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Requires -Version 6.0
#Requires -Modules PATH, Fonts
$ClassMap = @(
$script:ClassMap = @(
[PSCustomObject]@{
ClassID = 1
ClassName = 'Warrior'
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions src/WoW/private/Account/Export-WoWAccount.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Function Export-WoWAccount {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
An example
.NOTES
General notes
#>
Get-WoWAccount | ConvertTo-Json -EnumsAsStrings | Out-File -FilePath "$Script:WoW_Folder_Cache\Accounts.json" -Force
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
Function Import-WoWAccounts {
Function Import-WoWAccount {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
An example
.NOTES
General notes
#>
$CacheFilePath = "$Script:WoW_Folder_Cache\Accounts.json"
if (Test-Path $CacheFilePath) {
$ImportedAccounts = Get-Content $CacheFilePath | ConvertFrom-Json
Expand All @@ -7,6 +20,6 @@ Function Import-WoWAccounts {
$Account.IsMain = $ImportedAccount.IsMain
}
} else {
Write-WoWVerbose 'Import-WoWAccounts: Nothing to import'
Write-WoWVerbose 'Import-WoWAccount: Nothing to import'
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
Function Initialize-WoWAccounts {
Function Initialize-WoWAccount {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER WoWAccountsFolderPath
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
[OutputType([Account[]])]
Param(
Expand All @@ -7,7 +23,8 @@ Function Initialize-WoWAccounts {
[Account[]]$Accounts = $null

Write-WoWVerbose 'Accounts: Finding'
$AccountFolders = $WoWAccountsFolderPath | Get-ChildItem -Directory | Where-Object Name -NE SavedVariables | Select-Object Name, FullName | Sort-Object name
$AccountFolders = $WoWAccountsFolderPath | Get-ChildItem -Directory | Where-Object Name -NE SavedVariables |
Select-Object Name, FullName | Sort-Object name
Write-WoWVerbose "Accounts: Found $($AccountFolders.count)"

Write-WoWVerbose 'Accounts: Processing'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
Function Initialize-WoWAddon {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER WoWAddonsFolderPath
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
[OutputType([Addon[]])]
Param(
Expand Down
21 changes: 21 additions & 0 deletions src/WoW/private/BNetAPI/Export-BNetAPISetting.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Function Export-BNetAPISetting {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
param()
Write-WoWVerbose 'Export-BNetAPISetting: Export: Start'
Get-BNetAPIRegion | Select-Object Region | ConvertTo-Json -EnumsAsStrings |
Out-File -FilePath "$Script:WoW_Folder_Cache\BNetAPISettings.json" -Force
Write-WoWVerbose 'Export-BNetAPISetting: Export: Done'
}
46 changes: 46 additions & 0 deletions src/WoW/private/BNetAPI/Get-BNetAPIUserAccessToken.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

Function Get-BNetAPIUserAccessToken {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER Token
Parameter description
.PARAMETER Region
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
param(
$Token = $Script:BNetAPI_AccessToken,
$Region = $Script:BNetAPI_Settings.Region
)
$Body = @{
':region' = $Region
token = $Token
}

try {
$params = @{
Method = 'Post'
Uri = "$($Script:BNetAPI_Settings.BNetAPIPath)oauth/check_token"
Body = $Body
ContentType = 'application/x-www-form-urlencoded'
ErrorAction = 'Stop'
}

$Response = Invoke-RestMethod @params
} catch {
throw $_
}
return $Response
}
39 changes: 39 additions & 0 deletions src/WoW/private/BNetAPI/Get-BNetAPIUserInfo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Function Get-BNetAPIUserInfo {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER Token
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
param(
$Token = $Script:BNetAPI_AccessToken
)
$Headers = @{
Authorization = "Bearer $Token"
}

try {
$params = @{
Method = 'Get'
Uri = "$($Script:BNetAPI_Settings.BNetAPIPath)oauth/userinfo"
Headers = $Headers
ContentType = 'application/x-www-form-urlencoded'
ErrorAction = 'Stop'
}
$Response = Invoke-RestMethod @params
} catch {
throw $_
}
return $Response
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
Function Get-BNetAPIWoWRealms {
Function Get-BNetAPIWoWRealm {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
param()
Write-WoWVerbose 'Get-BNetAPIWoWRealms: Finding'
Write-WoWVerbose 'Get-BNetAPIWoWRealm: Finding'
[Realm[]]$Realms = $null

$Headers = @{
Expand All @@ -13,7 +26,12 @@ Function Get-BNetAPIWoWRealms {

$RawRealmIndex = Invoke-RestMethod -Method Get -Uri "$($APIURI)data/wow/realm/index?locale=$($Locale)" -Headers $Headers
$RawRealmIndex.realms | ForEach-Object -ThrottleLimit 50 -Parallel {
Invoke-RestMethod -Method Get -Uri "$using:APIURI/data/wow/realm/$($_.id)?namespace=dynamic-eu&locale=$using:Locale" -Headers $using:Headers
$params = @{
Method = 'Get'
Uri = "$using:APIURI/data/wow/realm/$($_.id)?namespace=dynamic-eu&locale=$using:Locale"
Headers = $using:Headers
}
Invoke-RestMethod @params
} | ForEach-Object {
$Realms += [Realm]::new(
$_.id,
Expand Down
27 changes: 27 additions & 0 deletions src/WoW/private/BNetAPI/Import-BNetAPISetting.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Function Import-BNetAPISetting {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
An example
.NOTES
General notes
#>
[CmdletBinding()]
param()
Write-WoWVerbose 'Import-BNetAPISetting: Import: Start'
$CacheFilePath = "$Script:WoW_Folder_Cache\BNetAPISettings.json"
if (Test-Path $CacheFilePath) {
$ImportedBNetAPISettings = Get-Content $CacheFilePath | ConvertFrom-Json
Write-WoWVerbose "Import-BNetAPISetting: Import: Setting region to $($ImportedBNetAPISettings.Region)"
Set-BNetAPIRegion -Region $ImportedBNetAPISettings.Region
Write-WoWVerbose 'Import-BNetAPISetting: Import: Done'
} else {
Write-WoWVerbose 'Import-BNetAPISetting: Import: Nothing to import'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ $Script:BNetAPI_RegionSettings = @(
}
)

$Script:BNetAPI_ClientID = '206367cb92d2430ab5d0f06d9e6ccbe6'
$Script:BNetAPI_ClientSecret = 'N2CeXceHwUIaJcBLMai3x8s65UTWRXW3'
$Script:BNetAPI_ClientID = '<get from secret vault>'
$Script:BNetAPI_ClientSecret = '<get from secret vault>'
$Script:BNetAPI_Settings = $Script:BNetAPI_RegionSettings[2]
52 changes: 52 additions & 0 deletions src/WoW/private/BNetAPI/New-BNetAPIUserAccessToken.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

#https://develop.battle.net/documentation/guides/using-oauth/client-credentials-flow
Function New-BNetAPIUserAccessToken {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER ClientID
Parameter description
.PARAMETER ClientSecret
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
Justification = 'Not changing state, just an object in memory.'
)]
[CmdletBinding()]
param(
$ClientID = $Script:BNetAPI_ClientID,
$ClientSecret = $Script:BNetAPI_ClientSecret
)
$Body = @{
client_id = $ClientID
client_secret = $ClientSecret
grant_type = 'client_credentials'
scope = ''
}

try {
$params = @{
Method = 'Post'
Uri = "$($Script:BNetAPI_Settings.BNetAPIPath)oauth/token"
Body = $Body
ContentType = 'application/x-www-form-urlencoded'
ErrorAction = 'Stop'
}
$Response = Invoke-RestMethod @params
} catch {
throw $_
}
return $Response.access_token
}
16 changes: 16 additions & 0 deletions src/WoW/private/Character/Export-WoWCharacter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Function Export-WoWCharacter {
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.EXAMPLE
An example
.NOTES
General notes
#>
Get-WoWCharacter | ConvertTo-Json -EnumsAsStrings | Out-File -FilePath "$Script:WoW_Folder_Cache\Characters.json" -Force
}
Loading

0 comments on commit 1f28730

Please sign in to comment.