NN.GameStats.psm1

#Region './Private/Get-MozambiqueHereAccessToken.ps1' 0
function Get-MozambiqueHereAccessToken {
    [CmdletBinding()]
    param (
        [string]$AccessTokenPath = "$env:USERPROFILE\.creds\MozambiqueHere\MozambiqueHereAccessToken.xml"
    )

    process {
        if (!(Test-Path $AccessTokenPath)) {
            New-MozambiqueHereAccessToken
        }
    
        Import-Clixml $AccessTokenPath | ConvertFrom-SecureString -AsPlainText
    }
}
#EndRegion './Private/Get-MozambiqueHereAccessToken.ps1' 15
#Region './Public/Invoke-MozambiqueHereBridgeRequest.ps1' 0
function Invoke-MozambiqueHereBridgeRequest {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory,ParameterSetName="Get user by UID")][string]$UID,
        [Parameter(Mandatory,ParameterSetName="Get user by name")][string]$player,
        [Parameter(Mandatory)][string][ValidateSet("PC","PS4","X1")]$Platform,
        [string]$ApiKey = $(Get-MozambiqueHereAccessToken)
    )
    
    process {
        $ParameterExclusion = @("ApiKey")
        $Body = $null
        $PSBoundParameters.Keys.ForEach({
            [string]$Key = ($_).ToLower()
            $Value = $PSBoundParameters.$key
        
            if ($ParameterExclusion -contains $Key) {
                return
            }
        
            $Body += @{
                $Key = $Value
            }
        })

        $Body += @{
            "auth" = $ApiKey
        }

        $splat = @{
            "Method" = "GET"
            "Uri" = "https://api.mozambiquehe.re/bridge"
            "Body" = $Body
        }

        #Write-Output $splat
        Invoke-RestMethod @splat
    }
}
#EndRegion './Public/Invoke-MozambiqueHereBridgeRequest.ps1' 40
#Region './Public/New-MozambiqueHereAccessToken.ps1' 0
function New-MozambiqueHereAccessToken {
    [CmdletBinding()]
    param (
        [string]$AccessTokenPath = "$env:USERPROFILE\.creds\MozambiqueHere\MozambiqueHereAccessToken.xml"
    )

    process {
        $ApiKey = Read-Host "Enter MozambiqueHere API key" -AsSecureString
    
        #Create parent folders of the access token file
        $AccessTokenDir = $AccessTokenPath.Substring(0, $AccessTokenPath.lastIndexOf('\'))
        if (!(Test-Path $AccessTokenDir)) {
            $null = New-Item -ItemType Directory $AccessTokenDir
        }

        #Create access token file
        $ApiKey | Export-Clixml $AccessTokenPath
    }
}
#EndRegion './Public/New-MozambiqueHereAccessToken.ps1' 20