public/Get-FixtureResult.ps1
function Get-FixtureResult { <# .SYNOPSIS Retrieves the predicted result of a fixture based on provided data. .EXAMPLE Get-FixtureResult -FixtureList $AllFuxtures -PredictionObject $Predictions .INPUTS - [Object] FixtureList - [Object] PredictionObject #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [Object]$FixtureList, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [Object]$Header, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [Object]$PredictionObject, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Token ) process{ $ErrorActionPreference = 'Stop' try { $NewObjects =@() $UnqiueObjects = $PredictionObject | Select-Object -Property fixture_id -Unique Write-Warning -Message "$($MyInvocation.MyCommand.Name): Professing fixture results. Unique prediction objects $($UnqiueObjects.Count)." foreach ($Object in $UnqiueObjects) { $Match = '' $Match = $FixtureList | Where-Object {$_.id -eq $($Object.Fixture_Id)} | Select-Object -First 1 Write-Warning -Message "Processing fixture result for $($Object.Fixture_Id)." if ($Match) { Write-Warning -Message "Processing fixture result for $($Match.Id) - $($Match.name)." $Uri = "https://api.sportmonks.com/v3/football/fixtures/$($Object.Fixture_Id)?api_token=$Token&include=scores" $Response = Invoke-RestMethod $Uri -Method 'GET' -Headers $Header $FixtureScore = $($Response.data) | Select-Object -ExpandProperty scores | Where-Object {$_.description -eq '2ND_HALF'} $HomeScore = ($($FixtureScore.score) | Where-Object {$_.participant -eq 'home'}).goals $AwayScore = ($($FixtureScore.score) | Where-Object {$_.participant -eq 'away'}).goals $NewObject = $Object.PSObject.Copy() $NewObject | Add-Member -MemberType NoteProperty -Name FixtureName -Value $($Match.name) $NewObject | Add-Member -MemberType NoteProperty -Name MatchResult -Value $($Match.result_info) $NewObject | Add-Member -MemberType NoteProperty -Name HomeScore -Value $HomeScore $NewObject | Add-Member -MemberType NoteProperty -Name AwayScore -Value $AwayScore $NewObject.psobject.properties.remove('TypeName') $NewObject.psobject.properties.remove('TypeId') $NewObjects += $NewObject } else { Write-Warning -Message "No match for fixture $($Object.Fixture_Id)." } # if } # foreach return $NewObjects } catch { "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # function |