functions/Get/Get-ZipFromGithub.ps1

function Get-ZipFromGithub {

    Param(
        [Parameter(Mandatory = $false)]
        [string]$Owner = 'lineupsystems',
        [Parameter(Mandatory = $true)]
        [string]$Repository,
        [Parameter(Mandatory = $false)]
        [string]$OutFile,
        [Parameter(Mandatory = $false)]
        [string]$Ref
    )

    begin { 
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

        $baseUri = "https://api.github.com";

        $headers = Get-GithubHeaders

        # If Ref is not passed then load it from customer config
        $Ref = Get-DefaultBranch -Ref $Ref
    }
    process {
        $argsUri = "repos/$Owner/$Repository/zipball/$Ref"

        if ($PSBoundParameters.ContainsKey('OutFile')) {
            $targetDir = Split-Path $OutFile
            if (-not (Test-Path $targetDir)) {
                New-Item -Path $targetDir -ItemType Directory -ErrorAction Stop | Out-Null
            }

            Invoke-WebRequest -Uri "$baseUri/$argsUri" -Headers $headers -OutFile $OutFile -ErrorAction Stop
        }
        else { 
            Invoke-WebRequest -Uri "$baseUri/$argsUri" -Headers $headers -ErrorAction Stop | Select-Object -Expand Content
        }
    }
}