public/Invoke-AutomatedSocialMediaPost.ps1

function Invoke-AutomatedSocialMediaPost {

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$BucketName,

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

        [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=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Date,

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

        [Parameter(Mandatory=$false)]
        [switch]$Post,

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

        [Parameter(Mandatory=$true)]
        [ValidateSet('facebook','instagram')]
        [string]$Platform,

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

    )
    process{

        $ErrorActionPreference = 'Stop'


        try {

            $Competions = Select-FootballCompetition -Continent $Continent
            $Competions.GetEnumerator() | ForEach-Object -Process {

                if ($Platform -eq 'facebook') {

                    $FBParams =@{
                        PageId = $PageId
                        Token  = $Token 
                        Competition = $($_.Key)
                        Date = $Date
                        Content = $Content
                        Path = $Path
                    }
                    
                    if ($Post) {

                        $FBParams.Add('post',$true)

                    } # if

                    Invoke-AutomatedFacebookPostWithPhoto @FBParams

                    Invoke-AutomatedFacebookStoryWithPhoto @FBParams

                } # if

                if ($Platform -eq 'instagram' -and $($PSBoundParameters.ContainsKey('BucketName'))) {

                    $InstaParams =@{
                        PageId = $PageId
                        Token  = $Token 
                        Competition = $($_.Key)
                        Date = $Date
                        Content = $Content
                        BucketName = $BucketName
                        Path = $Path
                    }

                    if ($Post) {

                        $InstaParams.Add('post',$true)

                    } # if
                    
                    Invoke-AutomatedInstagramSingleMediaPost @InstaParams

                    Invoke-AutomatedInstagramSingleMediaStoryPost @InstaParams

                } # if


            } # foreach-object

        }
        catch {

             throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch

    } # process

} # function