public/Invoke-SportsmonkAutomation.ps1

function Invoke-SportsmonkAutomation {
    <#
        .EXAMPLE
            Invoke-SportsmonkAutomation -Header $HeaderObject -Token $Token -SMToken $AccessToken -Action get-predictions -Path C:\sportsmonk
 
        .EXAMPLE
            Invoke-SportsmonkAutomation -Header $HeaderObject -Token $Token -SMToken $AccessToken -Action get-results -Path C:\sportsmonk
 
        .EXAMPLE
            Invoke-SportsmonkAutomation -Header $HeaderObject -Token $Token -SMToken $AccessToken -Action populate-templates -Path C:\sportsmonk
 
        .EXAMPLE
            Invoke-SportsmonkAutomation -Header $HeaderObject -Token $Token -SMToken $AccessToken -Action post-facebook -Content outcomes -Path C:\sportsmonk
     
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateSet('get-predictions','get-results','post-facebook','post-instagram','populate-templates')]
        [string]$Action,

        [Parameter(Mandatory=$false)]
        [ValidateSet('corners','goals','match','outcomes')]
        [string]$Content,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [Object]$Header,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$SMToken

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            if ($Action -eq 'get-predictions' -or $Action -eq 'get-results') {

                switch ($Action) {

                    'get-predictions' {

                        $ParamObjects = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\predictions.json" | ConvertFrom-Json

                    }
                    'get-results' {

                        $ParamObjects = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\results.json" | ConvertFrom-Json
                        
                    }
                    
                } # switch

                foreach ($ParamObject in $ParamObjects) {
                    
                    $FixtureParams = @{}

                    foreach ($Property in $ParamObject.psobject.Properties.Name) {

                        $FixtureParams[$Property] = $ParamObject.$Property

                    } # foreach

                    Invoke-FootballCompetitionFixtureAutomation @FixtureParams -Header $Header -Token $Token -Path $Path

                } # foreach

            } # if

            if ($Action -eq 'populate-templates') {

                    $ParamObjects = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\templates.json" | ConvertFrom-Json

                    foreach ($ParamObject in $ParamObjects) {

                        $TemplateParams = @{}

                        foreach ($Property in $ParamObject.psobject.Properties.Name) {

                            $TemplateParams[$Property] = $ParamObject.$Property

                        } # foreach

                        Invoke-PopulateFootballCompetitionTemplateAutomation @TemplateParams -Header $Header -Token $Token -Path $Path

                    } # foreach

            } # if

            if ($Action -eq 'post-facebook' -or $Action -eq 'post-instagram') {

                switch ($Action) {

                    'post-facebook' {

                        $ParamObjects = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\facebook.json" | ConvertFrom-Json
                        $ContentToPost =@('match','goals','corners','outcomes')

                    }
                    'post-instagram' {

                        $ParamObjects = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\instagram.json" | ConvertFrom-Json
                        $ContentToPost =@('match','goals','corners','outcomes')
                        
                    }

                } # switch

                if ($($PSBoundParameters.ContainsKey('Content'))) {

                    $ContentToPost =@($Content)

                } # if

                foreach ($ParamObject in $ParamObjects) {

                    $SocialMediaParams = @{}

                    foreach ($Property in $ParamObject.psobject.Properties.Name) {

                        $SocialMediaParams[$Property] = $ParamObject.$Property

                    } # foreach

                    foreach ($Content in $ContentToPost) {

                        Invoke-AutomatedSocialMediaPost @SocialMediaParams -Token $SMToken -Content $Content -Post -Path $Path

                    } # foreach

                } # foreach

            } # if

        }
        catch {

            "$($MyInvocation.MyCommand.Name): $_.Exception.Message"
 
         } # trycatch

    } # process

} # function