NN.Smarthome.psm1
#Region './Private/Get-FfailAccessToken.ps1' 0 function Get-FfailAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\Ffail\ffailAccessToken.xml" ) if (!(Test-Path $accessTokenPath)) { New-FfailAccessToken } Import-Clixml $accessTokenPath | ConvertFrom-SecureString -AsPlainText } #EndRegion './Private/Get-FfailAccessToken.ps1' 12 #Region './Public/Get-EnergyPrice.ps1' 0 function Get-EnergyPrice { param ( [Parameter(Mandatory)][string]$Zone, [Parameter(Mandatory)][datetime]$Date, [switch]$test ) if ($test) { $uri = "https://playground-norway-power.ffail.win/" $key = "123" } else { $uri = "https://norway-power.ffail.win/" $key = Get-FfailAccessToken } $convertedDate = Get-Date $Date -Format "yyyy-MM-dd" $splat = @{ "Method" = "GET" "Uri" = $uri "Body" = @{ "zone" = $Zone "date" = $convertedDate "key" = $key } } Invoke-RestMethod @splat } #EndRegion './Public/Get-EnergyPrice.ps1' 28 #Region './Public/New-FfailAccessToken.ps1' 0 function New-FfailAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\FFail\ffailAccessToken.xml" ) Write-Information -MessageData "Please send an email to `"power@ffail.win`" to get a free API key." -InformationAction "Continue" $apiKey = Read-Host "Enter Ffail 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-FfailAccessToken.ps1' 18 |