public/Set-ActionState.ps1
function Set-ActionState { <# .EXAMPLE Set-ActionState -Action post-facebook -Continent north-america -Enabled true -Date 2025-04-17 -Path C:\sportsmonk #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateSet('get-predictions','get-results','post-facebook','post-instagram','populate-templates')] [string]$Action, [Parameter(Mandatory=$true)] [ValidateSet('australia','europe','europe-uk','europe-uk-cup','europe-uk-fl','europe-uk-wsl','south-america','north-america','asia')] [string]$Continent, [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [string]$Date, [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [string]$DateRange, [Parameter(Mandatory=$true)] [ValidateSet('false','true')] [string]$Enabled, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path ) process{ $ErrorActionPreference = 'Stop' try { switch ($Action) { 'get-predictions' { $FileToUse = 'predictions.json' } 'get-results' { $FileToUse = 'results.json' } 'post-facebook' { $FileToUse = 'facebook.json' } 'post-instagram' { $FileToUse = 'instagram.json' } 'populate-templates' { $FileToUse = 'templates.json' } } # switcg $Configs = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\$FileToUse" -ErrorAction Stop | ConvertFrom-Json foreach ($Config in $Configs) { $ConfigToChange = $Config | Where-Object {$_.Continent -eq $Continent} if ($Action -like 'get-*' -and $ConfigToChange) { $DateSplit = $DateRange.Split('-') $Year = $DateSplit[0] $Month = $DateSplit[1] $DaysToRun = $DateSplit[-1] $ConfigToChange.Enabled = $Enabled $ConfigToChange.DateRange = $DateRange $ConfigToChange.DateMonth = $Month $ConfigToChange.DateYear = $Year $ConfigToChange.DaysToRun = $DaysToRun $ConfigToChange } elseif ($Action -notlike 'get-*' -and $ConfigToChange) { $ConfigToChange.Enabled = $Enabled $ConfigToChange.Date = $Date $ConfigToChange } else { Write-Warning -Message 'conifg not found' } # if } # foreach $JSON = $Configs | ConvertTo-Json Set-Content -Value $JSON -Path "$Path\git-hub\sportsmonk-api\function-parameters\$FileToUse" -ErrorAction Stop } catch { "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # function |