Private/OAuth/Request-RedditOAuthTokenInstalled.ps1

<#
    .NOTES
    
     Created with: VSCode
     Created on: 5/05/2017 11:27 AM
     Edited on: 5/14/2017
     Created by: Mark Kraus
     Organization:
     Filename: Request-RedditOAuthTokenInstalled.ps1
    
    .DESCRIPTION
        Request-RedditOAuthTokenInstalled Function
#>

[CmdletBinding()]
param()

function Request-RedditOAuthTokenInstalled {
    [CmdletBinding(
        HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled'
    )]
    [OutputType([RedditOAuthResponse])]
    param (
        [Parameter( 
            mandatory = $true, 
            ValueFromPipeline = $true, 
            ValueFromPipelineByPropertyName = $true
        )]
        [RedditApplication]$Application,

        [Parameter( 
            mandatory = $false, 
            ValueFromPipeline = $false, 
            ValueFromPipelineByPropertyName = $true
        )]
        [String]$DeviceID = [guid]::NewGuid().tostring(),

        [Parameter( 
            mandatory = $false, 
            ValueFromPipeline = $false, 
            ValueFromPipelineByPropertyName = $false
        )]
        [String]$AuthBaseUrl = [RedditOAuthToken]::AuthBaseURL
    )
    process {
        $Params = @{
            Uri             = $AuthBaseUrl
            Body            = @{
                grant_type = 'https://oauth.reddit.com/grants/installed_client'
                device_id  = $DeviceID
            }
            UserAgent       = $Application.UserAgent
            Headers         = @{
                Authorization = $Application.ClientCredential | Get-AuthorizationHeader 
            }
            Method          = 'POST'
            UseBasicParsing = $true
        }
        $Response = Invoke-WebRequest @Params
        $Null = $Params.Remove('Headers')
        [RedditOAuthResponse]@{
            Response    = $Response
            RequestDate = $Response.Headers.Date[0]
            Parameters  = $Params
            Content     = $Response.Content
            ContentType = $Response | Get-HttpResponseContentType
        }
    }
}