├── .gitignore ├── BuildTools ├── BuildDocs.ps1 ├── Modules │ ├── BuildDocs │ │ ├── BuildDocs.psd1 │ │ └── BuildDocs.psm1 │ ├── CodeCovio │ │ ├── CodeCovIo.psm1 │ │ └── CodeCovio.psd1 │ └── ModuleData │ │ ├── ModuleData.psd1 │ │ └── ModuleData.psm1 ├── build.ps1 ├── deploy.PSDeploy.ps1 └── psake.ps1 ├── Config ├── .codecov.yml ├── appveyor.yml └── header-mkdocs.yml ├── LICENSE ├── PRE_RELEASE.md ├── PSRAW ├── Classes │ ├── 001-RedditOAuthScope.ps1 │ ├── 002-RedditApplication.ps1 │ ├── 003-RedditOAuthResponse.ps1 │ ├── 004-RedditOAuthToken.ps1 │ ├── 005-RedditApiResponse.ps1 │ ├── 006-RedditDataObject.ps1 │ ├── 006-RedditDate.ps1 │ ├── 007-RedditThing.ps1 │ ├── 008-RedditHeaderSize.ps1 │ ├── 008-RedditModReport.ps1 │ ├── 008-RedditUserReport.ps1 │ ├── 009-RedditComment.ps1 │ ├── 009-RedditLink.ps1 │ ├── 011-RedditSubmission.ps1 │ ├── 012-RedditSubreddit.ps1 │ ├── 013-RedditMore.ps1 │ └── 014-RedditListing.ps1 ├── Enums │ ├── RedditApplicationType.ps1 │ ├── RedditOAuthDuration.ps1 │ ├── RedditOAuthGrantType.ps1 │ ├── RedditOAuthResponseType.ps1 │ ├── RedditThingKind.ps1 │ └── RedditThingPrefix.ps1 ├── PSRAW.psd1 ├── PSRAW.psm1 ├── Private │ ├── API │ │ └── Wait-RedditApiRateLimit.ps1 │ ├── HTTP │ │ └── Get-HttpResponseContentType.ps1 │ └── OAuth │ │ ├── Get-AuthorizationHeader.ps1 │ │ ├── Request-RedditOAuthTokenClient.ps1 │ │ ├── Request-RedditOAuthTokenInstalled.ps1 │ │ └── Request-RedditOAuthTokenPassword.ps1 ├── Public │ ├── API │ │ ├── Invoke-RedditRequest.ps1 │ │ └── Resolve-RedditDataObject.ps1 │ ├── Application │ │ ├── Export-RedditApplication.ps1 │ │ ├── Import-RedditApplication.ps1 │ │ └── New-RedditApplication.ps1 │ └── OAuth │ │ ├── Connect-Reddit.ps1 │ │ ├── Export-RedditOAuthToken.ps1 │ │ ├── Get-RedditDefaultOAuthToken.ps1 │ │ ├── Get-RedditOAuthScope.ps1 │ │ ├── Import-RedditOAuthToken.ps1 │ │ ├── Request-RedditOAuthToken.ps1 │ │ ├── Set-RedditDefaultOAuthToken.ps1 │ │ └── Update-RedditOAuthToken.ps1 └── en-US │ ├── PSRAW-help.xml │ ├── about_RedditApiResponse.help.txt │ ├── about_RedditApplication.help.txt │ ├── about_RedditApplicationType.help.txt │ ├── about_RedditComment.help.txt │ ├── about_RedditDataObject.help.txt │ ├── about_RedditDate.help.txt │ ├── about_RedditHeaderSize.help.txt │ ├── about_RedditLink.help.txt │ ├── about_RedditListing.help.txt │ ├── about_RedditModReport.help.txt │ ├── about_RedditMore.help.txt │ ├── about_RedditOAuthDuration.help.txt │ ├── about_RedditOAuthGrantType.help.txt │ ├── about_RedditOAuthResponse.help.txt │ ├── about_RedditOAuthResponseType.help.txt │ ├── about_RedditOAuthScope.help.txt │ ├── about_RedditOAuthToken.help.txt │ ├── about_RedditSubmission.help.txt │ ├── about_RedditSubreddit.help.txt │ ├── about_RedditThing.help.txt │ ├── about_RedditThingKind.help.txt │ ├── about_RedditThingPrefix.help.txt │ └── about_RedditUserReport.help.txt ├── PlasterTemplates ├── NewClass │ ├── Class.txt │ └── plasterManifest.xml └── NewFunction │ ├── function.txt │ └── plasterManifest.xml ├── README.md ├── Tests ├── API │ ├── Invoke-RedditRequest.Unit.Tests.ps1 │ ├── Resolve-RedditDataObject.Unit.Tests.ps1 │ └── Wait-RedditApiRateLimit.Unit.Tests.ps1 ├── Application │ ├── Export-RedditApplication.Unit.Tests.ps1 │ ├── Import-RedditApplication.Unit.Tests.ps1 │ └── New-RedditApplication.Unit.Tests.ps1 ├── Classes │ ├── 001-RedditOAuthScope.Unit.Tests.ps1 │ ├── 002-RedditApplication.Unit.Tests.ps1 │ ├── 003-RedditOAuthResponse.Unit.Tests.ps1 │ ├── 004-RedditOAuthToken.Unit.Tests.ps1 │ ├── 005-RedditApiResponse.Unit.Tests.ps1 │ ├── 006-RedditDataObject.Unit.Tests.ps1 │ ├── 006-RedditDate.Unit.Tests.ps1 │ ├── 007-RedditThing.Unit.Tests.ps1 │ ├── 008-RedditHeaderSize.Unit.Tests.ps1 │ ├── 008-RedditModReport.Unit.Tests.ps1 │ ├── 008-RedditUserReport.Unit.Tests.ps1 │ ├── 009-RedditComment.Unit.Tests.ps1 │ ├── 009-RedditLink.Unit.Tests.ps1 │ ├── 011-RedditSubmission.Unit.tests.ps1 │ ├── 012-RedditSubredditUnit.Tests.ps1 │ ├── 013-RedditMore.Unit.Tests.ps1 │ └── 014-RedditListing.Unit.Tests.ps1 ├── HTTP │ └── Get-HttpResponseContentType.Tests.ps1 ├── Help.Tests.ps1 ├── OAuth │ ├── Connect-Reddit.Unit.Tests.ps1 │ ├── Export-RedditOAuthToken.Unit.Tests.ps1 │ ├── Get-AuthorizationHeader.Unit.Tests.ps1 │ ├── Get-RedditDefaultOAuthToken.Unit.Tests.ps1 │ ├── Get-RedditOAuthScope.Unit.Tests.ps1 │ ├── Import-RedditOAuthToken.Unit.Tests.ps1 │ ├── Request-RedditOAuthToken.Unit.Tests.ps1 │ ├── Request-RedditOAuthTokenClient.Unit.Tests.ps1 │ ├── Request-RedditOAuthTokenInstalled.Unit.Tests.ps1 │ ├── Request-RedditOAuthTokenPassword.Unit.Tests.ps1 │ ├── Set-RedditDefaultOAuthToken.Unit.Tests.ps1 │ └── Update-RedditOAuthToken.Unit.Tests.ps1 ├── PSScriptAnalyzer.Tests.ps1 ├── Project.Tests.ps1 └── tools │ ├── Modules │ └── WebListener │ │ ├── WebListener.psd1 │ │ └── WebListener.psm1 │ └── WebListener │ ├── Controllers │ ├── EchoController.cs │ ├── GetController.cs │ ├── HomeController.cs │ ├── ScopeController.cs │ ├── StatusCodeController.cs │ ├── SubmissionController.cs │ ├── SubredditController.cs │ ├── TokenController.cs │ └── UserController.cs │ ├── Models │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── README.md │ ├── Startup.cs │ ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Scope │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ └── _Layout.cshtml │ ├── Submission │ │ ├── Index.cshtml │ │ └── Nested.cshtml │ ├── Subreddit │ │ └── Index.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── WebListener.csproj │ ├── appsettings.Development.json │ └── appsettings.json ├── build.psm1 ├── docs ├── ChangeLog.md ├── Examples │ ├── Quickstart.md │ └── images │ │ ├── quickstart-01.PNG │ │ └── quickstart-02.PNG ├── Module │ ├── Connect-Reddit.md │ ├── Export-RedditApplication.md │ ├── Export-RedditOAuthToken.md │ ├── Get-RedditDefaultOAuthToken.md │ ├── Get-RedditOAuthScope.md │ ├── Import-RedditApplication.md │ ├── Import-RedditOAuthToken.md │ ├── Invoke-RedditRequest.md │ ├── New-RedditApplication.md │ ├── PSRAW.md │ ├── Request-RedditOAuthToken.md │ ├── Resolve-RedditDataObject.md │ ├── Set-RedditDefaultOAuthToken.md │ ├── Update-RedditOAuthToken.md │ ├── about_RedditApiResponse.md │ ├── about_RedditApplication.md │ ├── about_RedditApplicationType.md │ ├── about_RedditComment.md │ ├── about_RedditDataObject.md │ ├── about_RedditDate.md │ ├── about_RedditHeaderSize.md │ ├── about_RedditLink.md │ ├── about_RedditListing.md │ ├── about_RedditModReport.md │ ├── about_RedditMore.md │ ├── about_RedditOAuthDuration.md │ ├── about_RedditOAuthGrantType.md │ ├── about_RedditOAuthResponse.md │ ├── about_RedditOAuthResponseType.md │ ├── about_RedditOAuthScope.md │ ├── about_RedditOAuthToken.md │ ├── about_RedditSubmission.md │ ├── about_RedditSubreddit.md │ ├── about_RedditThing.md │ ├── about_RedditThingKind.md │ ├── about_RedditThingPrefix.md │ └── about_RedditUserReport.md ├── PrivateFunctions │ ├── Get-AuthorizationHeader.md │ ├── Get-HttpResponseContentType.md │ ├── Request-RedditOAuthTokenClient.md │ ├── Request-RedditOAuthTokenPassword.md │ ├── Request-RedditOAuthTokeninstalled.md │ └── Wait-RedditApiRateLimit.md ├── Project │ ├── Contributing.md │ └── News.md ├── RELEASE.md └── index.md └── mkdocs.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # PowerShell Studio Build Files 2 | *.psproj 3 | *.psprojs 4 | *.psbuild 5 | *.preview.ps1 6 | *.run.ps1 7 | *.temppoint.* 8 | *.RestorePoint.* 9 | 10 | 11 | # Recycle Bin used on file shares 12 | $RECYCLE.BIN/ 13 | 14 | # Windows Installer files 15 | *.cab 16 | *.msi 17 | *.msm 18 | *.msp 19 | 20 | # Windows image file caches 21 | Thumbs.db 22 | ehthumbs.db 23 | 24 | # VS Code 25 | .vscode 26 | 27 | bin/ 28 | obj/ 29 | apps/ 30 | 31 | # Ignore executables 32 | *.exe 33 | *.msi 34 | *.appx 35 | 36 | # Ignore binaries and symbols 37 | *.pdb 38 | *.dll 39 | 40 | # Ignore packages 41 | *.deb 42 | *.zip 43 | *.rpm 44 | *.pkg 45 | *.nupkg 46 | 47 | 48 | # dotnet cli install/uninstall scripts 49 | dotnet-install.ps1 50 | dotnet-install.sh 51 | dotnet-uninstall-pkgs.sh 52 | dotnet-uninstall-debian-packages.sh 53 | 54 | pester-tests.xml 55 | -------------------------------------------------------------------------------- /BuildTools/Modules/BuildDocs/BuildDocs.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markekraus/PSRAW/d93ca99d5bbf6ea924c3ba4f419ef394581b6e64/BuildTools/Modules/BuildDocs/BuildDocs.psd1 -------------------------------------------------------------------------------- /BuildTools/Modules/CodeCovio/CodeCovio.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markekraus/PSRAW/d93ca99d5bbf6ea924c3ba4f419ef394581b6e64/BuildTools/Modules/CodeCovio/CodeCovio.psd1 -------------------------------------------------------------------------------- /BuildTools/Modules/ModuleData/ModuleData.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markekraus/PSRAW/d93ca99d5bbf6ea924c3ba4f419ef394581b6e64/BuildTools/Modules/ModuleData/ModuleData.psd1 -------------------------------------------------------------------------------- /BuildTools/Modules/ModuleData/ModuleData.psm1: -------------------------------------------------------------------------------- 1 | function Get-ModulePrivateFunction { 2 | [CmdletBinding()] 3 | [OutputType([System.Management.Automation.FunctionInfo])] 4 | param ( 5 | [Parameter( 6 | Mandatory = $true, 7 | ValueFromPipeline = $true, 8 | ValueFromPipelineByPropertyName = $true 9 | )] 10 | [string[]] 11 | $ModuleName 12 | ) 13 | 14 | process { 15 | foreach ($Name in $ModuleName) { 16 | $Module = $null 17 | Write-Verbose "Processing Module '$Name'" 18 | $Module = Get-Module -Name $Name -ErrorAction SilentlyContinue 19 | if (-not $Module) { 20 | Write-Error "Module '$Name' not found" 21 | continue 22 | } 23 | $ScriptBlock = { 24 | $ExecutionContext.InvokeCommand.GetCommands('*', 'Function', $true) 25 | } 26 | $PublicFunctions = $Module.ExportedCommands.GetEnumerator() | 27 | Select-Object -ExpandProperty Value | 28 | Select-Object -ExpandProperty Name 29 | & $Module $ScriptBlock | Where-Object {$_.Source -eq $Name -and $_.Name -notin $PublicFunctions} 30 | } 31 | } 32 | } 33 | 34 | function Get-ModuleClass { 35 | [CmdletBinding()] 36 | param ( 37 | [Parameter( 38 | Mandatory = $true, 39 | ValueFromPipeline = $true, 40 | ValueFromPipelineByPropertyName = $true 41 | )] 42 | [string[]] 43 | $ModuleName 44 | ) 45 | 46 | process { 47 | foreach ($Name in $ModuleName) { 48 | $Module = $null 49 | Write-Verbose "Processing Module '$Name'" 50 | $Module = Get-Module -Name $Name -ErrorAction SilentlyContinue 51 | if (-not $Module) { 52 | Write-Error "Module '$Name' not found" 53 | continue 54 | } 55 | $ModulePattern = $Module.ModuleBase. 56 | Replace([System.IO.Path]::DirectorySeparatorChar, '.'). 57 | Replace([System.IO.Path]::VolumeSeparatorChar, '.') 58 | $DynamicClassAttribute = 59 | [System.Management.Automation.DynamicClassImplementationAssemblyAttribute] 60 | [AppDomain]:: 61 | CurrentDomain. 62 | GetAssemblies(). 63 | where({ 64 | $_.GetCustomAttributes($true).TypeId -contains $DynamicClassAttribute -and 65 | $_.FullName -match $ModulePattern 66 | }). 67 | GetTypes(). 68 | where({ $_.IsPublic }) 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /BuildTools/build.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 4/23/2017 6 | Edited on: 4/23/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: build.ps1 10 | 11 | .DESCRIPTION 12 | Build Initialization 13 | #> 14 | param ($Task = 'Default') 15 | 16 | Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null 17 | 18 | $ModuleInstallScope = 'CurrentUser' 19 | if ($ENV:BHBuildSystem -eq 'AppVeyor') { 20 | $ModuleInstallScope = 'Global' 21 | } 22 | 23 | 24 | Install-Module -Scope $ModuleInstallScope Psake, PSDeploy, BuildHelpers, platyPS, PSScriptAnalyzer -force 25 | Install-Module -Scope $ModuleInstallScope Pester -Force -SkipPublisherCheck 26 | Import-Module Psake, BuildHelpers, platyPS, PSScriptAnalyzer 27 | Import-Module $PSScriptRoot/../build.psm1 28 | 29 | 30 | 31 | 32 | Set-BuildEnvironment -ErrorAction SilentlyContinue 33 | 34 | Invoke-psake -buildFile .\BuildTools\psake.ps1 -taskList $Task -nologo 35 | exit ([int](-not $psake.build_success)) 36 | -------------------------------------------------------------------------------- /BuildTools/deploy.PSDeploy.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 4/23/2017 6 | Edited on:: 4/23/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: deploy.PSDeploy.ps1 10 | 11 | .DESCRIPTION 12 | PSDeploy for PowerShell Gallery Module Deployment 13 | #> 14 | if ($ENV:ModuleName -and $ENV:ModuleName.Count -eq 1) { 15 | Deploy Module { 16 | By PSGalleryModule { 17 | FromSource $ENV:ModuleName 18 | To PSGallery 19 | WithOptions @{ 20 | ApiKey = $ENV:NugetApiKey 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Config/.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 2 3 | round: down 4 | range: "90...100" -------------------------------------------------------------------------------- /Config/appveyor.yml: -------------------------------------------------------------------------------- 1 | # See http://www.appveyor.com/docs/appveyor-yml for many more options 2 | cache: 3 | - '%LocalAppData%\Microsoft\dotnet -> appveyor.yml' 4 | - '%HOMEDRIVE%%HOMEPATH%\.nuget\packages -> appveyor.yml' 5 | 6 | version: 2.0.0.{build} 7 | skip_tags: true 8 | environment: 9 | APPVEYOR_SAVE_CACHE_ON_ERROR: true 10 | NugetApiKey: 11 | secure: 3sC7bUSY534F4WnpYXlP7XyikulxbSpfLZgC3y37gA2OAeMp35la0zplVjiliOFn 12 | access_token: 13 | secure: eBkkiWtTuwTfnTN2G4n0RegBV+MImV3BoKYm2pGmi/0Lu3VGb4m07m5FJWq+29sD 14 | ModuleName: PSRAW 15 | 16 | os: WMF 5 17 | 18 | skip_commits: 19 | message: /updated readme.*|update readme.*s/ 20 | 21 | build: false 22 | 23 | test_script: 24 | - ps: . .\BuildTools\build.ps1 25 | -------------------------------------------------------------------------------- /Config/header-mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: PSRAW - PowerShell Reddit API Wrapper Module 2 | site_author: Mark Kraus 3 | repo_url: https://github.com/markekraus/PSRAW/ 4 | theme: readthedocs 5 | copyright: "PSRAW is licensed under the MIT license" 6 | pages: 7 | - Home: index.md 8 | - PSRAW Project: 9 | - Contributing to PSRAW: Project/Contributing.md 10 | - Project News: Project/News.md -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mark Kraus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PRE_RELEASE.md: -------------------------------------------------------------------------------- 1 | ## Functions 2 | 3 | ### Invoke-RedditRequest 4 | 5 | * Fixed error when processing Invoke-WebRequest errors on Core. 6 | 7 | ### Resolve-RedditDataObject (experimental) 8 | 9 | * Public due to class implementation limitations 10 | * Will later be removed. 11 | 12 | 13 | ## Classes 14 | 15 | ### RedditComment (experimental) 16 | 17 | * Now has RedditDataObject base class 18 | * Added Kind instance property 19 | * Added MoreObject property 20 | * Added parentObject property 21 | * Replies is now a RedditComment array 22 | * AccessToken removed 23 | * Added Static RedditThingKind property 24 | * Added Constructor to convert a comment RedditThing to a RedditComment 25 | * Added HasMoreReplies method 26 | 27 | ### RedditDataObject (experimental) 28 | 29 | * Class Added as base class for all Reddit classes that Contain Data 30 | 31 | ### RedditHeaderSize 32 | 33 | * Added class to represent header Sizes returned from the API 34 | 35 | ### RedditLink (experimental) 36 | 37 | * Added class to represent Links and Self-Posts 38 | 39 | ### RedditListing (experimental) 40 | 41 | * Added class to represent "Listings" returned by the API 42 | 43 | ### RedditModReport 44 | 45 | * Added default Constructor for compatibility 46 | 47 | ### RedditMore (experimental) 48 | 49 | * Added class to represent "Mores" returned by the API 50 | 51 | ### RedditOAuthToken 52 | 53 | * Fixed IsRateLimited() to correctly return False when all values are 0 54 | 55 | ### RedditSubmission (experimental) 56 | 57 | * Added class to house the link and comments for a submission 58 | 59 | ### RedditSubreddit (experimental) 60 | 61 | * Added class to represent Subreddits 62 | 63 | ### RedditThing (experimental) 64 | 65 | * No longer a base class. This is now a meta class to mirror its function in the Reddit API. 66 | * Added constructor to convert a Reddit thing from the API to a RedditThing 67 | * Added default Constructor for compatibility 68 | * Added CreateFrom() Method to create an array of RedditThing objects from a RedditApiResponse 69 | 70 | ### RedditUserReport 71 | 72 | * Added default Constructor for compatibility 73 | 74 | 75 | ## Private Functions 76 | 77 | ### Get-HttpResponseContentType 78 | 79 | * Better null or empty detection 80 | 81 | ### Wait-RedditApiRateLimit 82 | 83 | * More verbose and helpful message 84 | 85 | 86 | ## Build Tools 87 | 88 | * Added build.psm1 helper module to to make Building and testing PSRAW easier 89 | * BuildDocs-Helper is now the BuildDocs Module 90 | * CodeCovIo-Helper is now the CodeCovIo Module 91 | * ModuleData-Helper is now the ModuleData Module 92 | * Performance and accuracy tweaks to get-ModuleClass 93 | * psake.ps1 has been radically changed to allow individual tasks to be run more independently and many tasks now rely on build.psm1 functions 94 | * Minor fixes to BuildDocs 95 | 96 | ## Project Configuration 97 | * Updates to .gitignore to accommodate dotnet builds 98 | * AppVeyor caching enabled to speed up dotnet between builds 99 | 100 | ## Tests 101 | 102 | * All tests have been redone to work with build.psm1's Start-PSRAWPester (now required to run the tests) 103 | * All the insanity blocks have been removed 104 | * WebListener added as an API mock up 105 | * many many test optimizations -------------------------------------------------------------------------------- /PSRAW/Classes/001-RedditOAuthScope.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 4/24/2017 3:37 PM 6 | Edited on: 5/10/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 001-RedditOAuthScope.ps1 10 | 11 | .DESCRIPTION 12 | RedditOAuthScope Class 13 | #> 14 | Class RedditOAuthScope { 15 | [String]$Scope 16 | [String]$Id 17 | [String]$Name 18 | [String]$Description 19 | 20 | Static [String]$ApiEndpointUri = 'https://www.reddit.com/api/v1/scopes' 21 | 22 | Static [String] GetApiEndpointUri (){ 23 | return [RedditOAuthScope]::ApiEndpointUri 24 | } 25 | 26 | RedditOAuthScope () { 27 | $This._init('','','','') 28 | } 29 | 30 | RedditOAuthScope ([String]$Scope) { 31 | $This._init($Scope,$Scope,$Scope,$Scope) 32 | } 33 | 34 | RedditOAuthScope ([String]$Scope, [String]$Id, [String]$Name, [String]$Description){ 35 | $This._init($Scope, $Id, $Name, $Description) 36 | } 37 | 38 | hidden [void] _init ([String]$Scope, [String]$Id, [String]$Name, [String]$Description){ 39 | $This.Scope = $Scope 40 | $This.Id = $Id 41 | $This.Name = $Name 42 | $This.Description = $Description 43 | } 44 | 45 | [string] ToString() { 46 | Return $This.Scope 47 | } 48 | } -------------------------------------------------------------------------------- /PSRAW/Classes/003-RedditOAuthResponse.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/2/2017 4:31 PM 6 | Edited on: 8/2/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 003-RedditOAuthResponse.ps1 10 | 11 | .DESCRIPTION 12 | RedditOAuthResponse Class 13 | #> 14 | Class RedditOAuthResponse { 15 | [hashtable]$Parameters 16 | [DateTime]$RequestDate 17 | [Microsoft.PowerShell.Commands.WebResponseObject]$Response 18 | [PSObject]$Content 19 | [String]$ContentType 20 | RedditOAuthResponse () { } 21 | } 22 | -------------------------------------------------------------------------------- /PSRAW/Classes/005-RedditApiResponse.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 5/20/2017 10:01 AM 6 | Edited on: 5/20/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 005-RedditApiResponse.ps1 10 | 11 | .DESCRIPTION 12 | RedditApiResponse Class 13 | #> 14 | Class RedditApiResponse { 15 | [RedditOAuthToken]$AccessToken 16 | [hashtable]$Parameters 17 | [DateTime]$RequestDate 18 | [Microsoft.PowerShell.Commands.WebResponseObject]$Response 19 | [PSObject]$ContentObject 20 | [String]$ContentType 21 | RedditApiResponse () { } 22 | } 23 | -------------------------------------------------------------------------------- /PSRAW/Classes/006-RedditDataObject.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/13/2017 11:50 AM 6 | Edited on: 8/13/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 006-RedditDataObject.ps1 10 | 11 | .DESCRIPTION 12 | RedditDataObject Base Class 13 | #> 14 | Class RedditDataObject { 15 | RedditDataObject () { } 16 | } 17 | -------------------------------------------------------------------------------- /PSRAW/Classes/006-RedditDate.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 6/1/2017 2:38 PM 6 | Edited on: 6/1/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 006-RedditDate.ps1 10 | 11 | .DESCRIPTION 12 | RedditDate Class 13 | #> 14 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 15 | "PSAvoidUsingEmptyCatchBlock", 16 | "", 17 | Justification = "Exception handled through presence of boolean test." 18 | )] 19 | Class RedditDate { 20 | [double]$Unix = 0 21 | [DateTime]$Date = '1970/1/1' 22 | static [DateTime]$UnixEpoch = '1970/1/1' 23 | RedditDate () { } 24 | RedditDate ([String]$String) { 25 | $Set = $false 26 | try { 27 | $This.Unix = [double]::Parse($string) 28 | $This.date = [RedditDate]::UnixEpoch.AddSeconds($This.Unix) 29 | $Set = $true 30 | } 31 | catch { } 32 | Try { 33 | $ParsedDate = [dateTime]::Parse($string) 34 | $Difference = $ParsedDate - [RedditDate]::UnixEpoch 35 | $This.Date = $ParsedDate 36 | $This.Unix = $Difference.TotalSeconds 37 | $Set = $true 38 | } 39 | catch { } 40 | if (-not $Set) { 41 | $Exception = [System.ArgumentException]::new( 42 | 'Unable to parse string as System.DateTime or System.Double.' 43 | ) 44 | throw $Exception 45 | } 46 | } 47 | RedditDate ([Double]$Double) { 48 | $This.Unix = $Double 49 | $This.date = [RedditDate]::UnixEpoch.AddSeconds($This.Unix) 50 | } 51 | RedditDate ([DateTime]$Date) { 52 | $Difference = $Date - [RedditDate]::UnixEpoch 53 | $This.Date = $Date 54 | $This.Unix = $Difference.TotalSeconds 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /PSRAW/Classes/007-RedditThing.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 5/29/2017 9:24 AM 6 | Edited on: 5/29/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 007-RedditThing.ps1 10 | 11 | .DESCRIPTION 12 | RedditThing Class 13 | #> 14 | Class RedditThing { 15 | [RedditThingKind]$Kind 16 | [PSObject]$Data 17 | [string]$Name 18 | [string]$Id 19 | [PSObject]$ParentObject 20 | [RedditDataObject]$RedditData 21 | RedditThing () {} 22 | RedditThing ([PSObject]$Object) { 23 | $this.Kind = $Object.Kind 24 | $This.Name = $Object.Name 25 | $This.Id = $Object.Id 26 | $This.Data = $Object.Data 27 | $This.RedditData = Resolve-RedditDataObject -RedditThing $this 28 | $This.RedditData.ParentObject = $This 29 | } 30 | static [RedditThing[]] CreateFrom([RedditApiResponse]$Response) { 31 | $RedditThings = foreach($Object in $Response.ContentObject){ 32 | $RedditThing = [RedditThing]::New($Object) 33 | $RedditThing.ParentObject = $Response 34 | $RedditThing 35 | } 36 | Return $RedditThings 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /PSRAW/Classes/008-RedditHeaderSize.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/16/2017 4:09 AM 6 | Edited on: 8/16/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 008-RedditHeaderSize.ps1 10 | 11 | .DESCRIPTION 12 | RedditHeaderSize Class 13 | #> 14 | Class RedditHeaderSize { 15 | [long]$Width 16 | [long]$Height 17 | RedditHeaderSize () { 18 | } 19 | RedditHeaderSize ([Object[]]$InputObjects) { 20 | $This.Width = $InputObjects[0] 21 | $This.Height = $InputObjects[1] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /PSRAW/Classes/008-RedditModReport.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 6/1/2017 1:44 PM 6 | Edited on: 6/1/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 008-RedditModReport.ps1 10 | 11 | .DESCRIPTION 12 | RedditModReport Class 13 | #> 14 | Class RedditModReport { 15 | [String]$Reason 16 | [String]$Moderator 17 | RedditModReport () { 18 | } 19 | RedditModReport ([Object[]]$InputObjects) { 20 | $This.Reason = $InputObjects[0] 21 | $This.Moderator = $InputObjects[1] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /PSRAW/Classes/008-RedditUserReport.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 6/1/2017 1:47 PM 6 | Edited on: 6/1/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 008-RedditUserReport.ps1 10 | 11 | .DESCRIPTION 12 | RedditUserReport Class 13 | #> 14 | Class RedditUserReport { 15 | [String]$Reason 16 | [long]$Count 17 | RedditUserReport () { 18 | } 19 | RedditUserReport ([Object[]]$InputObjects) { 20 | $This.Reason = $InputObjects[0] 21 | $This.Count = $InputObjects[1] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /PSRAW/Classes/011-RedditSubmission.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/15/2017 4:53 AM 6 | Edited on: 8/15/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 011-RedditSubmission.ps1 10 | 11 | .DESCRIPTION 12 | RedditSubmission Class 13 | #> 14 | Class RedditSubmission : RedditDataObject { 15 | [RedditLink]$Link 16 | [RedditComment[]]$Comments 17 | RedditSubmission () { } 18 | RedditSubmission ([RedditApiResponse]$ApiResponse) { 19 | $Things = [RedditThing]::CreateFrom($ApiResponse) 20 | $This.Link = $Things[0].RedditData.Items[0] 21 | $List = [system.collections.generic.list[RedditComment]]::new() 22 | foreach($comment in $Things[1].RedditData.GetComments()){ 23 | $List.Add($Comment) 24 | } 25 | foreach($CommentId in $Things[1].RedditData.GetMores().Children){ 26 | $Comment = [RedditComment]@{ 27 | Id = $CommentId 28 | name = 't1_{0}' -f $CommentId 29 | link_id = $this.Link.name 30 | parent_id = $this.Link.name 31 | subreddit = $this.Link.subreddit 32 | subreddit_id = $this.Link.subreddit_id 33 | subreddit_name_prefixed = $this.Link.subreddit_name_prefixed 34 | ParentObject = $This.Link 35 | } 36 | $List.Add($Comment) 37 | } 38 | $This.Comments = $List 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /PSRAW/Classes/013-RedditMore.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/17/2017 4:24 AM 6 | Edited on: 8/17/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 013-RedditMore.ps1 10 | 11 | .DESCRIPTION 12 | RedditMore Class 13 | #> 14 | Class RedditMore : RedditDataObject { 15 | [string[]]$Children 16 | [long]$Count 17 | [string]$Id 18 | [string]$Name 19 | [string]$Parent_Id 20 | [PSObject]$ParentObject 21 | [RedditThingKind]$Kind = 'More' 22 | Static [RedditThingKind]$RedditThingKind = 'More' 23 | RedditMore () { } 24 | RedditMore ([RedditThing]$RedditThing){ 25 | if($RedditThing.Kind -ne $This::RedditThingKind){ 26 | $Message = 'Unable to convert RedditThing of kind "{0}" to "{1}"' -f 27 | $RedditThing.Kind, 28 | $This.GetType().Name 29 | $Exception = [System.InvalidCastException]::new($Message) 30 | Throw $Exception 31 | } 32 | $This.Children = $RedditThing.Data.Children 33 | $This.Count = $RedditThing.Data.Count 34 | $This.Name = $RedditThing.Data.Name 35 | $This.id = $RedditThing.Data.id 36 | $This.Parent_Id = $RedditThing.Data.parent_id 37 | $This.ParentObject = $RedditThing 38 | } 39 | # TODO Add GetMoreItems() to retrieve the More's items 40 | } 41 | -------------------------------------------------------------------------------- /PSRAW/Classes/014-RedditListing.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/13/2017 10:10 AM 6 | Edited on: 8/17/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: 014-RedditListing.ps1 10 | 11 | .DESCRIPTION 12 | RedditListing Class 13 | #> 14 | Class RedditListing : RedditDataObject { 15 | [string]$Before 16 | [string]$After 17 | [string]$Modhash 18 | [RedditThing[]]$Children 19 | [RedditThingKind[]]$ChildKinds 20 | [PSObject]$ParentObject 21 | [RedditDataObject[]]$Items 22 | [RedditThingKind]$Kind = 'Listing' 23 | Static [RedditThingKind]$RedditThingKind = 'Listing' 24 | RedditListing () { } 25 | RedditListing ([RedditThing]$RedditThing){ 26 | if($RedditThing.Kind -ne $This::RedditThingKind){ 27 | $Message = 'Unable to convert RedditThing of kind "{0}" to "{1}"' -f 28 | $RedditThing.Kind, 29 | $This.GetType().Name 30 | $Exception = [System.InvalidCastException]::new($Message) 31 | Throw $Exception 32 | } 33 | $This.Before = $RedditThing.Data.before 34 | $This.After = $RedditThing.Data.After 35 | $This.Modhash = $RedditThing.Data.Modhash 36 | $This.Children = [RedditThing[]]$RedditThing.Data.children 37 | $This.ParentObject = $RedditThing 38 | $This.ChildKinds = $This.Children.Kind | Select-Object -Unique 39 | $This.Items = $This.Children.RedditData 40 | } 41 | 42 | [RedditComment[]] GetComments() { 43 | return ($This.Items | Where-Object {$_ -is 'RedditComment'}) 44 | } 45 | 46 | [RedditMore[]] GetMores() { 47 | return ($This.Items | Where-Object {$_ -is 'RedditMore'}) 48 | } 49 | 50 | [RedditLink[]] GetLinks() { 51 | return ($This.Items | Where-Object {$_ -is 'RedditLink'}) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /PSRAW/Enums/RedditApplicationType.ps1: -------------------------------------------------------------------------------- 1 | Enum RedditApplicationType { 2 | WebApp 3 | Script 4 | Installed 5 | } -------------------------------------------------------------------------------- /PSRAW/Enums/RedditOAuthDuration.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/01/2017 12:27 PM 6 | Edited on: 5/01/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: RedditOAuthDuration.psm1 10 | 11 | .DESCRIPTION 12 | RedditOAuthDuration Enum 13 | #> 14 | Enum RedditOAuthDuration { 15 | Permanent 16 | Temporary 17 | } -------------------------------------------------------------------------------- /PSRAW/Enums/RedditOAuthGrantType.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/05/2017 02:00 PM 6 | Edited on: 5/05/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: RedditOAuthGrantType.psm1 10 | 11 | .DESCRIPTION 12 | RedditOAuthGrantType Enum 13 | #> 14 | Enum RedditOAuthGrantType { 15 | Client_Credentials 16 | Installed_Client 17 | Password 18 | } -------------------------------------------------------------------------------- /PSRAW/Enums/RedditOAuthResponseType.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/01/2017 12:27 PM 6 | Edited on: 5/01/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: RedditOAuthResponseType.psm1 10 | 11 | .DESCRIPTION 12 | RedditOAuthResponseType Enum 13 | #> 14 | Enum RedditOAuthResponseType { 15 | Code 16 | Token 17 | } -------------------------------------------------------------------------------- /PSRAW/Enums/RedditThingKind.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 8/08/2017 4:38 AM 6 | Edited on: 8/08/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: RedditThingKind.ps1 10 | 11 | .DESCRIPTION 12 | RedditThingKind Enum 13 | #> 14 | 15 | Enum RedditThingKind { 16 | t1 # Comment 17 | t2 # Account 18 | t3 # Link 19 | t4 # Message 20 | t5 # Subreddit 21 | t6 # Award 22 | t8 # PromoCampaign 23 | listing # Listing 24 | more # ?? 25 | } -------------------------------------------------------------------------------- /PSRAW/Enums/RedditThingPrefix.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/29/2017 9:51 PM 6 | Edited on: 5/29/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: RedditThingPrefix.ps1 10 | 11 | .DESCRIPTION 12 | RedditThingPrefix Enum 13 | #> 14 | # https://www.reddit.com/dev/api/#fullnames 15 | Enum RedditThingPrefix { 16 | t1 # Comment 17 | t2 # Account 18 | t3 # Link 19 | t4 # Message 20 | t5 # Subreddit 21 | t6 # Award 22 | t8 # PromoCampaign 23 | } -------------------------------------------------------------------------------- /PSRAW/PSRAW.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | 3 | Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.139 4 | Created on: 4/23/2017 9:22 AM 5 | Edited On: 8/03/2017 6 | Created by: Mark Kraus 7 | Organization: 8 | Filename: PSRAW.psm1 9 | ------------------------------------------------------------------------- 10 | Module Name: PSRAW 11 | 12 | #> 13 | 14 | # v6 Invoke-WebRequest uses strict header validation by default and introduced a 15 | # SkipHeaderValidation Switch Parameter. Reddit requires a non-compliant 16 | # User-Agent format. Setting this Default Parameter value allows for backwards 17 | # compatibility with 5.1 without having to introduce version check logic before 18 | # each Invoke-WebRequest call. 19 | $PSDefaultParameterValues['Invoke-WebRequest:SkipHeaderValidation'] = $True 20 | 21 | $functionFolders = @('Enums','Classes','Public','Private' ) 22 | ForEach ($folder in $functionFolders) 23 | { 24 | $folderPath = Join-Path -Path $PSScriptRoot -ChildPath $folder 25 | If (Test-Path -Path $folderPath) 26 | { 27 | Write-Verbose -Message "Importing from $folder" 28 | $FunctionFiles = Get-ChildItem -Path $folderPath -Filter '*.ps1' -Recurse | 29 | Where-Object { $_.Name -notmatch '\.tests{0,1}\.ps1' } 30 | ForEach ($FunctionFile in $FunctionFiles) 31 | { 32 | Write-Verbose -Message " Importing $($FunctionFile.BaseName)" 33 | . $($FunctionFile.FullName) 34 | } 35 | } 36 | } 37 | $folderPath = Join-Path -Path $PSScriptRoot -ChildPath 'Public' 38 | $FunctionFiles = Get-ChildItem $folderPath -Filter '*.ps1' -Recurse | 39 | Where-Object { $_.Name -notmatch '\.tests{0,1}\.ps1' } 40 | foreach ($FunctionFile in $FunctionFiles) { 41 | $AST = [System.Management.Automation.Language.Parser]::ParseFile($FunctionFile.FullName, [ref]$null, [ref]$null) 42 | $Functions = $AST.FindAll({ 43 | $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] 44 | }, $true) 45 | if ($Functions.Name) { 46 | Export-ModuleMember -Function $Functions.Name 47 | } 48 | $Aliases = $AST.FindAll({ 49 | $args[0] -is [System.Management.Automation.Language.AttributeAst] -and 50 | $args[0].parent -is [System.Management.Automation.Language.ParamBlockAst] -and 51 | $args[0].TypeName.FullName -eq 'alias' 52 | }, $true) 53 | if ($Aliases.PositionalArguments.value) { 54 | Export-ModuleMember -Alias $Aliases.PositionalArguments.value 55 | } 56 | } 57 | 58 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 59 | "PSUseDeclaredVarsMoreThanAssignments", 60 | "", 61 | Justification = 'PsrawSettings is a module settings variable consumed in module functions' 62 | )] 63 | $PsrawSettings = @{ 64 | AccessToken = [RedditOAuthToken]::new() 65 | } -------------------------------------------------------------------------------- /PSRAW/Private/API/Wait-RedditApiRateLimit.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 5/20/2017 6:18 AM 6 | Edited on: 5/20/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Wait-RedditApiRateLimit.ps1 10 | 11 | .DESCRIPTION 12 | Wait-RedditApiRateLimit Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Wait-RedditApiRateLimit { 18 | [CmdletBinding( 19 | ConfirmImpact = 'None', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Wait-RedditApiRateLimit', 21 | SupportsShouldProcess = $true 22 | )] 23 | [OutputType([Void])] 24 | param 25 | ( 26 | [Parameter( 27 | Mandatory = $true, 28 | ValueFromPipeline = $true, 29 | ValueFromPipelineByPropertyName = $true 30 | )] 31 | [Alias('Token')] 32 | [RedditOAuthToken] 33 | $AccessToken, 34 | 35 | [Parameter( 36 | Mandatory = $false, 37 | ValueFromPipeline = $false, 38 | ValueFromPipelineByPropertyName = $true 39 | )] 40 | [int] 41 | $MaxSleepSeconds = 300 42 | ) 43 | Begin { 44 | $MaxSleepDate = (Get-date).AddSeconds($MaxSleepSeconds) 45 | } 46 | Process { 47 | if (-not $PSCmdlet.ShouldProcess($AccessToken.GUID)) { 48 | return 49 | } 50 | if (-not $AccessToken.IsRateLimited()) { 51 | Write-Verbose 'Token has not exceeded ratelimit.' 52 | return 53 | } 54 | $Message = 'Rate limit in effect until {0}. Sleeping. RateLimitRemaining: {1}; RateLimitRest: {2}; RateLimitUsed: {3}; LastApiCall: {4}; GUID:{5}' -f 55 | $AccessToken.GetRateLimitReset(), 56 | $AccessToken.RateLimitRemaining, 57 | $AccessToken.RateLimitRest, 58 | $AccessToken.RateLimitUsed, 59 | $AccessToken.LastApiCall, 60 | $AccessToken.GUID 61 | Write-Warning $Message 62 | while ( 63 | $AccessToken.IsRateLimited() -and 64 | (Get-Date) -lt $MaxSleepDate 65 | ) { 66 | Start-Sleep -Seconds 1 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /PSRAW/Private/HTTP/Get-HttpResponseContentType.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/2/2017 8:37 AM 6 | Edited on: 8/2/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Get-HttpResponseContentType.ps1 10 | 11 | .DESCRIPTION 12 | Get-HttpResponseContentType Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Get-HttpResponseContentType { 18 | [CmdletBinding( 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-HttpResponseContentType', 21 | SupportsShouldProcess = $false 22 | )] 23 | [OutputType([String])] 24 | param 25 | ( 26 | [Parameter( 27 | Mandatory = $true, 28 | ValueFromPipeline = $true, 29 | ValueFromPipelineByPropertyName = $true 30 | )] 31 | [Microsoft.PowerShell.Commands.WebResponseObject] 32 | $Response 33 | ) 34 | Process { 35 | @( 36 | $Response.BaseResponse.Content.Headers.ContentType.MediaType 37 | $Response.BaseResponse.ContentType 38 | ) | 39 | Where-Object {-not [string]::IsNullOrEmpty($_)} | 40 | Select-Object -First 1 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PSRAW/Private/OAuth/Get-AuthorizationHeader.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/05/2017 03:27 PM 6 | Edited on: 5/14/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Get-AuthorizationHeader.ps1 10 | 11 | .DESCRIPTION 12 | Get-AuthorizationHeader Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Get-AuthorizationHeader { 18 | [CmdletBinding( 19 | HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-AuthorizationHeader' 20 | )] 21 | [OutputType([System.String])] 22 | param ( 23 | [Parameter( 24 | Mandatory = $true, 25 | ValueFromPipeline = $true, 26 | ValueFromPipelineByPropertyName = $true 27 | )] 28 | [PSCredential] 29 | [System.Management.Automation.CredentialAttribute()]$Credential 30 | ) 31 | 32 | process { 33 | 'Basic {0}' -f ( 34 | [System.Convert]::ToBase64String( 35 | [System.Text.Encoding]::ASCII.GetBytes( 36 | ('{0}:{1}' -f $Credential.UserName, $Credential.GetNetworkCredential().Password) 37 | )# End [System.Text.Encoding]::ASCII.GetBytes( 38 | )# End [System.Convert]::ToBase64String( 39 | )# End 'Basic {0}' -f 40 | }# End process 41 | }# End Get-AuthorizationHeader -------------------------------------------------------------------------------- /PSRAW/Private/OAuth/Request-RedditOAuthTokenClient.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/05/2017 02:27 PM 6 | Edited on: 5/14/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Request-RedditOAuthTokenClient.ps1 10 | 11 | .DESCRIPTION 12 | Request-RedditOAuthTokenClient Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Request-RedditOAuthTokenClient { 18 | [CmdletBinding( 19 | HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenClient' 20 | )] 21 | [OutputType([RedditOAuthResponse])] 22 | param ( 23 | [Parameter( 24 | mandatory = $true, 25 | ValueFromPipeline = $true, 26 | ValueFromPipelineByPropertyName = $true 27 | )] 28 | [ValidateScript( 29 | { 30 | If (-not ($_.Type -eq [RedditApplicationType]::Script -or $_.Type -eq [RedditApplicationType]::WebApp)) { 31 | $Exception = [System.Management.Automation.ValidationMetadataException]::new( 32 | "RedditApplicationType must be 'Script' or 'WebApp" 33 | ) 34 | Throw $Exception 35 | } 36 | $true 37 | } 38 | )] 39 | [RedditApplication]$Application, 40 | 41 | [Parameter( 42 | mandatory = $false, 43 | ValueFromPipeline = $false, 44 | ValueFromPipelineByPropertyName = $false 45 | )] 46 | [String]$AuthBaseUrl = [RedditOAuthToken]::AuthBaseURL 47 | ) 48 | process { 49 | $Params = @{ 50 | Uri = $AuthBaseUrl 51 | Body = @{ 52 | grant_type = 'client_credentials' 53 | } 54 | UserAgent = $Application.UserAgent 55 | Headers = @{ 56 | Authorization = $Application.ClientCredential | Get-AuthorizationHeader 57 | } 58 | Method = 'POST' 59 | UseBasicParsing = $true 60 | } 61 | $Response = Invoke-WebRequest @Params 62 | $Null = $Params.Remove('Headers') 63 | [RedditOAuthResponse]@{ 64 | Response = $Response 65 | RequestDate = $Response.Headers.Date[0] 66 | Parameters = $Params 67 | Content = $Response.Content 68 | ContentType = $Response | Get-HttpResponseContentType 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /PSRAW/Private/OAuth/Request-RedditOAuthTokenInstalled.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/05/2017 11:27 AM 6 | Edited on: 5/14/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Request-RedditOAuthTokenInstalled.ps1 10 | 11 | .DESCRIPTION 12 | Request-RedditOAuthTokenInstalled Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Request-RedditOAuthTokenInstalled { 18 | [CmdletBinding( 19 | HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled' 20 | )] 21 | [OutputType([RedditOAuthResponse])] 22 | param ( 23 | [Parameter( 24 | mandatory = $true, 25 | ValueFromPipeline = $true, 26 | ValueFromPipelineByPropertyName = $true 27 | )] 28 | [RedditApplication]$Application, 29 | 30 | [Parameter( 31 | mandatory = $false, 32 | ValueFromPipeline = $false, 33 | ValueFromPipelineByPropertyName = $true 34 | )] 35 | [String]$DeviceID = [guid]::NewGuid().tostring(), 36 | 37 | [Parameter( 38 | mandatory = $false, 39 | ValueFromPipeline = $false, 40 | ValueFromPipelineByPropertyName = $false 41 | )] 42 | [String]$AuthBaseUrl = [RedditOAuthToken]::AuthBaseURL 43 | ) 44 | process { 45 | $Params = @{ 46 | Uri = $AuthBaseUrl 47 | Body = @{ 48 | grant_type = 'https://oauth.reddit.com/grants/installed_client' 49 | device_id = $DeviceID 50 | } 51 | UserAgent = $Application.UserAgent 52 | Headers = @{ 53 | Authorization = $Application.ClientCredential | Get-AuthorizationHeader 54 | } 55 | Method = 'POST' 56 | UseBasicParsing = $true 57 | } 58 | $Response = Invoke-WebRequest @Params 59 | $Null = $Params.Remove('Headers') 60 | [RedditOAuthResponse]@{ 61 | Response = $Response 62 | RequestDate = $Response.Headers.Date[0] 63 | Parameters = $Params 64 | Content = $Response.Content 65 | ContentType = $Response | Get-HttpResponseContentType 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /PSRAW/Private/OAuth/Request-RedditOAuthTokenPassword.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/05/2017 02:27 PM 6 | Edited on: 5/14/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Request-RedditOAuthTokenPassword.ps1 10 | 11 | .DESCRIPTION 12 | Request-RedditOAuthTokenPassword Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Request-RedditOAuthTokenPassword { 18 | [CmdletBinding( 19 | HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenPassword' 20 | )] 21 | [OutputType([RedditOAuthResponse])] 22 | param ( 23 | [Parameter( 24 | mandatory = $true, 25 | ValueFromPipeline = $true, 26 | ValueFromPipelineByPropertyName = $true 27 | )] 28 | [ValidateScript( 29 | { 30 | If (-not ($_.Type -eq [RedditApplicationType]::Script)) { 31 | $Exception = [System.Management.Automation.ValidationMetadataException]::new( 32 | "RedditApplicationType must be 'Script'" 33 | ) 34 | Throw $Exception 35 | } 36 | $true 37 | } 38 | )] 39 | [RedditApplication]$Application, 40 | 41 | [Parameter( 42 | mandatory = $false, 43 | ValueFromPipeline = $false, 44 | ValueFromPipelineByPropertyName = $false 45 | )] 46 | [String]$AuthBaseUrl = [RedditOAuthToken]::AuthBaseURL 47 | ) 48 | process { 49 | $Params = @{ 50 | Uri = $AuthBaseUrl 51 | Body = @{ 52 | grant_type = 'password' 53 | username = $Application.ScriptUser 54 | password = $Application.GetUserPassword() 55 | } 56 | UserAgent = $Application.UserAgent 57 | Headers = @{ 58 | Authorization = $Application.ClientCredential | Get-AuthorizationHeader 59 | } 60 | Method = 'POST' 61 | UseBasicParsing = $true 62 | } 63 | $Response = Invoke-WebRequest @Params 64 | $Null = $Params.Remove('Headers') 65 | [RedditOAuthResponse]@{ 66 | Response = $Response 67 | RequestDate = $Response.Headers.Date[0] 68 | Parameters = $Params 69 | Content = $Response.Content 70 | ContentType = $Response | Get-HttpResponseContentType 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /PSRAW/Public/API/Resolve-RedditDataObject.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/13/2017 12:55 PM 6 | Edited on: 8/13/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Resolve-RedditDataObject.ps1 10 | 11 | .DESCRIPTION 12 | Resolve-RedditDataObject Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Resolve-RedditDataObject { 18 | [CmdletBinding( 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Resolve-RedditdataObject', 21 | SupportsShouldProcess = $true 22 | )] 23 | [OutputType([RedditDataObject])] 24 | param 25 | ( 26 | [parameter( 27 | ParameterSetName = 'RedditAPIResponse', 28 | Mandatory = $true, 29 | Position = 0, 30 | ValueFromPipelineByPropertyName = $true, 31 | ValueFromPipeline = $true 32 | )] 33 | [RedditApiResponse]$RedditApiResponse, 34 | 35 | [parameter( 36 | ParameterSetName = 'RedditThing', 37 | Mandatory = $true, 38 | Position = 0, 39 | ValueFromPipelineByPropertyName = $true, 40 | ValueFromPipeline = $true 41 | )] 42 | [RedditThing]$RedditThing, 43 | 44 | [parameter( 45 | ParameterSetName = 'PSObject', 46 | Mandatory = $true, 47 | Position = 0, 48 | ValueFromPipelineByPropertyName = $true, 49 | ValueFromPipeline = $true 50 | )] 51 | [PSObject]$PSObject 52 | 53 | ) 54 | Begin { 55 | $DataObjectKindMap = @{ 56 | t1 = 'RedditComment' 57 | t2 = 'RedditAccount' 58 | t3 = 'RedditLink' 59 | t4 = 'RedditMessage' 60 | t5 = 'RedditSubreddit' 61 | t6 = 'RedditAward' 62 | t8 = 'RedditPromoCampaign' 63 | Listing = 'RedditListing' 64 | More = 'RedditMore' 65 | } 66 | } 67 | Process { 68 | if (-not $PSCmdlet.ShouldProcess("RedditDataObject")) { 69 | return 70 | } 71 | switch ($PSCmdlet.ParameterSetName) { 72 | 'RedditAPIResponse' { 73 | $RedditThing = [RedditThing]$RedditApiResponse.ContentObject 74 | $DataObjectKind = $RedditApiResponse.ContentObject.Kind 75 | Break 76 | } 77 | 'RedditThing' { 78 | $DataObjectKind = $RedditThing.Kind 79 | Break 80 | } 81 | 'PSObject' { 82 | $RedditThing = [RedditThing]$PSObject 83 | $DataObjectKind = $RedditThing.Kind 84 | Break 85 | } 86 | } 87 | $Class = $DataObjectKindMap["$DataObjectKind"] 88 | New-Object -TypeName $Class -ArgumentList $RedditThing 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /PSRAW/Public/Application/Export-RedditApplication.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 4/30/2017 1:09 PM 6 | Edited on: 5/11/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Export-RedditApplication.ps1 10 | 11 | .DESCRIPTION 12 | Export-RedditApplication Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Export-RedditApplication { 18 | [CmdletBinding(DefaultParameterSetName = 'ExportPath', 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Export-RedditApplication', 21 | SupportsShouldProcess = $true)] 22 | [OutputType([System.IO.FileInfo])] 23 | param 24 | ( 25 | [Parameter(ParameterSetName = 'Path', 26 | Mandatory = $true, 27 | ValueFromPipelineByPropertyName = $true)] 28 | [ValidateNotNullOrEmpty()] 29 | [string]$Path, 30 | 31 | [Parameter(ParameterSetName = 'LiteralPath', 32 | Mandatory = $true, 33 | ValueFromRemainingArguments = $true)] 34 | [ValidateNotNullOrEmpty()] 35 | [string]$LiteralPath, 36 | 37 | [Parameter(ParameterSetName = 'LiteralPath', 38 | Mandatory = $false, 39 | ValueFromPipelineByPropertyName = $true)] 40 | [Parameter(ParameterSetName = 'Path', 41 | Mandatory = $false, 42 | ValueFromPipelineByPropertyName = $true)] 43 | [Parameter(ParameterSetName = 'ExportPath', 44 | Mandatory = $false, 45 | ValueFromPipelineByPropertyName = $true)] 46 | [ValidateSet('ASCII', 'UTF8', 'UTF7', 'UTF32', 'Unicode', 'BigEndianUnicode', 'Default', 'OEM')] 47 | [string]$Encoding = 'Unicode', 48 | 49 | [Parameter(ParameterSetName = 'LiteralPath', 50 | Mandatory = $true, 51 | ValueFromPipeline = $true, 52 | ValueFromPipelineByPropertyName = $true)] 53 | [Parameter(ParameterSetName = 'Path', 54 | Mandatory = $true, 55 | ValueFromPipeline = $true, 56 | ValueFromPipelineByPropertyName = $true)] 57 | [Parameter(ParameterSetName = 'ExportPath', 58 | Mandatory = $true, 59 | ValueFromPipeline = $true, 60 | ValueFromPipelineByPropertyName = $true)] 61 | [Alias('App', 'RedditApplication')] 62 | [RedditApplication]$Application 63 | ) 64 | 65 | Process { 66 | $Params = @{ 67 | Depth = [int32]::MaxValue - 1 68 | Encoding = $Encoding 69 | InputObject = $Application 70 | } 71 | switch ($PsCmdlet.ParameterSetName) { 72 | 'Path' { 73 | $Params['Path'] = $Path 74 | $Target = $Path 75 | break 76 | } 77 | 'LiteralPath' { 78 | $Params['LiteralPath'] = $LiteralPath 79 | $Target = $LiteralPath 80 | break 81 | } 82 | 'ExportPath' { 83 | $Params['Path'] = $Application.ExportPath 84 | $Target = $LiteralPath 85 | break 86 | } 87 | } 88 | if ($pscmdlet.ShouldProcess("Target")) { 89 | Export-Clixml @Params 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /PSRAW/Public/Application/Import-RedditApplication.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/01/2017 4:39 AM 6 | Edited on: 5/11/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Import-RedditApplication.ps1 10 | 11 | .DESCRIPTION 12 | Import-RedditApplication Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Import-RedditApplication { 18 | [CmdletBinding(DefaultParameterSetName = 'Path', 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Import-RedditApplication', 21 | SupportsShouldProcess = $true)] 22 | [OutputType([RedditApplication])] 23 | param 24 | ( 25 | [Parameter(ParameterSetName = 'Path', 26 | Mandatory = $true, 27 | ValueFromPipeline = $true, 28 | ValueFromPipelineByPropertyName = $true)] 29 | [ValidateNotNullOrEmpty()] 30 | [string[]]$Path, 31 | 32 | [Parameter(ParameterSetName = 'LiteralPath', 33 | Mandatory = $true, 34 | ValueFromRemainingArguments = $true)] 35 | [ValidateNotNullOrEmpty()] 36 | [string[]]$LiteralPath 37 | ) 38 | 39 | Process { 40 | Switch ($PsCmdlet.ParameterSetName) { 41 | 'Path' { 42 | $ImportFiles = $Path 43 | $ImportParam = 'Path' 44 | Break 45 | } 46 | 'LiteralPath' { 47 | $ImportFiles = $LiteralPath 48 | $ImportParam = 'LiteralPath' 49 | Break 50 | } 51 | } 52 | foreach ($ImportFile in $ImportFiles) { 53 | if (-not $pscmdlet.ShouldProcess($ImportFile)) { 54 | Continue 55 | } 56 | $Params = @{ 57 | "$ImportParam" = $ImportFile 58 | } 59 | $InObject = Import-Clixml @Params 60 | $Application = [RedditApplication]$InObject 61 | $Application.ExportPath = (Resolve-Path $ImportFile).Path 62 | $Application 63 | } #End Foreach 64 | } #End Process 65 | } #End Function -------------------------------------------------------------------------------- /PSRAW/Public/OAuth/Connect-Reddit.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/11/2017 6:00 PM 6 | Edited on: 8/11/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Connect-Reddit.ps1 10 | 11 | .DESCRIPTION 12 | Connect-Reddit Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Connect-Reddit { 18 | [CmdletBinding( 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Connect-Reddit' 21 | )] 22 | [OutputType([Void])] 23 | param 24 | ( 25 | [pscredential]$ClientCredential, 26 | [pscredential]$UserCredential, 27 | [uri]$RedirectUri 28 | ) 29 | Process { 30 | $ClientID = $ClientCredential.UserName 31 | if ([string]::IsNullOrEmpty($ClientID)) { 32 | $ClientID = Read-Host 'Enter your Reddit Script Application Client ID' 33 | } 34 | $ClientSecret = $ClientCredential.Password 35 | if( 36 | $null -eq $ClientSecret -or 37 | $ClientSecret.Length -eq 0 38 | ) { 39 | $ClientSecret = Read-Host 'Enter your Reddit Script Application Client Secret' -AsSecureString 40 | } 41 | if([string]::IsNullOrEmpty($RedirectUri.AbsoluteUri)){ 42 | [uri]$RedirectUri = Read-Host 'Enter your Reddit Application Redirect URI' 43 | } 44 | $Username = $UserCredential.UserName 45 | if ( 46 | $Null -eq $Username -or 47 | $Username -eq [string]::Empty 48 | ) { 49 | $Username = Read-Host 'Enter your Reddit User ID' 50 | } 51 | $Password = $UserCredential.Password 52 | if( 53 | $null -eq $Password -or 54 | $Password.Length -eq 0 55 | ) { 56 | $Password = Read-Host 'Enter your Reddit Password' -AsSecureString 57 | } 58 | $AppParams = @{ 59 | Script = $True 60 | ClientCredential = [pscredential]::New($ClientID,$ClientSecret) 61 | UserCredential = [pscredential]::New($Username,$Password) 62 | RedirectUri = $RedirectUri 63 | } 64 | $Application = New-RedditApplication @AppParams 65 | Request-RedditOAuthToken -Script -Application $Application 66 | } 67 | } -------------------------------------------------------------------------------- /PSRAW/Public/OAuth/Get-RedditDefaultOAuthToken.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/12/2017 8:01 AM 6 | Edited on: 8/12/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Get-RedditDefaultOAuthToken.ps1 10 | 11 | .DESCRIPTION 12 | Get-RedditDefaultOAuthToken Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Get-RedditDefaultOAuthToken { 18 | [CmdletBinding( 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Get-RedditDefaultOAuthToken', 21 | SupportsShouldProcess = $true 22 | )] 23 | [OutputType([RedditOAuthToken])] 24 | param( ) 25 | Process { 26 | if (-not $PSCmdlet.ShouldProcess("Getting Default Token")) { 27 | return 28 | } 29 | $Script:PsrawSettings.AccessToken 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /PSRAW/Public/OAuth/Get-RedditOAuthScope.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 4/23/2017 1:42 PM 6 | Edited on: 5/13/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Get-RedditOAuthScope.ps1 10 | 11 | .DESCRIPTION 12 | Get-RedditOAuthScope Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Get-RedditOAuthScope { 18 | [CmdletBinding( 19 | ConfirmImpact = 'None', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Get-RedditOAuthScope' 21 | )] 22 | [OutputType([RedditOAuthScope])] 23 | param 24 | ( 25 | [Parameter(Mandatory = $false)] 26 | [string]$ApiEndpointUri = [RedditOAuthScope]::GetApiEndpointUri() 27 | ) 28 | 29 | Write-Verbose "Retrieving Scopes from '$ApiEndpointUri'" 30 | $ResultObj = Invoke-RestMethod -Uri $ApiEndpointUri 31 | 32 | Write-Verbose "Looping through each scope and creating [RedditOAuthScope] Objects" 33 | foreach ($Property in $ResultObj.psobject.Properties.Name) { 34 | Write-Verbose "Processing '$Property'" 35 | [RedditOAuthScope]@{ 36 | Scope = $Property 37 | Id = $ResultObj.$Property.id 38 | Name = $ResultObj.$Property.Name 39 | Description = $ResultObj.$Property.Description 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /PSRAW/Public/OAuth/Import-RedditOAuthToken.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/11/2017 4:39 AM 6 | Edited on: 5/11/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Import-RedditOAuthToken.ps1 10 | 11 | .DESCRIPTION 12 | Import-RedditOAuthToken Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Import-RedditOAuthToken { 18 | [CmdletBinding( 19 | DefaultParameterSetName = 'Path', 20 | ConfirmImpact = 'Low', 21 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Import-RedditOAuthToken', 22 | SupportsShouldProcess = $true 23 | )] 24 | [OutputType([RedditOAuthToken])] 25 | param 26 | ( 27 | [Parameter( 28 | ParameterSetName = 'Path', 29 | Mandatory = $true, 30 | ValueFromPipeline = $true, 31 | ValueFromPipelineByPropertyName = $true)] 32 | [ValidateNotNullOrEmpty()] 33 | [string[]]$Path, 34 | 35 | [Parameter( 36 | ParameterSetName = 'LiteralPath', 37 | Mandatory = $true, 38 | ValueFromRemainingArguments = $true 39 | )] 40 | [ValidateNotNullOrEmpty()] 41 | [string[]]$LiteralPath, 42 | 43 | [switch] 44 | $PassThru 45 | ) 46 | 47 | Process { 48 | Switch ($PsCmdlet.ParameterSetName) { 49 | 'Path' { 50 | $ImportFiles = $Path 51 | $ImportParam = 'Path' 52 | Break 53 | } 54 | 'LiteralPath' { 55 | $ImportFiles = $LiteralPath 56 | $ImportParam = 'LiteralPath' 57 | Break 58 | } 59 | } 60 | foreach ($ImportFile in $ImportFiles) { 61 | if (-not $pscmdlet.ShouldProcess($ImportFile)) { 62 | Continue 63 | } 64 | $Params = @{ 65 | "$ImportParam" = $ImportFile 66 | } 67 | $InObject = Import-Clixml @Params 68 | $AccessToken = [RedditOAuthToken]::Reserialize($InObject) 69 | $AccessToken.ExportPath = (Resolve-Path $ImportFile).Path 70 | $AccessToken | Set-RedditDefaultOAuthToken 71 | If ($PassThru) { 72 | $AccessToken 73 | } 74 | } #End Foreach 75 | } #End Process 76 | } #End Function -------------------------------------------------------------------------------- /PSRAW/Public/OAuth/Set-RedditDefaultOAuthToken.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: 8/12/2017 8:00 AM 6 | Edited on: 8/12/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Set-RedditDefaultOAuthToken.ps1 10 | 11 | .DESCRIPTION 12 | Set-RedditDefaultOAuthToken Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Set-RedditDefaultOAuthToken { 18 | [CmdletBinding( 19 | ConfirmImpact = 'Low', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Set-RedditDefaultOAuthToken', 21 | SupportsShouldProcess = $true 22 | )] 23 | [OutputType([Void])] 24 | param 25 | ( 26 | [Parameter( 27 | Mandatory = $true, 28 | ValueFromPipeline = $true, 29 | ValueFromPipelineByPropertyName = $true, 30 | Position = 0 31 | )] 32 | [Alias('Token')] 33 | [RedditOAuthToken] 34 | $AccessToken 35 | ) 36 | Process { 37 | if (-not $PSCmdlet.ShouldProcess("Setting default Access Token")) { 38 | return 39 | } 40 | $Script:PsrawSettings.AccessToken = $AccessToken 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PSRAW/Public/OAuth/Update-RedditOAuthToken.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: VSCode 5 | Created on: 5/17/2017 04:07 AM 6 | Edited on: 5/18/2017 7 | Created by: Mark Kraus 8 | Organization: 9 | Filename: Update-RedditOAuthToken.ps1 10 | 11 | .DESCRIPTION 12 | Update-RedditOAuthToken Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function Update-RedditOAuthToken { 18 | [CmdletBinding( 19 | HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Update-RedditOAuthToken', 20 | SupportsShouldProcess = $true 21 | )] 22 | [OutputType([RedditOAuthToken])] 23 | param 24 | ( 25 | [Parameter( 26 | Mandatory = $false, 27 | ValueFromPipeline = $true, 28 | ValueFromPipelineByPropertyName = $true, 29 | Position = 0 30 | )] 31 | [Alias('Token')] 32 | [RedditOAuthToken[]]$AccessToken = (Get-RedditDefaultOAuthToken), 33 | 34 | [switch]$Force, 35 | 36 | [switch]$PassThru, 37 | 38 | [switch]$SetDefault 39 | 40 | ) 41 | 42 | process { 43 | foreach ($Token in $AccessToken) { 44 | if (-not $PSCmdlet.ShouldProcess($Token.GUID)) { 45 | continue 46 | } 47 | if (-not $Token.IsExpired() -and -not $Force) { 48 | continue 49 | } 50 | switch ($Token.GrantType) { 51 | 'Installed_Client' { 52 | $Params = @{ 53 | Application = $Token.Application 54 | DeviceID = $Token.DeviceID 55 | } 56 | $Result = Request-RedditOAuthTokenInstalled @Params 57 | Break 58 | } 59 | 'Password' { 60 | $Params = @{ 61 | Application = $Token.Application 62 | } 63 | $Result = Request-RedditOAuthTokenPassword @Params 64 | Break 65 | } 66 | 'Client_Credentials' { 67 | $Params = @{ 68 | Application = $Token.Application 69 | } 70 | $Result = Request-RedditOAuthTokenClient @Params 71 | Break 72 | } 73 | } 74 | $Token.Refresh($Result) 75 | if ($SetDefault) { 76 | $Token | Set-RedditDefaultOAuthToken 77 | } 78 | if ($PassThru.IsPresent) { 79 | $Token 80 | } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditApplicationType.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditapplicationtype 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditApplicationType Enum 6 | 7 | LONG DESCRIPTION 8 | The `RedditApplicationType` enumerator represents the available option for 9 | applications registered in Reddit. To register an application go to 10 | https://ssl.reddit.com/prefs/apps . `RedditApplicationType` is used by the 11 | Type property of the `RedditApplication` class. 12 | For more information on Reddit OAuth App Types see 13 | https://github.com/reddit/reddit/wiki/OAuth2-App-Types 14 | 15 | FIELDS 16 | Installed 17 | An app intended for installation, such as on a mobile phone. 18 | 19 | Script 20 | Script for personal use. Will only be able to act on behalf of the developer 21 | who registered the application. 22 | 23 | WebApp 24 | A Web base application. Can also be used in scripts to act on behalf of 25 | other users. 26 | 27 | EXAMPLES 28 | WebApp 29 | $WebApp = [RedditApplicationType]::WebApp 30 | 31 | Script 32 | $Script = [RedditApplicationType]::Script 33 | 34 | installed 35 | $Installed= [RedditApplicationType]::Installed 36 | 37 | SEE ALSO 38 | about_RedditApplicationType 39 | about_RedditApplication 40 | New-RedditApplication 41 | https://ssl.reddit.com/prefs/apps 42 | https://github.com/reddit/reddit/wiki/OAuth2-App-Types 43 | https://github.com/reddit/reddit/wiki/API 44 | https://github.com/reddit/reddit/wiki/OAuth2 45 | https://www.reddit.com/prefs/apps 46 | https://www.reddit.com/wiki/api 47 | https://psraw.readthedocs.io/ 48 | 49 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditDataObject.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditdataobject 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditDataObject Class (experimental) 6 | 7 | LONG DESCRIPTION 8 | Base Class for Reddit data Objects. This class is used only as a general 9 | base class and provide no functionality or features. 10 | 11 | CONSTRUCTORS 12 | RedditDataObject() 13 | Creates an empty `RedditDataObject` 14 | 15 | [RedditDataObject]::new() 16 | 17 | PROPERTIES 18 | METHODS 19 | EXAMPLES 20 | [RedditDataObject]::new() 21 | 22 | NOTES 23 | Experimental: This is an experimental feature. Expect radical changes 24 | between versions. Do not write production code against this until it has 25 | been marked stable. 26 | 27 | DERIVED CLASSES 28 | * 29 | RedditComment 30 | * 31 | RedditLink 32 | * 33 | RedditListing 34 | * 35 | RedditMore 36 | * 37 | RedditSubmission 38 | * 39 | RedditSubreddit 40 | 41 | SEE ALSO 42 | about_RedditDataObject 43 | about_RedditComment 44 | about_RedditLink 45 | about_RedditSubmission 46 | about_RedditSubreddit 47 | about_RedditMore 48 | about_RedditListing 49 | Resolve-RedditDataObject 50 | https://www.reddit.com/wiki/api 51 | https://github.com/reddit/reddit/wiki/JSON 52 | https://psraw.readthedocs.io/ 53 | 54 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditDate.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditdate 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditDate Class 6 | 7 | LONG DESCRIPTION 8 | Reddit uses Unix Epoch dates in a Double. The `RedditDate` class provides 9 | easy translation between a Unix date and a `DateTime` object. This object 10 | does not automatically update after it is initialized. 11 | 12 | CONSTRUCTORS 13 | RedditDate() 14 | Creates a `RedditDate` at the Unix Epoch. 15 | 16 | [RedditDate]::new() 17 | 18 | RedditDate(DateTime Date) 19 | Creates a `RedditDate` from a `DateTime` object. 20 | 21 | [RedditDate]::new([DateTime]$Date) 22 | 23 | RedditDate(Double Double) 24 | Creates a `RedditDate` from a `Double` 25 | 26 | [RedditDate]::new([Double]$Double) 27 | 28 | RedditDate(String String) 29 | Creates a `RedditDate` from a parsable `Double` or `DateTime` `String`. 30 | 31 | [RedditDate]::new([String]$String) 32 | 33 | PROPERTIES 34 | Date 35 | The `DateTime` of the `RedditDate` 36 | 37 | Name: Date 38 | Type: DateTime 39 | Hidden: False 40 | Static: False 41 | 42 | Unix 43 | The Unix Timestamp in seconds. 44 | 45 | Name: Unix 46 | Type: Double 47 | Hidden: False 48 | Static: False 49 | 50 | UnixEpoch 51 | The Unix Epoch time used in creating the `RedditDate` 52 | 53 | Name: UnixEpoch 54 | Type: DateTime 55 | Hidden: False 56 | Static: True 57 | 58 | METHODS 59 | EXAMPLES 60 | $Date = [dateTime]'7/27/2017' 61 | [RedditDate]::New($Date) 62 | [RedditDate]::New(1501113600) 63 | [RedditDate]::New('7/27/2017') 64 | [RedditDate]::New('1501113600') 65 | $UnixDate = ([RedditDate]$Date).Unix 66 | $UnixDate = ([RedditDate]'7/27/2017').Unix 67 | $DateTime = ([RedditDate]1501113600).Date 68 | $DateTime = ([RedditDate]'1501113600').Date 69 | 70 | SEE ALSO 71 | about_RedditDate 72 | https://www.reddit.com/wiki/api 73 | https://psraw.readthedocs.io/ 74 | 75 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditHeaderSize.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditheadersize 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditHeaderSize Class 6 | 7 | LONG DESCRIPTION 8 | Represents the size of a Subreddit Header 9 | 10 | CONSTRUCTORS 11 | RedditHeaderSize() 12 | Creates an empty `RedditHeaderSize` 13 | 14 | [RedditHeaderSize]::new() 15 | 16 | RedditHeaderSize(Object[] InputObjects) 17 | Creates a `RedditHeaderSize` from an array where the first element is the 18 | width and the second element is the height. This is how the Reddit API 19 | returns the object. 20 | 21 | [RedditHeaderSize]::new([Object[]]$InputObjects) 22 | 23 | PROPERTIES 24 | Height 25 | The Height of the Header 26 | 27 | Name: Height 28 | Type: Int64 29 | Hidden: False 30 | Static: False 31 | 32 | Width 33 | The Width of the Header 34 | 35 | Name: Width 36 | Type: Int64 37 | Hidden: False 38 | Static: False 39 | 40 | METHODS 41 | SEE ALSO 42 | about_RedditHeaderSize 43 | about_RedditSubreddit 44 | https://www.reddit.com/wiki/api 45 | https://psraw.readthedocs.io/ 46 | 47 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditModReport.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditmodreport 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditModReport Class 6 | 7 | LONG DESCRIPTION 8 | A moderator report for a comment or submission. 9 | 10 | CONSTRUCTORS 11 | RedditModReport() 12 | Creates an empty `RedditModReport` object. 13 | 14 | [RedditModReport]::new() 15 | 16 | RedditModReport(Object[] InputObjects) 17 | Creates a `RedditModReport` from an array. 18 | 19 | [RedditModReport]::new([Object[]]$InputObjects) 20 | 21 | PROPERTIES 22 | Moderator 23 | The reporting Moderator's Reddit username. 24 | 25 | Name: Moderator 26 | Type: String 27 | Hidden: False 28 | Static: False 29 | 30 | Reason 31 | The reason for the report. 32 | 33 | Name: Reason 34 | Type: String 35 | Hidden: False 36 | Static: False 37 | 38 | METHODS 39 | EXAMPLES 40 | $RedditModReport = [RedditModReport]@('Breaks Rule 12', 'markekraus') 41 | 42 | SEE ALSO 43 | about_RedditModReport 44 | about_RedditComment 45 | about_RedditLink 46 | https://www.reddit.com/wiki/api 47 | https://psraw.readthedocs.io/ 48 | 49 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditMore.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditmore 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditMore Class (experimental) 6 | 7 | LONG DESCRIPTION 8 | Represents a `More` objects returned from teh reddit API. A more is returned 9 | containing a list of IDs when a listing contains too many items to return 10 | all of the data for all items. This happens, for example, when a submission 11 | has too many replies. X number or replies will be returned normally and the 12 | rest will be returned as a `More`. Another instance when a `More` is 13 | returned is when a comments is too deep in the reply chain that an empty 14 | More is returned to indicate the comment has replies that can be fetched 15 | separately. 16 | 17 | CONSTRUCTORS 18 | RedditMore() 19 | Creates an empty `RedditMore` object 20 | 21 | [RedditMore]::new() 22 | 23 | RedditMore(RedditThing RedditThing) 24 | Creates a `RedditMore` from a `RedditThing` containing a `More` returned 25 | from the reddit API. 26 | 27 | [RedditMore]::new([RedditThing]$RedditThing) 28 | 29 | PROPERTIES 30 | Children 31 | IDs of the Children that were not returned 32 | 33 | Name: Children 34 | Type: String[] 35 | Hidden: False 36 | Static: False 37 | 38 | Count 39 | The number of Children 40 | 41 | Name: Count 42 | Type: Int64 43 | Hidden: False 44 | Static: False 45 | 46 | Id 47 | The `More`'s ID 48 | 49 | Name: Id 50 | Type: String 51 | Hidden: False 52 | Static: False 53 | 54 | Kind 55 | The kind. this should always be `More` 56 | 57 | Name: Kind 58 | Type: RedditThingKind 59 | Hidden: False 60 | Static: False 61 | 62 | Name 63 | The Reddit Fullname of the `More` 64 | 65 | Name: Name 66 | Type: String 67 | Hidden: False 68 | Static: False 69 | 70 | Parent_Id 71 | The Fullname of the parent that returned the more This is either a link or 72 | comment. 73 | 74 | Name: Parent_Id 75 | Type: String 76 | Hidden: False 77 | Static: False 78 | 79 | ParentObject 80 | This may contain the Parent object that returned the more 81 | 82 | Name: ParentObject 83 | Type: System.Management.Automation.PSObject 84 | Hidden: False 85 | Static: False 86 | 87 | RedditThingKind 88 | The kind. This should always be `More` 89 | 90 | Name: RedditThingKind 91 | Type: RedditThingKind 92 | Hidden: False 93 | Static: True 94 | 95 | METHODS 96 | NOTES 97 | Experimental: This is an experimental feature. Expect radical changes 98 | between versions. Do not write production code against this until it has 99 | been marked stable. 100 | 101 | DERIVED FROM 102 | RedditDataObject 103 | 104 | SEE ALSO 105 | about_RedditMore 106 | about_RedditComment 107 | about_RedditDataObject 108 | about_RedditLink 109 | about_RedditListing 110 | about_RedditThing 111 | https://www.reddit.com/wiki/api 112 | https://github.com/reddit/reddit/wiki/JSON 113 | https://psraw.readthedocs.io/ 114 | 115 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditOAuthDuration.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditoauthduration 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditOAuthDuration Enum 6 | 7 | LONG DESCRIPTION 8 | The `RedditOAuthDuration` enumerator represents the available options for 9 | Access Token durations during Authorization code requests to the Reddit API. 10 | 11 | FIELDS 12 | Permanent 13 | Requests for permanent OAuth Access Tokens will issue an OAuth Refresh 14 | Token. Access Tokens are valid for 60 minutes. When the Access Token expires 15 | the Refresh Token can be used to request a new access token without 16 | requiring the application to be authorized again. Refresh tokens are valid 17 | until a user or developer revokes the authorization for the application. 18 | When `Permanent` Access Tokens are "renewed" the do not require a new grant 19 | flow and the Refresh Token will be used to request a new Access Token. 20 | `Permanent` is currently not support in PSRAW. 21 | 22 | Temporary 23 | Requests for temporary OAuth Access Tokens will not issue Refresh Tokens and 24 | when they expire the user will need to authorize the applications again. 25 | Access Tokens are valid for 60 minutes. 26 | When `Temporary` Access Tokens are "renewed" a new grant flow is started. 27 | `Temporary` can be used with any grant flow. 28 | 29 | EXAMPLES 30 | Permanent 31 | $Permanent = [RedditOAuthDuration]::Permanent 32 | 33 | Temporary 34 | $Temporary = [RedditOAuthDuration]::Temporary 35 | 36 | SEE ALSO 37 | about_RedditOAuthDuration 38 | about_RedditApplication 39 | about_RedditOAuthToken 40 | New-RedditApplication 41 | Request-RedditOAuthToken 42 | https://ssl.reddit.com/prefs/apps 43 | https://github.com/reddit/reddit/wiki/API 44 | https://github.com/reddit/reddit/wiki/OAuth2 45 | https://www.reddit.com/prefs/apps 46 | https://www.reddit.com/wiki/api 47 | https://psraw.readthedocs.io/ 48 | 49 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditOAuthGrantType.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditoauthgranttype 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditOAuthGrantType Enum 6 | 7 | LONG DESCRIPTION 8 | The `RedditOAuthGrantType` enumerator contains the available grant types 9 | available for OAuth Access Tokens requests on Reddit. this is visible on 10 | `RedditOAuthToken` objects as the `GrantType` property. It is used by 11 | various functions in this module to determine the actions and endpoints 12 | required to request Access Tokens. 13 | 14 | FIELDS 15 | Client_Credentials 16 | This grant method uses the Client ID and Client Secret to request an 17 | anonymous Access Token. This method will not act under a user context but 18 | will allow "logged out" access to the OAuth API endpoints for `Script` and 19 | `WebApp` applications. For more information see the `Client` parameter 20 | description of `Request-RedditOAuthToken` or the Reddit OAuth documentation 21 | at https://github.com/reddit/reddit/wiki/OAuth2#application-only-oauth 22 | 23 | Installed_Client 24 | This grant flow allows anonymous access to the Reddit API for `Installed` 25 | applications. This method will not act under a user context but will allow 26 | "logged out" access to the OAuth API endpoints. For more information see 27 | the `Installed` parameter description of `Request-RedditOAuthToken` or the 28 | Reddit OAuth documentation at 29 | https://github.com/reddit/reddit/wiki/OAuth2#application-only-oauth 30 | 31 | Password 32 | This grant flow allows for the developer of `Script` applications to access 33 | the Reddit API as themselves. This uses the Username, Password, Client ID, 34 | and Client Secret to request an OAuth Access Token. For more information 35 | see the `Script` parameter description of `Request-RedditOAuthToken` or the 36 | Reddit OAuth documentation at 37 | https://github.com/reddit/reddit/wiki/OAuth2#application-only-oauth 38 | 39 | SEE ALSO 40 | about_RedditOAuthGrantType 41 | about_RedditOAuthToken 42 | Request-RedditOAuthToken 43 | https://github.com/reddit/reddit/wiki/OAuth2 44 | https://psraw.readthedocs.io/ 45 | 46 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditOAuthResponse.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditoauthresponse 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditOAuthResponse Class 6 | 7 | LONG DESCRIPTION 8 | The `RedditOAuthResponse` Class encapsulates the responses from Reddit OAuth 9 | grant flows. 10 | 11 | CONSTRUCTORS 12 | RedditOAuthResponse() 13 | Default Constructor creates an empty `RedditOAuthResponse` object. 14 | 15 | [RedditOAuthResponse]::new() 16 | 17 | PROPERTIES 18 | Content 19 | The Content returned from the Reddit. It may be either plain text or an 20 | object created from JSON. 21 | 22 | Name: Content 23 | Type: System.Management.Automation.PSObject 24 | Hidden: False 25 | Static: False 26 | 27 | ContentType 28 | The `Content-Type` response header returned from Reddit. 29 | 30 | Name: ContentType 31 | Type: String 32 | Hidden: False 33 | Static: False 34 | 35 | Parameters 36 | The parameters that were passed to `Invoke-WebRequest`. 37 | 38 | Name: Parameters 39 | Type: System.Collections.Hashtable 40 | Hidden: False 41 | Static: False 42 | 43 | RequestDate 44 | The date the request was made. 45 | 46 | Name: RequestDate 47 | Type: DateTime 48 | Hidden: False 49 | Static: False 50 | 51 | Response 52 | The `Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject` or 53 | `Microsoft.PowerShell.Commands.HtmlWebResponseObject` returned from 54 | `Invoke-WebRequest` 55 | 56 | Name: Response 57 | Type: Microsoft.PowerShell.Commands.WebResponseObject 58 | Hidden: False 59 | Static: False 60 | 61 | METHODS 62 | EXAMPLES 63 | Example 1 64 | [RedditOAuthResponse]@{ 65 | Response = $Response 66 | RequestDate = $Response.Headers.Date[0] 67 | Parameters = $Params 68 | Content = $Response.Content 69 | ContentType = $Response | Get-HttpResponseContentType 70 | } 71 | 72 | This is an example of how the `RedditOAuthResponse` class is used in 73 | `Request-RedditOAuthTokenPassword`. 74 | 75 | SEE ALSO 76 | about_RedditOAuthResponse 77 | Request-RedditOAuthTokenClient 78 | Request-RedditOAuthTokenInstalled 79 | Request-RedditOAuthTokenPassword 80 | about_RedditOAuthToken 81 | Request-RedditOAuthToken 82 | Update-RedditOAuthToken 83 | Invoke-WebRequest 84 | https://github.com/reddit/reddit/wiki/OAuth2 85 | https://psraw.readthedocs.io/ 86 | 87 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditOAuthResponseType.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditoauthresponsetype 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditOAuthResponseType Enum 6 | 7 | LONG DESCRIPTION 8 | The `RedditOAuthResponseType` enumerator represents the available options 9 | for authorization requests made to Reddit. 10 | 11 | FIELDS 12 | Code 13 | Used to request OAuth Authorization Code in Code Flow Token requests 14 | 15 | Token 16 | Used to request OAuth Access Tokens. 17 | 18 | SEE ALSO 19 | about_RedditOAuthResponseType 20 | about_RedditApplication 21 | https://github.com/reddit/reddit/wiki/OAuth2 22 | https://psraw.readthedocs.io/ 23 | 24 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditSubmission.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditsubmission 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditSubmission Class (experimental) 6 | 7 | LONG DESCRIPTION 8 | A `RedditSubmission` object contains the link and comments returned from a 9 | Reddit submission. 10 | 11 | CONSTRUCTORS 12 | RedditSubmission() 13 | Creates an empty `RedditSubmission` object 14 | 15 | [RedditSubmission]::new() 16 | 17 | RedditSubmission(RedditApiResponse ApiResponse) 18 | Creates a `RedditSubmission` from a `RedditApiResponse` returned from 19 | `Invoke-RedditRequest`. 20 | 21 | [RedditSubmission]::new([RedditApiResponse]$ApiResponse) 22 | 23 | PROPERTIES 24 | Comments 25 | An array of comments in reply to the submission. 26 | 27 | Name: Comments 28 | Type: RedditComment[] 29 | Hidden: False 30 | Static: False 31 | 32 | Link 33 | The link or self-post of the submission. 34 | 35 | Name: Link 36 | Type: RedditLink 37 | Hidden: False 38 | Static: False 39 | 40 | METHODS 41 | NOTES 42 | Experimental: This is an experimental feature. Expect radical changes 43 | between versions. Do not write production code against this until it has 44 | been marked stable. 45 | 46 | DERIVED FROM 47 | RedditDataObject 48 | 49 | SEE ALSO 50 | about_RedditSubmission 51 | about_RedditApiResponse 52 | about_RedditComment 53 | about_RedditDataObject 54 | about_RedditLink 55 | https://www.reddit.com/wiki/api 56 | https://github.com/reddit/reddit/wiki/JSON 57 | https://psraw.readthedocs.io/ 58 | 59 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditThingKind.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditthingkind 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditThingKind Enum 6 | 7 | LONG DESCRIPTION 8 | This s used by `RedditThing` objects to determine their kind. 9 | 10 | FIELDS 11 | listing 12 | A listing is a list of Reddit Things 13 | 14 | more 15 | A list of String ids that are the additional things that can be downloaded 16 | but are not because there are too many to list. 17 | 18 | t1 19 | Reddit Comment 20 | 21 | t2 22 | Reddit Account 23 | 24 | t3 25 | Reddit Submission Link 26 | 27 | t4 28 | Reddit Message 29 | 30 | t5 31 | Reddit Subreddit 32 | 33 | t6 34 | Reddit Award 35 | 36 | t8 37 | Reddit Promotion Campaign 38 | 39 | EXAMPLES 40 | Example 1 41 | $Listing = [RedditThingKind]::listing 42 | 43 | SEE ALSO 44 | about_RedditThingKind 45 | about_RedditThing 46 | Invoke-RedditRequest 47 | https://github.com/reddit/reddit/wiki/JSON 48 | https://www.reddit.com/wiki/api 49 | https://psraw.readthedocs.io/ 50 | 51 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditThingPrefix.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_redditthingprefix 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditThingPrefix Enum 6 | 7 | LONG DESCRIPTION 8 | An data object returned from the Reddit API will have a type prefix to 9 | identify what kind of Reddit Thing it is. This is subset of 10 | `RedditThingKind` is only used with data objects such as comments, accounts, 11 | and links and not with collection objects such as `more`s and `listing`s. 12 | 13 | FIELDS 14 | t1 15 | Comment 16 | 17 | t2 18 | Account 19 | 20 | t3 21 | Link 22 | 23 | t4 24 | Message 25 | 26 | t5 27 | Subreddit 28 | 29 | t6 30 | Award 31 | 32 | t8 33 | Promotion campaign 34 | 35 | EXAMPLES 36 | Example 1 37 | $Comment = [RedditThingPrefix]::t1 38 | 39 | SEE ALSO 40 | about_RedditThingPrefix 41 | about_RedditThingKind 42 | about_RedditThing 43 | Invoke-RedditRequest 44 | https://github.com/reddit/reddit/wiki/JSON 45 | https://www.reddit.com/wiki/api 46 | https://psraw.readthedocs.io/ 47 | 48 | -------------------------------------------------------------------------------- /PSRAW/en-US/about_RedditUserReport.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_reddituserreport 3 | 4 | SHORT DESCRIPTION 5 | Describes the RedditUserReport Class 6 | 7 | LONG DESCRIPTION 8 | `RedditUserReport` represent reports made by a users on a link or comment. 9 | These will only be visible to subreddit moderators. 10 | 11 | CONSTRUCTORS 12 | RedditUserReport() 13 | Creates an empty `RedditUserReport` object. 14 | 15 | [RedditUserReport]::new() 16 | 17 | RedditUserReport(Object[] InputObjects) 18 | Creates `RedditUserReport` from an object array 19 | 20 | [RedditUserReport]::new([Object[]]$InputObjects) 21 | 22 | PROPERTIES 23 | Count 24 | The number of times this reason has been reported 25 | 26 | Name: Count 27 | Type: Int64 28 | Hidden: False 29 | Static: False 30 | 31 | Reason 32 | The reason provided by the user(s). 33 | 34 | Name: Reason 35 | Type: String 36 | Hidden: False 37 | Static: False 38 | 39 | METHODS 40 | EXAMPLES 41 | [RedditUserReport]@{ 42 | Reason = 'Spam' 43 | Count = 5 44 | } 45 | 46 | SEE ALSO 47 | about_RedditUserReport 48 | about_RedditComment 49 | about_RedditLink 50 | https://www.reddit.com/wiki/api 51 | https://psraw.readthedocs.io/ 52 | 53 | -------------------------------------------------------------------------------- /PlasterTemplates/NewClass/Class.txt: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: <%=$PLASTER_Date%> <%=$PLASTER_Time%> 6 | Edited on: <%=$PLASTER_Date%> 7 | Created by: <%=$PLASTER_PARAM_AuthorName%> 8 | Organization: <%=$PLASTER_PARAM_AuthorOrg%> 9 | Filename: <%=$PLASTER_PARAM_ClassOrder%>-<%=$PLASTER_PARAM_ClassName%>.ps1 10 | 11 | .DESCRIPTION 12 | <%=$PLASTER_PARAM_ClassName%> Class 13 | #> 14 | Class <%=$PLASTER_PARAM_ClassName%> { 15 | <%=$PLASTER_PARAM_ClassName%> () { } 16 | } -------------------------------------------------------------------------------- /PlasterTemplates/NewClass/plasterManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | NewClass 6 | fb459e00-bf44-4a87-833f-74325dec5e42 7 | 1.0.0 8 | New Class 9 | 10 | Mark Kraus 11 | Class 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /PlasterTemplates/NewFunction/function.txt: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | 4 | Created with: Plaster 5 | Created on: <%=$PLASTER_Date%> <%=$PLASTER_Time%> 6 | Edited on: <%=$PLASTER_Date%> 7 | Created by: <%=$PLASTER_PARAM_AuthorName%> 8 | Organization: <%=$PLASTER_PARAM_AuthorOrg%> 9 | Filename: <%=$PLASTER_PARAM_FunctionName%>.ps1 10 | 11 | .DESCRIPTION 12 | <%=$PLASTER_PARAM_FunctionName%> Function 13 | #> 14 | [CmdletBinding()] 15 | param() 16 | 17 | function <%=$PLASTER_PARAM_FunctionName%> { 18 | [CmdletBinding( 19 | ConfirmImpact = '<%=$PLASTER_PARAM_ConfirmImpact%>', 20 | HelpUri = 'https://psraw.readthedocs.io/en/latest/<%=$PLASTER_PARAM_FunctionScope%>/<%=$PLASTER_PARAM_FunctionName%>', 21 | SupportsShouldProcess = $true 22 | )] 23 | [OutputType([<%=$PLASTER_PARAM_OutputType%>])] 24 | param 25 | ( 26 | 27 | ) 28 | Begin { 29 | 30 | } 31 | Process { 32 | if (-not $PSCmdlet.ShouldProcess("Item")) { 33 | return 34 | } 35 | 36 | } 37 | End { 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /PlasterTemplates/NewFunction/plasterManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | NewFunction 6 | 37b036b5-4474-42c4-9e06-5031908576c7 7 | 1.0.0 8 | New Function 9 | 10 | Mark Kraus 11 | Function, PrivateFunction, PublicFunction 12 | 13 | 14 | 18 | 22 | 27 | 32 | 38 | 42 | 46 | 47 | 53 | 57 | 61 | 65 | 69 | 70 | 75 | 76 | 77 | 81 | 85 | 86 | -------------------------------------------------------------------------------- /Tests/API/Resolve-RedditDataObject.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 9/03/2017 11:02 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Resolve-RedditDataObject.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Resolve-RedditDataObject Function unit tests 14 | #> 15 | Describe "Resolve-RedditDataObject" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | 21 | } 22 | InModuleScope $ModuleName { 23 | $Url = Get-WebListenerUrl -Test 'Subreddit' 24 | Get-TokenScript | Set-RedditDefaultOAuthToken 25 | $Response = Invoke-RedditRequest -Uri $Url 26 | $RedditThing = [RedditThing]$Response.ContentObject 27 | $PSObject = $Response.ContentObject 28 | Context "Test Cases" { 29 | $TestCases = @( 30 | @{ 31 | Name = 'RedditApiResponse' 32 | Params = @{ 33 | RedditAPIResponse = $Response 34 | } 35 | } 36 | @{ 37 | Name = 'RedditThing' 38 | Params = @{ 39 | RedditThing = $RedditThing 40 | } 41 | } 42 | @{ 43 | Name = 'PSObject' 44 | Params = @{ 45 | PSObject = $PSObject 46 | } 47 | } 48 | ) 49 | It "'' Parameter set has no errors" -TestCases $TestCases { 50 | Param($Name, $Params) 51 | $Result = @{} 52 | { $Result['Object'] = Resolve-RedditDataObject @Params -ErrorAction Stop } | 53 | Should Not Throw 54 | $Result.Object | Should Not BeNullOrEmpty 55 | $Result.Object.psobject.typenames.where( { $_ -eq 'RedditListing' }) | 56 | Should Be 'RedditListing' 57 | } 58 | } 59 | Context "Features" { 60 | It "Supports WhatIf" { 61 | 62 | {Resolve-RedditDataObject -RedditThing $RedditThing -WhatIf } | Should Not Throw 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Tests/API/Wait-RedditApiRateLimit.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/18/2017 06:19 PM 7 | Edited on: 9/01/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Wait-RedditApiRateLimit.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Wait-RedditApiRateLimit Function unit tests 14 | #> 15 | 16 | Describe "Wait-RedditApiRateLimit" -Tags Unit, Build { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | 21 | InModuleScope $ModuleName { 22 | $TestCases = @( 23 | @{ 24 | Name = 'Code' 25 | Params = @{ 26 | AccessToken = Get-TokenScript 27 | } 28 | } 29 | @{ 30 | Name = 'Sleep' 31 | Params = @{ 32 | AccessToken = Get-TokenScript 33 | MaxSleepSeconds = 300 34 | } 35 | } 36 | ) 37 | It "'' Parameter set does not have errors" -TestCases $TestCases { 38 | Param($Name, $Params) 39 | { Wait-RedditApiRateLimit @Params -ErrorAction Stop } | Should Not throw 40 | } 41 | It "Emits a 'System.Void' Object" { 42 | (Get-Command Wait-RedditApiRateLimit).OutputType.Name.where( { $_ -eq 'System.Void' }) | Should Be 'System.Void' 43 | } 44 | It "Sleeps when the Token is Rate Limited" { 45 | $AccessToken = Get-TokenScript 46 | $AccessToken.RateLimitRemaining = 0 47 | $AccessToken.RateLimitRest = 3 48 | Measure-Command { 49 | $AccessToken.LastApiCall = Get-Date 50 | $AccessToken | Wait-RedditApiRateLimit 51 | } | Select-Object -ExpandProperty TotalSeconds | Should BeGreaterThan 2 52 | } 53 | It "Sleeps only until MaxSleepSeconds" { 54 | $AccessToken = Get-TokenScript 55 | $AccessToken.RateLimitRemaining = 0 56 | $AccessToken.RateLimitRest = 5 57 | Measure-Command { 58 | $AccessToken.LastApiCall = Get-Date 59 | $AccessToken | Wait-RedditApiRateLimit -MaxSleepSeconds 3 60 | } | Select-Object -ExpandProperty TotalSeconds | Should BeLessThan 5 61 | } 62 | It "Supports WhatIf" { 63 | $AccessToken = Get-TokenScript 64 | $AccessToken.RateLimitRemaining = 0 65 | $AccessToken.RateLimitRest = 5 66 | Measure-Command { 67 | $AccessToken.LastApiCall = Get-Date 68 | $AccessToken | Wait-RedditApiRateLimit -WhatIf 69 | } | Select-Object -ExpandProperty TotalSeconds | Should BeLessThan 1 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Tests/Application/Export-RedditApplication.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 4/30/2017 1:22 PM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Export-RedditApplication.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Export-RedditApplication Function unit tests 14 | #> 15 | 16 | Describe "Export-RedditApplication" -Tags Build, Unit { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | $ExportFile = '{0}\RedditApplicationExport-{1}.xml' -f $TestDrive, [guid]::NewGuid().toString() 22 | $Application = Get-ApplicationScript 23 | $Application.ExportPath = $ExportFile 24 | $TestCases = @( 25 | @{ 26 | Name = 'Path' 27 | Params = @{ 28 | Path = $ExportFile 29 | Application = $Application 30 | } 31 | } 32 | @{ 33 | Name = 'LiteralPath' 34 | Params = @{ 35 | LiteralPath = $ExportFile 36 | Application = $Application 37 | } 38 | } 39 | @{ 40 | Name = 'ExportPath' 41 | Params = @{ 42 | Application = $Application 43 | } 44 | } 45 | ) 46 | } 47 | It "'' Parameter set does not have errors" -TestCases $TestCases { 48 | param($Name, $Params) 49 | { & Export-RedditApplication @Params -ErrorAction Stop } | Should not throw 50 | } 51 | It "Exports a valid XML file." { 52 | Export-RedditApplication -Application $Application -Path $ExportFile 53 | Test-Path -Path $ExportFile | Should Be $True 54 | $xml = New-Object System.Xml.XmlDocument 55 | {$xml.Load($ExportFile)} | should not throw 56 | } 57 | It "Does not store secrets in plaintext" { 58 | Export-RedditApplication -Application $Application -Path $ExportFile 59 | $ExportFile | Should Not Contain $Application.GetClientSecret() 60 | $ExportFile | Should Not Contain $Application.GetUserPassword() 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Tests/Application/Import-RedditApplication.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 05/01/2017 4:43 PM 7 | Edited on: 09/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Import-RedditApplication.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Import-RedditApplication Function unit tests 14 | #> 15 | Describe "Import-RedditApplication" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $ExportFile = '{0}\RedditApplicationExport-{1}.xml' -f $TestDrive, [guid]::NewGuid().toString() 21 | $Application = Get-ApplicationScript 22 | $Application.ExportPath = $ExportFile 23 | $Application | Export-Clixml -Path $ExportFile 24 | $TestCases = @( 25 | @{ 26 | Name = 'Path' 27 | Params = @{ 28 | Path = $ExportFile 29 | } 30 | } 31 | @{ 32 | Name = 'LiteralPath' 33 | Params = @{ 34 | LiteralPath = $ExportFile 35 | } 36 | } 37 | ) 38 | } 39 | It "'' Parameter set does not have errors" -TestCases $TestCases { 40 | param($Name, $Params) 41 | { Import-RedditApplication @Params -ErrorAction Stop } | Should not throw 42 | } 43 | It "Emits a 'RedditApplication' Object" { 44 | (Get-Command Import-RedditApplication).OutputType.Name.where( { $_ -eq 'RedditApplication' }) | Should be 'RedditApplication' 45 | } 46 | It "Returns a 'RedditApplication' Object" { 47 | $Object = Import-RedditApplication -Path $ExportFile | Select-Object -First 1 48 | $Object.psobject.typenames.where( { $_ -eq 'RedditApplication' }) | Should be 'RedditApplication' 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tests/Application/New-RedditApplication.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 4/26/2017 04:40 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: New-RedditApplication.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for New-RedditApplication 14 | #> 15 | Describe "New-RedditApplication Build" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $TestCases = @( 21 | @{ 22 | Name = 'WebApp' 23 | Params = @{ 24 | Name = 'TestApplication' 25 | Description = 'This is only a test' 26 | RedirectUri = 'https://localhost/' 27 | UserAgent = 'windows:PSRAW-Unit-Tests:v1.0.0.0' 28 | Scope = 'read' 29 | ClientCredential = Get-ClientCredential 30 | WebApp = $True 31 | } 32 | } 33 | @{ 34 | Name = 'Script' 35 | Params = @{ 36 | Name = 'TestApplication' 37 | Description = 'This is only a test' 38 | RedirectUri = 'https://localhost/' 39 | UserAgent = 'windows:PSRAW-Unit-Tests:v1.0.0.0' 40 | Scope = 'read' 41 | ClientCredential = Get-ClientCredential 42 | UserCredential = Get-UserCredential 43 | Script = $True 44 | } 45 | } 46 | @{ 47 | Name = 'Installed' 48 | Params = @{ 49 | Name = 'TestApplication' 50 | Description = 'This is only a test' 51 | RedirectUri = 'https://localhost/' 52 | UserAgent = 'windows:PSRAW-Unit-Tests:v1.0.0.0' 53 | Scope = 'read' 54 | ClientCredential = Get-ClientCredential 55 | Installed = $True 56 | } 57 | } 58 | ) 59 | } 60 | It "'' Parameter set does not have errors" -TestCases $TestCases { 61 | param($Name, $Params) 62 | { New-RedditApplication @Params -ErrorAction Stop } | Should not throw 63 | } 64 | It "Emits a 'RedditApplication' Object" { 65 | (Get-Command New-RedditApplication).OutputType.Name.where( { $_ -eq 'RedditApplication' }) | Should be 'RedditApplication' 66 | } 67 | It "Returns a 'RedditApplication' Object" { 68 | $LocalParams = $TestCases[0].Params.psobject.Copy() 69 | $Object = New-RedditApplication @LocalParams | Select-Object -First 1 70 | $Object.psobject.typenames.where( { $_ -eq 'RedditApplication' }) | Should be 'RedditApplication' 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Tests/Classes/001-RedditOAuthScope.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 4/30/2017 10:15 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditOAuthScope.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditOAuthScope Class 14 | #> 15 | 16 | Describe "[RedditOAuthScope] Tests" -Tag Unit, Build { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | } 22 | $TestCases = @( 23 | @{ 24 | Name = 'read' 25 | Hash = @{ 26 | Scope = 'creddits' 27 | Id = 'creddits' 28 | Name = 'Spend reddit gold creddits' 29 | Description = 'Spend my reddit gold creddits on giving gold to other users.' 30 | } 31 | } 32 | ) 33 | It "Converts the '' hash" -TestCases $TestCases { 34 | param($Name, $Hash) 35 | {[RedditOAuthScope]$Hash} | should not throw 36 | } 37 | It "Has a working Uber Constructor." { 38 | { 39 | [RedditOAuthScope]::new( 40 | <#Scope #> 'creddits', 41 | <#Id #> 'creddits', 42 | <#Name #> 'Spend reddit gold creddits', 43 | <#Description #> 'Spend my reddit gold creddits on giving gold to other users.' 44 | ) 45 | } | should not throw 46 | } 47 | It "Has a working GetApiEndpointUri() static method" { 48 | [RedditOAuthScope]::GetApiEndpointUri() | should be 'https://www.reddit.com/api/v1/scopes' 49 | } 50 | It "Has a working ApiEndpointUri static property" { 51 | [RedditOAuthScope]::ApiEndpointUri | should be 'https://www.reddit.com/api/v1/scopes' 52 | } 53 | It "Has a working default constructor" { 54 | {[RedditOAuthScope]::new()} | Should not throw 55 | $EmptyScope = [RedditOAuthScope]::new() 56 | $EmptyScope.Id | should be '' 57 | $EmptyScope.Description | Should be '' 58 | $EmptyScope.Scope | should be '' 59 | $EmptyScope.Name | should be '' 60 | } 61 | It "Converts a [String] to a [RedditOAuthScope]" { 62 | {[RedditOAuthScope]'read'} | should not throw 63 | $ReadScope = [RedditOAuthScope]'read' 64 | $ReadScope.Id | should be 'read' 65 | $ReadScope.Description | Should be 'read' 66 | $ReadScope.Scope | should be 'read' 67 | $ReadScope.Name | should be 'read' 68 | } 69 | } -------------------------------------------------------------------------------- /Tests/Classes/003-RedditOAuthResponse.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 8/2/2017 4:51 PM 7 | Edited on: 09/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditOAuthResponse.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditOAuthResponse Class 14 | #> 15 | Describe "[RedditOAuthResponse] Tests" -Tag Unit, Build { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $Uri = Get-WebListenerUrl -Test Token 21 | $response = Invoke-WebRequest -UseBasicParsing -Uri $Uri 22 | $TestCases = @( 23 | @{ 24 | Name = 'TestHash' 25 | Hash = @{ 26 | Parameters = @{ 27 | ContentType = 'application/json' 28 | Method = 'Default' 29 | Uri = 'https://oauth.reddit.com/api/v1/me' 30 | ErrorAction = 'Stop' 31 | UseBasicParsing = $true 32 | } 33 | RequestDate = $response.Headers.Date[0] 34 | Response = $response 35 | Content = $response.Content 36 | ContentType = 'application/json' 37 | } 38 | } 39 | ) 40 | } 41 | It "Converts the '' hash" -TestCases $TestCases { 42 | Param($Name, $Hash) 43 | {[RedditOAuthResponse]$Hash} | should not throw 44 | } 45 | It "Has a working default constructor" { 46 | {[RedditOAuthResponse]::new()} | Should not throw 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Tests/Classes/005-RedditApiResponse.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/20/2017 1:15 PM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditApiResponse.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditApiResponse Class 14 | #> 15 | 16 | Describe "[RedditApiResponse] Tests" -Tag Unit, Build { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | $Uri = Get-WebListenerUrl -Test 'User' 22 | $response = Invoke-WebRequest -UseBasicParsing -Uri $Uri -SessionVariable 'Session' 23 | $TestCases = @( 24 | @{ 25 | Name = 'TestHash' 26 | Hash = @{ 27 | AccessToken = Get-TokenScript 28 | RequestDate = $response.Headers.Date[0] 29 | Response = $response 30 | ContentObject = $response.Content | ConvertFrom-Json 31 | ContentType = 'application/json' 32 | Parameters = @{ 33 | ContentType = 'application/json' 34 | Method = 'Default' 35 | Uri = $Uri 36 | ErrorAction = 'Stop' 37 | WebSession = $Session 38 | UseBasicParsing = $true 39 | } 40 | } 41 | } 42 | ) 43 | } 44 | It "Converts the '' hash" -TestCases $TestCases { 45 | param($Name, $Hash) 46 | {[RedditApiResponse]$Hash} | should not throw 47 | } 48 | It "Has a working default constructor" { 49 | {[RedditApiResponse]::new()} | Should not throw 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Tests/Classes/006-RedditDataObject.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 8/30/2017 3:54 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditDataObject.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditDataObject Class 14 | #> 15 | 16 | Describe "[RedditDataObject] Tests" -Tag Unit, Build { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | } 22 | It "Has a working default constructor" { 23 | {[RedditDataObject]::new()} | Should not throw 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Tests/Classes/006-RedditDate.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 6/02/2017 4:28 AM 7 | Edited on: 09/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditDate.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditDate Class 14 | #> 15 | 16 | Describe "[RedditDate] Build Tests" -Tag Build, Unit { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | } 22 | It 'Creates a RedditDate from a Unix string' { 23 | $RedditDate = [RedditDate]'31536000' 24 | $RedditDate.Date | should be (get-date '1971/1/1') 25 | $RedditDate.Unix | should be 31536000 26 | } 27 | It 'Creates a RedditDate from a Date string' { 28 | $RedditDate = [RedditDate]'1971/1/1' 29 | $RedditDate.Date | should be (get-date '1971/1/1') 30 | $RedditDate.Unix | should be 31536000 31 | } 32 | It 'Throws when the string cannot be parsed' { 33 | Try { 34 | [RedditDate]'invalid' 35 | } 36 | Catch { 37 | $Exception = $_ 38 | } 39 | $Message = 'Cannot convert value "invalid" to type "RedditDate". Error: "Unable to parse string as System.DateTime or System.Double."' 40 | $Exception.Exception.Message | Should Be $Message 41 | $Exception.Exception.InnerException.InnerException.InnerException | should BeOfType 'System.ArgumentException' 42 | } 43 | It 'Creates a RedditDate from a Double' { 44 | $RedditDate = [RedditDate]31536000.0 45 | $RedditDate.Date | should be (get-date '1971/1/1') 46 | } 47 | It 'Creates a RedditDate from a DateTime' { 48 | $RedditDate = [RedditDate](get-date '1971/1/1') 49 | $RedditDate.Unix | Should be 31536000.0 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Tests/Classes/007-RedditThing.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/29/2017 9:26 PM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditThing.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditThing Class 14 | #> 15 | 16 | Describe "[RedditThing] Tests" -Tag Unit, Build { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | 22 | $Uri = Get-WebListenerUrl -Test 'Submission' 23 | $TokenScript = Get-TokenScript 24 | $Response = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 25 | $Comment = $Response.ContentObject[1].data.children[0] 26 | 27 | $TestCases = @( 28 | @{ 29 | Name = 'TestHash' 30 | Hash = @{ 31 | Kind = 't1' 32 | Name = 'test' 33 | Id = 'test' 34 | Data = [pscustomobject]@{ test = 'test' } 35 | ParentObject = [pscustomobject]@{ test = 'test' } 36 | RedditData = [RedditComment]::New() 37 | } 38 | } 39 | ) 40 | } 41 | It "Converts the '' hash" -TestCases $TestCases { 42 | param($Name, $Hash) 43 | { [RedditThing]$Hash } | should not throw 44 | } 45 | It "Has a working default constructor" { 46 | { [RedditThing]::New() } | Should not throw 47 | } 48 | It "Has a working ([PSObject]`$Object) Constructor" { 49 | {[RedditThing]::new($Comment)} | Should Not Throw 50 | } 51 | It "CreateFrom() converts a [RedditApiResponse] to [RedditThing[]]" { 52 | {[RedditThing]::CreateFrom($Response)} | Should Not Throw 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Tests/Classes/008-RedditHeaderSize.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 9/01/2017 4:17 AM 7 | Edited on: 9/01/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: RedditHeaderSize.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditHeaderSize Class 14 | #> 15 | 16 | Describe "[RedditHeaderSize] Tests" -Tag Unit, Build { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | 22 | $TestCases = @( 23 | @{ 24 | Name = 'TestHash' 25 | Hash = @{ 26 | Width = 5 27 | Height = 10 28 | } 29 | } 30 | ) 31 | } 32 | It "Converts the '' hash" -TestCases $TestCases { 33 | param($Name, $Hash) 34 | { [RedditHeaderSize]$Hash } | should not throw 35 | } 36 | It "Has a working default constructor" { 37 | { [RedditHeaderSize]::New() } | Should not throw 38 | } 39 | It "Has a working ([Object[]]`$InputObjects) constructor" { 40 | $Result = @{} 41 | $InputObject = @(5, 10) 42 | { $Result['object'] = [RedditHeaderSize]::New($InputObject) } | Should not throw 43 | $Result['object'].Width | Should Be 5 44 | $Result['object'].Height | Should Be 10 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Tests/Classes/008-RedditModReport.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 6/02/2017 4:28 AM 7 | Edited on: 9/01/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 008-RedditModReport.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditModReport Class 14 | #> 15 | 16 | Describe "[RedditModReport] Build Tests" -Tag Build, Unit { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | 22 | $TestCases = @( 23 | @{ 24 | Name = 'TestHash' 25 | Hash = @{ 26 | Reason = 'Spam' 27 | Moderator = 'TestMod' 28 | } 29 | } 30 | ) 31 | } 32 | It "Converts the '' hash" -TestCases $TestCases { 33 | param($Name, $Hash) 34 | { [RedditModReport]$Hash } | should not throw 35 | } 36 | It "Has a working default constructor" { 37 | { [RedditModReport]::New() } | Should not throw 38 | } 39 | It "Has a working ([Object[]]`$InputObjects) constructor" { 40 | $Result = @{} 41 | $InputObject = @('Breaks Rule 12', 'markekraus') 42 | { $Result['object'] = [RedditModReport]::New($InputObject) } | Should not throw 43 | $Result['object'].Reason | Should Be 'Breaks Rule 12' 44 | $Result['object'].Moderator | Should Be 'markekraus' 45 | } 46 | } -------------------------------------------------------------------------------- /Tests/Classes/008-RedditUserReport.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 6/02/2017 4:50 AM 7 | Edited on: 9/01/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 008-RedditUserReport.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditUserReport Class 14 | #> 15 | 16 | Describe "[RedditUserReport] Build Tests" -Tag Build, Unit { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | 22 | $TestCases = @( 23 | @{ 24 | Name = 'TestHash' 25 | Hash = @{ 26 | Reason = 'Spam' 27 | Count = 5 28 | } 29 | } 30 | ) 31 | } 32 | It "Converts the '' hash" -TestCases $TestCases { 33 | param($Name, $Hash) 34 | { [RedditUserReport]$Hash } | should not throw 35 | } 36 | It "Has a working default constructor" { 37 | { [RedditUserReport]::New() } | Should not throw 38 | } 39 | It "Has a working ([Object[]]`$InputObjects) constructor" { 40 | $Result = @{} 41 | $InputObject = @('Breaks Rule 12', 5) 42 | { $Result['object'] = [RedditUserReport]::New($InputObject) } | Should not throw 43 | $Result['object'].Reason | Should Be 'Breaks Rule 12' 44 | $Result['object'].Count | Should Be 5 45 | } 46 | } -------------------------------------------------------------------------------- /Tests/Classes/009-RedditLink.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 9/02/2017 8:42 AM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 009-RedditLink.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditLink Class 14 | #> 15 | Describe "[RedditLink] Build Tests" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $TokenScript = Get-TokenScript 21 | $Uri = Get-WebListenerUrl -Test 'Submission' 22 | $Submission = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 23 | $Submission2 = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 24 | $Link1 = [RedditThing]$Submission.ContentObject[0].data.children[0] 25 | $Link2 = [RedditThing]$Submission2.ContentObject[0].data.children[0] 26 | } 27 | Context "RedditLink () Constructor" { 28 | it "Has a default constructor" { 29 | { [RedditLink]::New() } | Should Not Throw 30 | } 31 | } 32 | Context "RedditLink ([RedditThing]`$RedditThing) Constructor" { 33 | It "Throws when a RedditThing is not a Link" { 34 | $Comment = [RedditThing]@{ Kind = 't1'} 35 | { [RedditLink]::New($Comment) } | Should Throw 'Unable to convert RedditThing of kind "t1" to "RedditLink"' 36 | } 37 | It "Converts a RedditThing to a RedditLink" { 38 | $Result = @{} 39 | { $Result['Object'] = [RedditLink]::New($Link1) } | Should Not Throw 40 | $Result.Object.id | should be $Link1.Data.Id 41 | } 42 | It "Automatically adds properties the class does not contain" { 43 | $Params = @{ 44 | MemberType = 'NoteProperty' 45 | Name = 'NewProperty' 46 | Value = 'TestValue' 47 | } 48 | $Link2.Data | Add-Member @Params 49 | $Result = @{} 50 | { $Result['Object'] = [RedditLink]::New($Link2) } | Should Not Throw 51 | $Result.Object.NewProperty | Should be 'TestValue' 52 | } 53 | } 54 | Context "Methods" { 55 | It "Has a GetApiEndpointUri() Method" { 56 | $Link = [RedditLink]::New($Link1) 57 | $result = 'https://oauth.reddit.com/api/info?id=t3_{0}' -f $Link1.Data.id 58 | $Link.GetApiEndpointUri() | Should Be $Result 59 | } 60 | It 'Has a GetFullName() method' { 61 | $Link = [RedditLink]::New($Link1) 62 | $Link.GetFullName() | Should Be $Link1.Data.name 63 | } 64 | It 'Has a ToString() method' { 65 | $Link = [RedditLink]::New($Link1) 66 | $Link.ToString() | Should Match $Link1.Data.Title 67 | $Link.ToString() | Should Match $Link1.Data.subreddit_name_prefixed 68 | $Link.ToString() | Should Match $Link1.Data.author 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Tests/Classes/011-RedditSubmission.Unit.tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 9/02/2017 9:25 AM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 011-RedditSubmission.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditSubmission Class 14 | #> 15 | Describe "[RedditSubmission] Build Tests" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $TokenScript = Get-TokenScript 21 | $Uri = Get-WebListenerUrl -Test 'Submission/Nested' 22 | $Submission1 = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 23 | $Link1 = $Submission1.ContentObject[0].data.children[0].data 24 | $Comment1 = $Submission1.ContentObject[1].data.children[0].data 25 | $Comment2 = $Submission1.ContentObject[1].data.children[1].data 26 | $Comment3 = $Submission1.ContentObject[1].data.children[2].data 27 | } 28 | It "Has a default constructor" { 29 | { [RedditSubmission]::New() } | Should Not Throw 30 | } 31 | It "Converts a RedditApiResponse to RedditSubmission" { 32 | $Result = @{} 33 | { $Result['Object'] = [RedditSubmission]::New($Submission1) } | Should Not Throw 34 | $Result.Object.link.id | should Be $Link1.id 35 | $Result.Object.Comments.Count | Should Be 7 36 | $Result.Object.Comments[0].Id | Should Be $Comment1.Id 37 | $Result.Object.Comments[1].Id | Should Be $Comment2.Id 38 | $Result.Object.Comments[2].Id | Should Be $Comment3.Id 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tests/Classes/012-RedditSubredditUnit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 9/02/2017 11:29 AM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 012-RedditSubreddit.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditSubreddit Class 14 | #> 15 | Describe "[RedditSubreddit] Build Tests" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $TokenScript = Get-TokenScript 21 | $Uri = Get-WebListenerUrl -Test 'Subreddit' 22 | $Response = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 23 | $Subreddit1 = [RedditThing]$Response.ContentObject.data.children[0] 24 | $Response = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 25 | $Subreddit2 = [RedditThing]$Response.ContentObject.data.children[0] 26 | } 27 | Context 'RedditSubreddit () Constructor' { 28 | It "Has a default constructor" { 29 | { [RedditSubreddit]::New() } | Should Not Throw 30 | } 31 | } 32 | Context 'RedditSubreddit ([RedditThing]$RedditThing) Constructor' { 33 | It "Throws when a RedditThing is not a Subreddit" { 34 | $Comment = [RedditThing]@{ Kind = 't1'} 35 | { [RedditSubreddit]::New($Comment) } | Should Throw 'Unable to convert RedditThing of kind "t1" to "RedditSubreddit"' 36 | } 37 | It "Converts a RedditApiResponse to RedditSubreddit" { 38 | $Result = @{} 39 | { $Result['Object'] = [RedditSubreddit]::New($Subreddit1) } | Should Not Throw 40 | $Result.Object.id | should Be $Subreddit1.Data.id 41 | } 42 | It "Automatically adds properties the class does not contain" { 43 | $Params = @{ 44 | MemberType = 'NoteProperty' 45 | Name = 'NewProperty' 46 | Value = 'TestValue' 47 | } 48 | $Subreddit2.Data | Add-Member @Params 49 | $Result = @{} 50 | { $Result['Object'] = [RedditSubreddit]::New($Subreddit2) } | Should Not Throw 51 | $Result.Object.NewProperty | Should be 'TestValue' 52 | } 53 | } 54 | Context "Methods" { 55 | It "Has a GetApiEndpointUri() method" { 56 | $Subreddit = [RedditSubreddit]::New($Subreddit1) 57 | $result = 'https://oauth.reddit.com/api/info?id=t5_{0}' -f $Subreddit1.data.id 58 | $Subreddit.GetApiEndpointUri() | Should Be $result 59 | } 60 | It "Has a GetFullName() method" { 61 | $Subreddit = [RedditSubreddit]::New($Subreddit1) 62 | $Subreddit.GetFullName() | Should Be $Subreddit1.data.name 63 | } 64 | It "Has a ToString() method" { 65 | $Subreddit = [RedditSubreddit]::New($Subreddit1) 66 | $Subreddit.ToString() | Should Match $Subreddit1.Data.url 67 | $Subreddit.ToString() | Should Match $Subreddit1.Data.title 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Tests/Classes/013-RedditMore.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 9/02/2017 11:29 AM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 013-RedditMore.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditMore Class 14 | #> 15 | Describe "[RedditMore] Build Tests" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | } 21 | BeforeEach { 22 | $More = [redditthing][PSCustomObject]@{ 23 | kind = 'more' 24 | data = [PSCustomObject]@{ 25 | count = 2 26 | children = [object[]]@('12345', 'abcde') 27 | name = 't1_54321' 28 | id = '54321' 29 | } 30 | } 31 | } 32 | Context "RedditMore () Constructor" { 33 | It "Has a default constructor" { 34 | { [RedditMore]::New() } | Should Not Throw 35 | } 36 | } 37 | Context "RedditMore ([RedditThing]`$RedditThing) Constructor" { 38 | It "Throws if the ReditThing is not a More" { 39 | $Comment = [RedditThing]@{ 40 | Kind = 't1' 41 | } 42 | { [RedditMore]::New($Comment) } | Should Throw 'Unable to convert RedditThing of kind "t1" to "RedditMore"' 43 | } 44 | it "Converts a RedditThing to a RedditMore" { 45 | $Result = @{} 46 | { $Result['Object'] = [RedditMore]::New($More) } | Should Not Throw 47 | $Result.Object.Count | Should be $More.data.count 48 | $Result.Object.id | Should be $More.data.id 49 | $Result.Object.children[0] | Should be $More.data.children[0] 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Tests/Classes/014-RedditListing.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 6/02/2017 4:50 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: 014-RedditListing.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for RedditListing Class 14 | #> 15 | Describe "[RedditSubreddit] Build Tests" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $TokenScript = Get-TokenScript 21 | $Uri = Get-WebListenerUrl -Test 'Submission/Nested' 22 | $Response = Invoke-RedditRequest -Uri $Uri -AccessToken $TokenScript 23 | $Link = [RedditThing]$Response.ContentObject[0] 24 | $Comments = [RedditThing]$Response.ContentObject[1] 25 | } 26 | Context "RedditListing () Constructor" { 27 | It "Has a Default Constructor" { 28 | { [RedditListing]::New() } | Should Not Throw 29 | } 30 | } 31 | Context 'RedditListing ([RedditThing]$RedditThing)' { 32 | It "Throws when a RedditThing is not a Listing" { 33 | $Comment = [RedditThing]@{ Kind = 't1'} 34 | { [RedditListing]::New($Comment) } | 35 | Should Throw 'Unable to convert RedditThing of kind "t1" to "RedditListing"' 36 | } 37 | It "Converts a RedditThing to a RedditListing" { 38 | $Result = @{} 39 | { $Result['Object'] = [RedditListing]::New()} 40 | } 41 | } 42 | Context "Methods" { 43 | It "Has a GetComments() Method" { 44 | $Listing = [RedditListing]::New($Comments) 45 | $Result = @{} 46 | { $Result["Object"] = $Listing.GetComments() } | Should Not Throw 47 | $Result.Object.Count | Should Be 3 48 | } 49 | It "Has a GetMores() Method" { 50 | $Listing = [RedditListing]::New($Comments) 51 | $Result = @{} 52 | { $Result["Object"] = $Listing.GetMores() } | Should Not Throw 53 | $Result.Object.Count | Should Be 1 54 | } 55 | It "Has a GetLinks() Method" { 56 | $Listing = [RedditListing]::New($Link) 57 | $Result = @{} 58 | { $Result["Object"] = $Listing.GetLinks() } | Should Not Throw 59 | $Result.Object.Count | Should Be 1 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Tests/HTTP/Get-HttpResponseContentType.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 8/01/2017 3:37 PM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Get-HttpResponseContentType.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Get-HttpResponseContentType Function unit tests 14 | #> 15 | Describe 'Get-HttpResponseContentType' -Tag Unit, Build { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | } 21 | InModuleScope $ModuleName { 22 | It 'Returns a valid content-type string for a provided WebResponse' { 23 | $uri = Get-WebListenerUrl -Test 'Get' 24 | $Response = Invoke-WebRequest -Uri $uri 25 | $Response | Get-HttpResponseContentType | 26 | Should Match 'application/json' 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tests/OAuth/Connect-Reddit.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/18/2017 4:31 AM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Connect-Reddit.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Connect-Reddit Function unit tests 14 | #> 15 | Describe "Connect-Reddit" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $OriginalAuthBaseURL = [RedditOAuthToken]::AuthBaseURL 21 | # Tricks Request-RedditOAuthToken into using WebListener 22 | [RedditOAuthToken]::AuthBaseURL = Get-WebListenerUrl -Test 'Token' 23 | } 24 | AfterAll { 25 | [RedditOAuthToken]::AuthBaseURL = $OriginalAuthBaseURL 26 | } 27 | Mock -CommandName Read-Host -ModuleName $ModuleName -MockWith { 28 | $ClientId = '54321' 29 | $ClientSecret = '12345' 30 | $SecClientSecret = $ClientSecret | ConvertTo-SecureString -AsPlainText -Force 31 | $UserId = 'reddituser' 32 | $UserSecret = 'password' 33 | $SecUserSecret = $UserSecret | ConvertTo-SecureString -AsPlainText -Force 34 | $RedirectUri = 'https://localhost/' 35 | Switch -Regex ($Prompt) { 36 | 'Client ID' { 37 | $Output = $ClientId; break 38 | } 39 | 'Client Secret' { 40 | $Output = $SecClientSecret; break 41 | } 42 | 'User ID' { 43 | $Output = $UserId; break 44 | } 45 | 'Password' { 46 | $Output = $SecUserSecret; break 47 | } 48 | 'Redirect' { 49 | $Output = $RedirectUri; break 50 | } 51 | Default { 52 | Throw "Unknown Prompt: $_" 53 | } 54 | } 55 | return $Output 56 | } 57 | It "Runs without error" { 58 | { Connect-Reddit } | Should Not Throw 59 | } 60 | } -------------------------------------------------------------------------------- /Tests/OAuth/Export-RedditOAuthToken.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 4/30/2017 1:22 PM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Export-RedditOAuthToken.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Export-RedditOAuthToken Function unit tests 14 | #> 15 | Describe "Export-RedditOAuthToken Build" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $Module = Get-Module -Name $ModuleName 21 | $TokenExportFile = '{0}\RedditTokenExport.xml' -f $TestDrive 22 | $TokenScript = Get-TokenScript 23 | $TokenScript.ExportPath = $TokenExportFile 24 | $TestCases = @( 25 | @{ 26 | Name = 'Path' 27 | Params = @{ 28 | Path = $TokenExportFile 29 | AccessToken = $TokenScript 30 | } 31 | } 32 | @{ 33 | Name = 'LiteralPath' 34 | Params = @{ 35 | LiteralPath = $TokenExportFile 36 | AccessToken = $TokenScript 37 | } 38 | } 39 | @{ 40 | Name = 'ExportPath' 41 | Params = @{ 42 | AccessToken = $TokenScript 43 | } 44 | } 45 | ) 46 | } 47 | Context "Test cases" { 48 | It "'' Parameter set does not have errors" -TestCases $TestCases { 49 | param ($Name, $Params) 50 | { Export-RedditOAuthToken @Params -ErrorAction Stop } | Should not throw 51 | } 52 | } 53 | Context "Features" { 54 | It "Exports a valid XML file." { 55 | $TokenScript | Export-RedditOAuthToken 56 | Test-Path -Path $TokenExportFile | Should Be $True 57 | $xml = [System.Xml.XmlDocument]::new() 58 | { $xml.Load($TokenExportFile) } | should not throw 59 | } 60 | It "Does not store secrets in plaintext" { 61 | $TokenScript | Export-RedditOAuthToken 62 | $Params = @{ 63 | Path = $TokenExportFile 64 | SimpleMatch = $true 65 | Pattern = $TokenScript.GetAccessToken() 66 | } 67 | Select-String @Params | should be $null 68 | } 69 | It "Exports the default Token when one is not supplied" { 70 | $TokenScript | Set-RedditDefaultOAuthToken 71 | { Export-RedditOAuthToken -Path $TokenExportFile -ErrorAction Stop } | 72 | Should not throw 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Tests/OAuth/Get-AuthorizationHeader.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/07/2017 8:30 PM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Get-AuthorizationHeader.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Get-AuthorizationHeader Function unit tests 14 | #> 15 | Describe "Get-AuthorizationHeader" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | } 21 | InModuleScope $ModuleName { 22 | It 'Returns an rfc2617 Authorization header' { 23 | Get-AuthorizationHeader -Credential (Get-ClientCredential) | 24 | Should Be 'Basic NTQzMjE6MDgyMzk4NDItYTZmNS00ZmU1LWFiNGMtNDU5MjA4NGFkNDRl' 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/OAuth/Get-RedditDefaultOAuthToken.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 8/12/2017 8:10 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Get-RedditDefaultOAuthToken.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Get-RedditDefaultOAuthToken Function unit tests 14 | #> 15 | Describe "Get-RedditDefaultOAuthToken" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | } 21 | It "Runs without error" { 22 | { Get-RedditDefaultOAuthToken } | Should Not Throw 23 | } 24 | It "Returns the default token" { 25 | $TokenScript = Get-TokenScript 26 | $TokenScript | Set-RedditDefaultOAuthToken 27 | $Result = Get-RedditDefaultOAuthToken 28 | $Result.GUID | Should Be $TokenScript.GUID 29 | } 30 | It "Supports what if" { 31 | { Get-RedditDefaultOAuthToken -WhatIf } | Should Not Throw 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tests/OAuth/Get-RedditOAuthScope.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 4/23/2017 04:40 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Get-RedditOAuthScope.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Unit Tests for Get-RedditOAuthScope 14 | #> 15 | 16 | Describe "Get-RedditOAuthScope" -Tags Build, Unit { 17 | BeforeAll { 18 | Initialize-PSRAWTest 19 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 20 | Import-Module -force $ModulePath 21 | # Tricks Get-RedditOAuthScope into using WebListener 22 | $OriginalApiEndpointUri = [RedditOAuthScope]::ApiEndpointUri 23 | [RedditOAuthScope]::ApiEndpointUri = Get-WebListenerUrl -Test 'Scope' 24 | } 25 | AfterAll { 26 | [RedditOAuthScope]::ApiEndpointUri = $OriginalApiEndpointUri 27 | } 28 | It 'Does not have errors when passed required parameters' { 29 | { Get-RedditOAuthScope -ErrorAction Stop } | Should not throw 30 | } 31 | It "Emits a 'RedditOAuthScope' Object" { 32 | (Get-Command Get-RedditOAuthScope).OutputType.Name.where( { $_ -eq 'RedditOAuthScope' }) | Should be 'RedditOAuthScope' 33 | } 34 | It "Returns a 'RedditOAuthScope' Object" { 35 | $Object = Get-RedditOAuthScope | Select-Object -First 1 36 | $Object.psobject.typenames.where( { $_ -eq 'RedditOAuthScope' }) | Should be 'RedditOAuthScope' 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Tests/OAuth/Import-RedditOAuthToken.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 05/11/2017 4:41 AM 7 | Edited on: 09/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Import-RedditOAuthToken.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Import-RedditOAuthToken Function unit tests 14 | #> 15 | Describe "Import-RedditOAuthToken" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $Module = Get-Module $ModuleName 21 | $TokenExportFile = '{0}\RedditTokenExport.xml' -f $TestDrive 22 | $TokenScript = Get-TokenScript 23 | $TokenScript | Export-Clixml -Path $TokenExportFile 24 | $TestCases = @( 25 | @{ 26 | Name = 'Path' 27 | Params = @{ 28 | Path = $TokenExportFile 29 | } 30 | } 31 | @{ 32 | Name = 'LiteralPath' 33 | Params = @{ 34 | LiteralPath = $TokenExportFile 35 | } 36 | } 37 | @{ 38 | Name = 'Path PassThru' 39 | Params = @{ 40 | Path = $TokenExportFile 41 | PassThru = $true 42 | } 43 | } 44 | @{ 45 | Name = 'LiteralPath PassThru' 46 | Params = @{ 47 | LiteralPath = $TokenExportFile 48 | PassThru = $true 49 | } 50 | } 51 | ) 52 | } 53 | Context "Test Cases" { 54 | It "'' Parameter set does not have errors" -TestCases $TestCases { 55 | Param($Name, $Params) 56 | { Import-RedditOAuthToken @Params -ErrorAction Stop } | Should not throw 57 | } 58 | } 59 | Context "Features" { 60 | It "Emits a 'RedditOAuthToken' Object" { 61 | (Get-Command Import-RedditOAuthToken). 62 | OutputType.Name.where( { $_ -eq 'RedditOAuthToken' }) | 63 | Should be 'RedditOAuthToken' 64 | } 65 | It "Returns a 'RedditOAuthToken' Object with -PassThru" { 66 | $Object = Import-RedditOAuthToken -Path $TokenExportFile -PassThru | Select-Object -First 1 67 | $Object.psobject.typenames.where( { $_ -eq 'RedditOAuthToken' }) | 68 | Should be 'RedditOAuthToken' 69 | } 70 | It "Sets the imported token as the default token" { 71 | & $Module { $PsrawSettings.AccessToken = $null } 72 | & $Module { $PsrawSettings.AccessToken } | Should BeNullOrEmpty 73 | { Import-RedditOAuthToken -Path $TokenExportFile -ErrorAction Stop } | Should not throw 74 | & $Module { $PsrawSettings.AccessToken.GUID } | Should Be $TokenScript.GUID 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Tests/OAuth/Request-RedditOAuthTokenClient.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/07/2017 8:50 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Request-RedditOAuthTokenClient.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Request-RedditOAuthTokenClient Function unit tests 14 | #> 15 | Describe "Request-RedditOAuthTokenClient" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $OriginalAuthBaseURL = [RedditOAuthToken]::AuthBaseURL 21 | # Tricks Request-RedditOAuthTokenClient into using WebListener 22 | [RedditOAuthToken]::AuthBaseURL = Get-WebListenerUrl -Test 'Token' 23 | } 24 | AfterAll { 25 | [RedditOAuthToken]::AuthBaseURL = $OriginalAuthBaseURL 26 | } 27 | InModuleScope $ModuleName { 28 | Context "Test Cases" { 29 | $TestCases = @( 30 | @{ 31 | Name = 'Script' 32 | Params = @{ 33 | Application = Get-ApplicationScript 34 | } 35 | } 36 | @{ 37 | Name = 'WebApp' 38 | Params = @{ 39 | Application = Get-ApplicationWebApp 40 | } 41 | } 42 | ) 43 | It "'' Parameter set does not have errors" -TestCases $TestCases { 44 | Param($Name, $Params) 45 | { Request-RedditOAuthTokenClient @Params -ErrorAction Stop } | Should not throw 46 | } 47 | } 48 | Context "Features" { 49 | It "Emits a 'RedditOAuthResponse' Object" { 50 | (Get-Command Request-RedditOAuthTokenClient). 51 | OutputType.Name.where( { $_ -eq 'RedditOAuthResponse' }) | 52 | Should be 'RedditOAuthResponse' 53 | } 54 | It "Returns a 'RedditOAuthResponse' Object" { 55 | $ApplicationScript = Get-ApplicationScript 56 | $Object = Request-RedditOAuthTokenClient -Application $ApplicationScript | 57 | Select-Object -First 1 58 | $Object.psobject.typenames.where( { $_ -eq 'RedditOAuthResponse' }) | 59 | Should be 'RedditOAuthResponse' 60 | } 61 | It "Does not support 'Installed' apps" { 62 | $ApplicationInstalled = Get-ApplicationInstalled 63 | { Request-RedditOAuthTokenClient -Application $ApplicationInstalled -ErrorAction Stop } | 64 | Should throw "RedditApplicationType must be 'Script' or 'WebApp" 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Tests/OAuth/Request-RedditOAuthTokenPassword.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 5/07/2017 11:50 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Request-RedditOAuthTokenPassword.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Request-RedditOAuthTokenPassword Function unit tests 14 | #> 15 | Describe "Request-RedditOAuthTokenPassword" -Tag Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $OriginalAuthBaseURL = [RedditOAuthToken]::AuthBaseURL 21 | # Tricks Request-RedditOAuthTokenPassword into using WebListener 22 | [RedditOAuthToken]::AuthBaseURL = Get-WebListenerUrl -Test 'Token' 23 | } 24 | AfterAll { 25 | [RedditOAuthToken]::AuthBaseURL = $OriginalAuthBaseURL 26 | } 27 | InModuleScope $ModuleName { 28 | Context "Test Cases" { 29 | $TestCases = @( 30 | @{ 31 | Name = 'Script' 32 | Params = @{ 33 | Application = Get-ApplicationScript 34 | } 35 | } 36 | ) 37 | It "'' Parameter set does not have errors" -TestCases $TestCases { 38 | Param($Name, $Params) 39 | { Request-RedditOAuthTokenPassword @Params -ErrorAction Stop } | Should not throw 40 | } 41 | } 42 | Context "Features" { 43 | It "Emits a 'RedditOAuthResponse' Object" { 44 | (Get-Command Request-RedditOAuthTokenPassword). 45 | OutputType.Name.where( { $_ -eq 'RedditOAuthResponse' }) | 46 | Should be 'RedditOAuthResponse' 47 | } 48 | It "Returns a 'RedditOAuthResponse' Object" { 49 | $ApplicationScript = Get-ApplicationScript 50 | $Object = Request-RedditOAuthTokenPassword -Application $ApplicationScript | 51 | Select-Object -First 1 52 | $Object.psobject.typenames.where( { $_ -eq 'RedditOAuthResponse' }) | 53 | Should be 'RedditOAuthResponse' 54 | } 55 | It "Does not support 'Installed' apps" { 56 | $ApplicationInstalled = Get-ApplicationInstalled 57 | { Request-RedditOAuthTokenPassword -Application $ApplicationInstalled -ErrorAction Stop } | 58 | Should throw "RedditApplicationType must be 'Script'" 59 | } 60 | It "Does not support 'WebApp' apps" { 61 | $ApplicationWebApp = Get-ApplicationWebApp 62 | { Request-RedditOAuthTokenPassword -Application $ApplicationWebApp -ErrorAction Stop } | 63 | Should throw "RedditApplicationType must be 'Script'" 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /Tests/OAuth/Set-RedditDefaultOAuthToken.Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 8/12/2017 8:16 AM 7 | Edited on: 9/02/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Set-RedditDefaultOAuthToken.Unit.Tests.ps1 11 | 12 | .DESCRIPTION 13 | Set-RedditDefaultOAuthToken Function unit tests 14 | #> 15 | Describe "Set-RedditDefaultOAuthToken" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | } 21 | BeforeEach { 22 | $TokenScript = Get-TokenScript 23 | } 24 | It "Runs without error" { 25 | { $TokenScript | Set-RedditDefaultOAuthToken } | Should Not Throw 26 | } 27 | It "Returns the default token" { 28 | $TokenScript | Set-RedditDefaultOAuthToken 29 | $Result = Get-RedditDefaultOAuthToken 30 | $Result.GUID | Should Be $TokenScript.GUID 31 | } 32 | It "Supports what if" { 33 | { $TokenScript | Set-RedditDefaultOAuthToken -WhatIf } | Should Not Throw 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/PSScriptAnalyzer.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.135 6 | Created on: 2/28/2017 11:49 AM 7 | Edited on: 9/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: PSScriptAnalyzer.tests.Ps1 11 | 12 | .DESCRIPTION 13 | Runs PSScriptAnalyzer tests for every rule against every file in the module 14 | #> 15 | Describe "PSScriptAnalyzer Tests" -Tags Build { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | Import-Module -force $ModulePath 20 | $Params = @{ 21 | Path = $ModuleRoot 22 | Severity = @('Error', 'Warning') 23 | Recurse = $true 24 | Verbose = $false 25 | ErrorVariable = 'ErrorVariable' 26 | ErrorAction = 'SilentlyContinue' 27 | } 28 | $ScriptWarnings = Invoke-ScriptAnalyzer @Params 29 | $scripts = Get-ChildItem $ModuleRoot -Include *.ps1, *.psm1 -Recurse 30 | } 31 | foreach ($Script in $scripts) { 32 | $RelPath = $Script.FullName.Replace($ModuleRoot, '') -replace '^\\', '' 33 | Context "$RelPath" { 34 | $Rules = $ScriptWarnings | 35 | Where-Object {$_.ScriptPath -like $Script.FullName} | 36 | Select-Object -ExpandProperty RuleName -Unique 37 | foreach ($rule in $Rules) { 38 | It "Passes $rule" { 39 | $BadLines = $ScriptWarnings | 40 | Where-Object {$_.ScriptPath -like $Script.FullName -and $_.RuleName -like $rule} | 41 | Select-Object -ExpandProperty Line 42 | $BadLines | should be $null 43 | } 44 | } 45 | $Exceptions = $ErrorVariable.Exception.Message | 46 | Where-Object {$_ -match [regex]::Escape($Script.FullName)} 47 | foreach ($Exception in $Exceptions) { 48 | it 'Has no parse errors' { 49 | $Exception | should be $null 50 | } 51 | break 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Tests/Project.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Test must be run with Start-PSRAWPester 4 | 5 | Created with: VSCode 6 | Created on: 04/23/2017 12:06 PM 7 | Edited on: 09/03/2017 8 | Created by: Mark Kraus 9 | Organization: 10 | Filename: Project.Tests.ps1 11 | 12 | .DESCRIPTION 13 | General Pester Tests for the project 14 | #> 15 | Describe "General project validation: PSRAW" -Tags Build, Unit { 16 | BeforeAll { 17 | Initialize-PSRAWTest 18 | Remove-Module $ModuleName -Force -ErrorAction SilentlyContinue 19 | } 20 | It "Module '$ModuleName' can import cleanly" { 21 | { Import-Module $ModulePath -force } | Should Not Throw 22 | } 23 | Import-Module $ModulePath -force 24 | It "Module '$ModuleName' Imports Functions" { 25 | Get-Command -Module $ModuleName | 26 | Measure-Object | 27 | Select-Object -ExpandProperty Count | 28 | Should BeGreaterThan 0 29 | } 30 | } -------------------------------------------------------------------------------- /Tests/tools/Modules/WebListener/WebListener.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | ModuleVersion = '1.0.0' 3 | GUID = '90572e25-3f15-49b0-8f25-fb717d3ef46a' 4 | Author = 'Mark Kraus' 5 | Description = 'An HTTP Listener for testing purposes' 6 | RootModule = 'WebListener.psm1' 7 | FunctionsToExport = @( 8 | 'Get-WebListener' 9 | 'Get-WebListenerUrl' 10 | 'Start-WebListener' 11 | 'Stop-WebListener' 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/EchoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using mvc.Models; 9 | 10 | namespace mvc.Controllers 11 | { 12 | public class EchoController : Controller 13 | { 14 | public ContentResult Index(string Body) 15 | { 16 | Response.Headers.Clear(); 17 | foreach (var key in Request.Query.Keys) 18 | { 19 | if(key.ToLower() == "body") 20 | { 21 | continue; 22 | } 23 | if (key.ToLower() == "statuscode") 24 | { 25 | Response.StatusCode = int.Parse(Request.Query[key]); 26 | continue; 27 | } 28 | Response.Headers.Add(key,Request.Query[key]); 29 | } 30 | return Content(Body); 31 | } 32 | public IActionResult Error() 33 | { 34 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/GetController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.AspNetCore.Http.Extensions; 9 | using mvc.Models; 10 | 11 | namespace mvc.Controllers 12 | { 13 | public class GetController : Controller 14 | { 15 | public JsonResult Index() 16 | { 17 | Hashtable args = new Hashtable(); 18 | foreach (var key in Request.Query.Keys) 19 | { 20 | args.Add(key,Request.Query[key]); 21 | } 22 | Hashtable headers = new Hashtable(); 23 | foreach (var key in Request.Headers.Keys) 24 | { 25 | headers.Add(key,Request.Headers[key]); 26 | } 27 | Hashtable output = new Hashtable 28 | { 29 | {"args" , args}, 30 | {"headers", headers}, 31 | {"origin", Request.HttpContext.Connection.RemoteIpAddress.ToString()}, 32 | {"url", UriHelper.GetDisplayUrl(Request)} 33 | }; 34 | return Json(output); 35 | } 36 | public IActionResult Error() 37 | { 38 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using mvc.Models; 8 | 9 | namespace mvc.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | return View(); 16 | } 17 | public IActionResult Error() 18 | { 19 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/ScopeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using mvc.Models; 8 | 9 | namespace mvc.Controllers 10 | { 11 | public class ScopeController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | Response.ContentType = "application/json"; 16 | return View(); 17 | } 18 | 19 | public IActionResult Error() 20 | { 21 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/StatusCodeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using mvc.Models; 9 | 10 | namespace mvc.Controllers 11 | { 12 | public class StatusCodeController : Controller 13 | { 14 | public JsonResult Index(Int32 StatusCode) 15 | { 16 | Response.StatusCode = StatusCode; 17 | Hashtable output = new Hashtable 18 | { 19 | {"StatusCode" , StatusCode}, 20 | }; 21 | return Json(output); 22 | } 23 | public IActionResult Error() 24 | { 25 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/SubmissionController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using mvc.Models; 8 | 9 | namespace mvc.Controllers 10 | { 11 | public class SubmissionController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | Response.ContentType = "application/json"; 16 | return View(); 17 | } 18 | 19 | public IActionResult Nested() 20 | { 21 | Response.ContentType = "application/json"; 22 | return View(); 23 | } 24 | 25 | public IActionResult Error() 26 | { 27 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/SubredditController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using mvc.Models; 8 | 9 | namespace mvc.Controllers 10 | { 11 | public class SubredditController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | Response.ContentType = "application/json"; 16 | return View(); 17 | } 18 | 19 | public IActionResult Error() 20 | { 21 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/TokenController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using mvc.Models; 9 | 10 | namespace mvc.Controllers 11 | { 12 | public class TokenController : Controller 13 | { 14 | static public Hashtable tokenObject = new Hashtable 15 | { 16 | {"access_token", "3fdd9e66-eaaa-4263-a834-a33cff22886e"}, 17 | {"token_type" , "bearer"}, 18 | {"expires_in" , 3600}, 19 | {"scope" , "*"} 20 | }; 21 | 22 | static public Hashtable tokenInstalledObject = new Hashtable 23 | { 24 | {"access_token", "3fdd9e66-eaaa-4263-a834-a33cff22886e"}, 25 | {"token_type" , "bearer"}, 26 | {"expires_in" , 3600}, 27 | {"scope" , "*"}, 28 | {"device_id" , "06383696-d7cd-47ac-a5ce-45330c251215"} 29 | }; 30 | 31 | public JsonResult Index() 32 | { 33 | return Json(tokenObject); 34 | } 35 | 36 | public JsonResult Installed(string device_id) 37 | { 38 | Hashtable response; 39 | if (String.IsNullOrEmpty(device_id)) 40 | { 41 | response = tokenInstalledObject; 42 | } 43 | else 44 | { 45 | response = new Hashtable 46 | { 47 | {"access_token", System.Guid.NewGuid().ToString()}, 48 | {"token_type" , "bearer"}, 49 | {"expires_in" , 3600}, 50 | {"scope" , "*"}, 51 | {"device_id" , device_id} 52 | }; 53 | } 54 | return Json(response); 55 | } 56 | 57 | public JsonResult New() 58 | { 59 | Hashtable newToken = new Hashtable 60 | { 61 | {"access_token", System.Guid.NewGuid().ToString()}, 62 | {"token_type" , "bearer"}, 63 | {"expires_in" , 3600}, 64 | {"scope" , "*"} 65 | }; 66 | return Json(newToken); 67 | } 68 | 69 | public IActionResult Error() 70 | { 71 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc; 8 | using mvc.Models; 9 | 10 | namespace mvc.Controllers 11 | { 12 | public class UserController : Controller 13 | { 14 | static public Hashtable userObject = new Hashtable 15 | { 16 | {"comment_karma" , 0}, 17 | {"created" , 1389649907.0}, 18 | {"created_utc" , 1389649907.0}, 19 | {"has_mail" , false}, 20 | {"has_mod_mail" , false}, 21 | {"has_verified_email", null}, 22 | {"id" , "1"}, 23 | {"is_gold" , false}, 24 | {"is_mod" , true}, 25 | {"link_karma" , 1}, 26 | {"name" ,"reddit_bot"}, 27 | {"over_18" , true} 28 | }; 29 | 30 | public JsonResult Index() 31 | { 32 | return Json(userObject); 33 | } 34 | public IActionResult Error() 35 | { 36 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace mvc.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Security.Authentication; 7 | using System.Security.Cryptography.X509Certificates; 8 | using System.Threading.Tasks; 9 | using Microsoft.AspNetCore; 10 | using Microsoft.AspNetCore.Hosting; 11 | using Microsoft.AspNetCore.Server.Kestrel.Https; 12 | using Microsoft.Extensions.Configuration; 13 | using Microsoft.Extensions.Logging; 14 | 15 | 16 | 17 | namespace mvc 18 | { 19 | public class Program 20 | { 21 | public static void Main(string[] args) 22 | { 23 | if (args.Count() != 1) 24 | { 25 | System.Console.WriteLine("Required: "); 26 | Environment.Exit(1); 27 | } 28 | BuildWebHost(args).Run(); 29 | } 30 | 31 | public static IWebHost BuildWebHost(string[] args) => 32 | WebHost.CreateDefaultBuilder() 33 | .UseStartup().UseKestrel(options => 34 | { 35 | options.Listen(IPAddress.Loopback, int.Parse(args[0])); 36 | }) 37 | .Build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/README.md: -------------------------------------------------------------------------------- 1 | # WebListener App 2 | 3 | ASP.NET Core 2.0 app for testing HTTP Requests. The default page will return a list of available tests. 4 | 5 | # Run with `dotnet` 6 | 7 | ``` 8 | dotnet restore 9 | dotnet publish --output bin --configuration Release 10 | cd bin 11 | dotnet WebListener.dll 8080 12 | ``` 13 | 14 | The test site can then be accessed via `http://localhost:8080/` 15 | 16 | The `WebListener.dll` takes 1 arguments: 17 | 18 | * The TCP Port to bind on for HTTP 19 | 20 | # Run With WebListener Module 21 | 22 | ```powershell 23 | . .\BuildTools\build.ps1 -Task BuildTestTools 24 | $Listener = Start-WebListener -HttpPort 8080 25 | ``` 26 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace mvc 11 | { 12 | public class Startup 13 | { 14 | public Startup(IConfiguration configuration) 15 | { 16 | Configuration = configuration; 17 | } 18 | 19 | public IConfiguration Configuration { get; } 20 | 21 | // This method gets called by the runtime. Use this method to add services to the container. 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | services.AddMvc(); 25 | } 26 | 27 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 28 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 29 | { 30 | if (env.IsDevelopment()) 31 | { 32 | app.UseDeveloperExceptionPage(); 33 | } 34 | else 35 | { 36 | app.UseExceptionHandler("/Home/Error"); 37 | } 38 | 39 | app.UseStaticFiles(); 40 | 41 | app.UseMvc(routes => 42 | { 43 | routes.MapRoute( 44 | name: "default", 45 | template: "{controller=Home}/{action=Index}/{id?}"); 46 | }); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | 

Available Tests

2 |
16 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 22 |

23 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | @RenderBody() 2 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Views/Subreddit/Index.cshtml: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "Listing", 3 | "data": { 4 | "children": [ 5 | { 6 | "kind": "t5", 7 | "data": { 8 | "banner_img": "", 9 | "user_sr_theme_enabled": true, 10 | "user_flair_text": null, 11 | "submit_text_html": "<!-- SC_OFF --><div class=\"md\"><p>Check yo shizzle</p>\n</div><!-- SC_ON -->", 12 | "user_is_banned": false, 13 | "wiki_enabled": true, 14 | "show_media": true, 15 | "id": "343lw", 16 | "display_name_prefixed": "r/MarksDebuggingSub", 17 | "submit_text": "Check yo shizzle", 18 | "user_can_flair_in_sr": null, 19 | "display_name": "MarksDebuggingSub", 20 | "header_img": null, 21 | "description_html": "<!-- SC_OFF --><div class=\"md\"><p>Rules? Just one: do as I say when I say.</p>\n</div><!-- SC_ON -->", 22 | "title": "Sub for debugging various Reddit and RES issues", 23 | "collapse_deleted_comments": true, 24 | "user_has_favorited": false, 25 | "over18": false, 26 | "public_description_html": "<!-- SC_OFF --><div class=\"md\"><p>What are you doing with your life?</p>\n</div><!-- SC_ON -->", 27 | "spoilers_enabled": true, 28 | "icon_size": null, 29 | "audience_target": "", 30 | "suggested_comment_sort": null, 31 | "active_user_count": null, 32 | "icon_img": "", 33 | "header_title": null, 34 | "description": "Rules? Just one: do as I say when I say.", 35 | "user_is_muted": false, 36 | "submit_link_label": null, 37 | "accounts_active": null, 38 | "public_traffic": false, 39 | "header_size": null, 40 | "subscribers": 4, 41 | "user_flair_css_class": null, 42 | "submit_text_label": null, 43 | "whitelist_status": null, 44 | "user_sr_flair_enabled": null, 45 | "lang": "en", 46 | "user_is_moderator": true, 47 | "is_enrolled_in_new_modmail": false, 48 | "key_color": "", 49 | "name": "t5_343lw", 50 | "user_flair_enabled_in_sr": false, 51 | "created": 1413720120, 52 | "url": "/r/MarksDebuggingSub/", 53 | "quarantine": false, 54 | "hide_ads": false, 55 | "created_utc": 1413691320, 56 | "banner_size": null, 57 | "user_is_contributor": true, 58 | "accounts_active_is_fuzzed": false, 59 | "advertiser_category": null, 60 | "public_description": "What are you doing with your life?", 61 | "link_flair_enabled": false, 62 | "allow_images": true, 63 | "show_media_preview": true, 64 | "comment_score_hide_mins": 0, 65 | "subreddit_type": "restricted", 66 | "submission_type": "any", 67 | "user_is_subscriber": true 68 | } 69 | } 70 | ], 71 | "after": null, 72 | "before": null 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using mvc 2 | @using mvc.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/WebListener.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | A simple ASP.NET Core 2.0 MVC app to provide an HTTP server for testing. 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Tests/tools/WebListener/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /docs/Examples/images/quickstart-01.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markekraus/PSRAW/d93ca99d5bbf6ea924c3ba4f419ef394581b6e64/docs/Examples/images/quickstart-01.PNG -------------------------------------------------------------------------------- /docs/Examples/images/quickstart-02.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markekraus/PSRAW/d93ca99d5bbf6ea924c3ba4f419ef394581b6e64/docs/Examples/images/quickstart-02.PNG -------------------------------------------------------------------------------- /docs/Module/Get-RedditDefaultOAuthToken.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSRAW-help.xml 3 | Module Name: PSRAW 4 | online version: https://psraw.readthedocs.io/en/latest/Module/Get-RedditDefaultOAuthToken 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-RedditDefaultOAuthToken 9 | 10 | ## SYNOPSIS 11 | Retrieves the session default OAuth Token 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-RedditDefaultOAuthToken [-WhatIf] [-Confirm] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | A session default OAuth Token is set by `Set-RedditDefaultOAuthToken`, `Connect-Reddit`, `Import-RedditOAuthToken`, `Request-RedditOAuthToken`, and `Update-RedditOAuthToken` (with the `-SetDefault` parameter) all set the default session OAuth Token. The `Get-RedditDefaultOAuthToken` can be used to retrieve the current default OAuth Token. Many PSRAW commands require a `RedditOAuthToken` to authenticate with the Reddit API. The session default OAuth Token is used by those commands so that one does not need to be manually supplied each time. 21 | 22 | ## EXAMPLES 23 | 24 | ### Example 1 25 | ``` 26 | PS C:\> $DefaultToken = Get-RedditDefaultOAuthToken 27 | ``` 28 | 29 | This retrieves the current default session OAuth Token. 30 | 31 | ## PARAMETERS 32 | 33 | ### -Confirm 34 | Prompts you for confirmation before running the cmdlet. 35 | 36 | ```yaml 37 | Type: SwitchParameter 38 | Parameter Sets: (All) 39 | Aliases: cf 40 | 41 | Required: False 42 | Position: Named 43 | Default value: None 44 | Accept pipeline input: False 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### -WhatIf 49 | Shows what would happen if the cmdlet runs. 50 | The cmdlet is not run. 51 | 52 | ```yaml 53 | Type: SwitchParameter 54 | Parameter Sets: (All) 55 | Aliases: wi 56 | 57 | Required: False 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### CommonParameters 65 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 66 | 67 | ## INPUTS 68 | 69 | ### None 70 | 71 | ## OUTPUTS 72 | 73 | ### RedditOAuthToken 74 | 75 | ## NOTES 76 | 77 | ## RELATED LINKS 78 | 79 | [https://psraw.readthedocs.io/en/latest/Module/Get-RedditDefaultOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Get-RedditDefaultOAuthToken) 80 | 81 | [Connect-Reddit](https://psraw.readthedocs.io/en/latest/Module/Connect-Reddit) 82 | 83 | [Import-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Import-RedditOAuthToken) 84 | 85 | [Request-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Request-RedditOAuthToken) 86 | 87 | [Set-RedditDefaultOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Set-RedditDefaultOAuthToken) 88 | 89 | [Update-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Update-RedditOAuthToken) 90 | 91 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 92 | -------------------------------------------------------------------------------- /docs/Module/Get-RedditOAuthScope.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSRAW-help.xml 3 | Module Name: PSRAW 4 | online version: https://psraw.readthedocs.io/en/latest/Module/Get-RedditOAuthScope 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-RedditOAuthScope 9 | 10 | ## SYNOPSIS 11 | Retrieve valid Reddit OAuth Scopes. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-RedditOAuthScope [[-ApiEndpointUri] ] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Retrieve valid OAuth scope IDs, Names, and Descriptions from Reddit. 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $RedditOAuthScopes = Get-RedditOAuthScope 27 | ``` 28 | 29 | ## PARAMETERS 30 | 31 | ### -ApiEndpointUri 32 | Optional. 33 | URL for the Reddit App Scope definitions. 34 | Default: 35 | 36 | https://www.reddit.com/api/v1/scopes 37 | 38 | ```yaml 39 | Type: String 40 | Parameter Sets: (All) 41 | Aliases: 42 | 43 | Required: False 44 | Position: 1 45 | Default value: [RedditOAuthScope]::GetApiEndpointUri() 46 | Accept pipeline input: False 47 | Accept wildcard characters: False 48 | ``` 49 | 50 | ### CommonParameters 51 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 52 | 53 | ## INPUTS 54 | 55 | ## OUTPUTS 56 | 57 | ### RedditOAuthScope 58 | 59 | ## NOTES 60 | For complete documentation visit [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 61 | 62 | For more information about registering Reddit Apps, Reddit's API, or Reddit OAuth see: 63 | 64 | * [https://github.com/reddit/reddit/wiki/API](https://github.com/reddit/reddit/wiki/API) 65 | * [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 66 | * [https://www.reddit.com/prefs/apps](https://www.reddit.com/prefs/apps) 67 | * [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 68 | 69 | ## RELATED LINKS 70 | 71 | [Get-RedditOAuthScope](https://psraw.readthedocs.io/en/latest/Module/Get-RedditOAuthScope) 72 | 73 | [about_RedditOAuthScope](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthScope) 74 | 75 | [https://github.com/reddit/reddit/wiki/API](https://github.com/reddit/reddit/wiki/API) 76 | 77 | [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 78 | 79 | [https://www.reddit.com/prefs/apps](https://www.reddit.com/prefs/apps) 80 | 81 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 82 | 83 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 84 | -------------------------------------------------------------------------------- /docs/Module/PSRAW.md: -------------------------------------------------------------------------------- 1 | --- 2 | Module Name: PSRAW 3 | Module Guid: 92c8f916-4890-45eb-a3e7-592f5b5b3f24 4 | Download Help Link: 5 | Help Version: 0.0.1.0 6 | Locale: en-US 7 | --- 8 | 9 | # PSRAW Module 10 | ## Description 11 | PSRAW is a PowerShell Reddit API Wrapper Module providing full access to the Reddit API via PowerShell. 12 | 13 | ## PSRAW Cmdlets 14 | ### [Connect-Reddit](Connect-Reddit.md) 15 | Authenticates to the Reddit API 16 | 17 | ### [Export-RedditApplication](Export-RedditApplication.md) 18 | Exports a `RedditApplication` object to an XML file. 19 | 20 | ### [Export-RedditOAuthToken](Export-RedditOAuthToken.md) 21 | Exports a `RedditOAuthToken` object to an XML file. 22 | 23 | ### [Get-RedditDefaultOAuthToken](Get-RedditDefaultOAuthToken.md) 24 | Retrieves the session default OAuth Token 25 | 26 | ### [Get-RedditOAuthScope](Get-RedditOAuthScope.md) 27 | Retrieve valid Reddit OAuth Scopes. 28 | 29 | ### [Import-RedditApplication](Import-RedditApplication.md) 30 | Imports a `RedditApplication` object from an XML file. 31 | 32 | ### [Import-RedditOAuthToken](Import-RedditOAuthToken.md) 33 | Imports a `RedditOAuthToken` object from an XML file and sets it as the session default OAuth Token 34 | 35 | ### [Invoke-RedditRequest](Invoke-RedditRequest.md) 36 | Performs an authenticated API request against the Reddit API. 37 | 38 | ### [New-RedditApplication](New-RedditApplication.md) 39 | Creates a `RedditApplication` object 40 | 41 | ### [Request-RedditOAuthToken](Request-RedditOAuthToken.md) 42 | Requests a OAuth Access Token from Reddit and sets it as the session default OAuth Token 43 | 44 | ### [Resolve-RedditDataObject](Resolve-RedditDataObject.md) 45 | Resolves a `RedditDataObject` from another object (experimental) 46 | 47 | ### [Set-RedditDefaultOAuthToken](Set-RedditDefaultOAuthToken.md) 48 | Sets the session default OAuth Token 49 | 50 | ### [Update-RedditOAuthToken](Update-RedditOAuthToken.md) 51 | Refresh a `RedditOAuthToken` 52 | 53 | -------------------------------------------------------------------------------- /docs/Module/about_RedditApplicationType.md: -------------------------------------------------------------------------------- 1 | # RedditApplicationType 2 | ## about_RedditApplicationType 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditApplicationType Enum 6 | 7 | # LONG DESCRIPTION 8 | The `RedditApplicationType` enumerator represents the available option for applications registered in Reddit. To register an application go to https://ssl.reddit.com/prefs/apps . `RedditApplicationType` is used by the Type property of the `RedditApplication` class. 9 | 10 | For more information on Reddit OAuth App Types see https://github.com/reddit/reddit/wiki/OAuth2-App-Types 11 | 12 | 13 | # Fields 14 | ## Installed 15 | An app intended for installation, such as on a mobile phone. 16 | 17 | ## Script 18 | Script for personal use. Will only be able to act on behalf of the developer who registered the application. 19 | 20 | ## WebApp 21 | A Web base application. Can also be used in scripts to act on behalf of other users. 22 | 23 | # EXAMPLES 24 | 25 | ## WebApp 26 | ```powershell 27 | $WebApp = [RedditApplicationType]::WebApp 28 | ``` 29 | 30 | ## Script 31 | ```powershell 32 | $Script = [RedditApplicationType]::Script 33 | ``` 34 | 35 | ## installed 36 | ```powershell 37 | $Installed= [RedditApplicationType]::Installed 38 | ``` 39 | 40 | # SEE ALSO 41 | 42 | [about_RedditApplicationType](https://psraw.readthedocs.io/en/latest/Module/about_RedditApplicationType) 43 | 44 | [about_RedditApplication](https://psraw.readthedocs.io/en/latest/Module/about_RedditApplication) 45 | 46 | [New-RedditApplication](https://psraw.readthedocs.io/en/latest/Module/New-RedditApplication) 47 | 48 | [https://ssl.reddit.com/prefs/apps](https://ssl.reddit.com/prefs/apps) 49 | 50 | [https://github.com/reddit/reddit/wiki/OAuth2-App-Types](https://github.com/reddit/reddit/wiki/OAuth2-App-Types) 51 | 52 | [https://github.com/reddit/reddit/wiki/API](https://github.com/reddit/reddit/wiki/API) 53 | 54 | [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 55 | 56 | [https://www.reddit.com/prefs/apps](https://www.reddit.com/prefs/apps) 57 | 58 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 59 | 60 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 61 | -------------------------------------------------------------------------------- /docs/Module/about_RedditDataObject.md: -------------------------------------------------------------------------------- 1 | # RedditDataObject 2 | ## about_RedditDataObject 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditDataObject Class (experimental) 6 | 7 | # LONG DESCRIPTION 8 | Base Class for Reddit data Objects. This class is used only as a general base class and provide no functionality or features. 9 | 10 | 11 | # Constructors 12 | ## RedditDataObject() 13 | Creates an empty `RedditDataObject` 14 | 15 | ```powershell 16 | [RedditDataObject]::new() 17 | ``` 18 | 19 | 20 | # Properties 21 | 22 | # Methods 23 | 24 | # EXAMPLES 25 | ```powershell 26 | [RedditDataObject]::new() 27 | ``` 28 | 29 | # NOTES 30 | 31 | Experimental: This is an experimental feature. Expect radical changes between versions. Do not write production code against this until it has been marked stable. 32 | 33 | # DERIVED CLASSES 34 | * [RedditComment](https://psraw.readthedocs.io/en/latest/Module/about_RedditComment) 35 | * [RedditLink](https://psraw.readthedocs.io/en/latest/Module/about_RedditLink) 36 | * [RedditListing](https://psraw.readthedocs.io/en/latest/Module/about_RedditListing) 37 | * [RedditMore](https://psraw.readthedocs.io/en/latest/Module/about_RedditMore) 38 | * [RedditSubmission](https://psraw.readthedocs.io/en/latest/Module/about_RedditSubmission) 39 | * [RedditSubreddit](https://psraw.readthedocs.io/en/latest/Module/about_RedditSubreddit) 40 | 41 | 42 | # SEE ALSO 43 | 44 | [about_RedditDataObject](https://psraw.readthedocs.io/en/latest/Module/about_RedditDataObject) 45 | 46 | [about_RedditComment](https://psraw.readthedocs.io/en/latest/Module/about_RedditComment) 47 | 48 | [about_RedditLink](https://psraw.readthedocs.io/en/latest/Module/about_RedditLink) 49 | 50 | [about_RedditSubmission](https://psraw.readthedocs.io/en/latest/Module/about_RedditSubmission) 51 | 52 | [about_RedditSubreddit](https://psraw.readthedocs.io/en/latest/Module/about_RedditSubreddit) 53 | 54 | [about_RedditMore](https://psraw.readthedocs.io/en/latest/Module/about_RedditMore) 55 | 56 | [about_RedditListing](https://psraw.readthedocs.io/en/latest/Module/about_RedditListing) 57 | 58 | [Resolve-RedditDataObject](https://psraw.readthedocs.io/en/latest/Module/Resolve-RedditDataObject) 59 | 60 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 61 | 62 | [https://github.com/reddit/reddit/wiki/JSON](https://github.com/reddit/reddit/wiki/JSON) 63 | 64 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 65 | -------------------------------------------------------------------------------- /docs/Module/about_RedditDate.md: -------------------------------------------------------------------------------- 1 | # RedditDate 2 | ## about_RedditDate 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditDate Class 6 | 7 | # LONG DESCRIPTION 8 | Reddit uses Unix Epoch dates in a Double. The `RedditDate` class provides easy translation between a Unix date and a `DateTime` object. This object does not automatically update after it is initialized. 9 | 10 | # Constructors 11 | ## RedditDate() 12 | Creates a `RedditDate` at the Unix Epoch. 13 | 14 | ```powershell 15 | [RedditDate]::new() 16 | ``` 17 | 18 | ## RedditDate(DateTime Date) 19 | Creates a `RedditDate` from a `DateTime` object. 20 | 21 | ```powershell 22 | [RedditDate]::new([DateTime]$Date) 23 | ``` 24 | 25 | ## RedditDate(Double Double) 26 | Creates a `RedditDate` from a `Double` 27 | 28 | ```powershell 29 | [RedditDate]::new([Double]$Double) 30 | ``` 31 | 32 | ## RedditDate(String String) 33 | Creates a `RedditDate` from a parsable `Double` or `DateTime` `String`. 34 | 35 | ```powershell 36 | [RedditDate]::new([String]$String) 37 | ``` 38 | 39 | 40 | # Properties 41 | ## Date 42 | The `DateTime` of the `RedditDate` 43 | 44 | ```yaml 45 | Name: Date 46 | Type: DateTime 47 | Hidden: False 48 | Static: False 49 | ``` 50 | 51 | ## Unix 52 | The Unix Timestamp in seconds. 53 | 54 | ```yaml 55 | Name: Unix 56 | Type: Double 57 | Hidden: False 58 | Static: False 59 | ``` 60 | 61 | ## UnixEpoch 62 | The Unix Epoch time used in creating the `RedditDate` 63 | 64 | ```yaml 65 | Name: UnixEpoch 66 | Type: DateTime 67 | Hidden: False 68 | Static: True 69 | ``` 70 | 71 | 72 | # Methods 73 | 74 | # EXAMPLES 75 | ```powershell 76 | $Date = [dateTime]'7/27/2017' 77 | [RedditDate]::New($Date) 78 | [RedditDate]::New(1501113600) 79 | [RedditDate]::New('7/27/2017') 80 | [RedditDate]::New('1501113600') 81 | $UnixDate = ([RedditDate]$Date).Unix 82 | $UnixDate = ([RedditDate]'7/27/2017').Unix 83 | $DateTime = ([RedditDate]1501113600).Date 84 | $DateTime = ([RedditDate]'1501113600').Date 85 | ``` 86 | 87 | # SEE ALSO 88 | 89 | [about_RedditDate](https://psraw.readthedocs.io/en/latest/Module/about_RedditDate) 90 | 91 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 92 | 93 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 94 | -------------------------------------------------------------------------------- /docs/Module/about_RedditHeaderSize.md: -------------------------------------------------------------------------------- 1 | # RedditHeaderSize 2 | ## about_RedditHeaderSize 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditHeaderSize Class 6 | 7 | # LONG DESCRIPTION 8 | Represents the size of a Subreddit Header 9 | 10 | 11 | # Constructors 12 | ## RedditHeaderSize() 13 | Creates an empty `RedditHeaderSize` 14 | 15 | ```powershell 16 | [RedditHeaderSize]::new() 17 | ``` 18 | 19 | ## RedditHeaderSize(Object[] InputObjects) 20 | Creates a `RedditHeaderSize` from an array where the first element is the width and the second element is the height. This is how the Reddit API returns the object. 21 | 22 | ```powershell 23 | [RedditHeaderSize]::new([Object[]]$InputObjects) 24 | ``` 25 | 26 | 27 | # Properties 28 | ## Height 29 | The Height of the Header 30 | 31 | ```yaml 32 | Name: Height 33 | Type: Int64 34 | Hidden: False 35 | Static: False 36 | ``` 37 | 38 | ## Width 39 | The Width of the Header 40 | 41 | ```yaml 42 | Name: Width 43 | Type: Int64 44 | Hidden: False 45 | Static: False 46 | ``` 47 | 48 | 49 | # Methods 50 | 51 | # SEE ALSO 52 | 53 | [about_RedditHeaderSize](https://psraw.readthedocs.io/en/latest/Module/about_RedditHeaderSize) 54 | 55 | [about_RedditSubreddit](https://psraw.readthedocs.io/en/latest/Module/about_RedditSubreddit) 56 | 57 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 58 | 59 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 60 | -------------------------------------------------------------------------------- /docs/Module/about_RedditModReport.md: -------------------------------------------------------------------------------- 1 | # RedditModReport 2 | ## about_RedditModReport 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditModReport Class 6 | 7 | # LONG DESCRIPTION 8 | A moderator report for a comment or submission. 9 | 10 | 11 | # Constructors 12 | ## RedditModReport() 13 | Creates an empty `RedditModReport` object. 14 | 15 | ```powershell 16 | [RedditModReport]::new() 17 | ``` 18 | 19 | 20 | ## RedditModReport(Object[] InputObjects) 21 | Creates a `RedditModReport` from an array. 22 | 23 | ```powershell 24 | [RedditModReport]::new([Object[]]$InputObjects) 25 | ``` 26 | 27 | 28 | # Properties 29 | ## Moderator 30 | The reporting Moderator's Reddit username. 31 | 32 | ```yaml 33 | Name: Moderator 34 | Type: String 35 | Hidden: False 36 | Static: False 37 | ``` 38 | 39 | ## Reason 40 | The reason for the report. 41 | 42 | ```yaml 43 | Name: Reason 44 | Type: String 45 | Hidden: False 46 | Static: False 47 | ``` 48 | 49 | 50 | # Methods 51 | 52 | # EXAMPLES 53 | ```powershell 54 | $RedditModReport = [RedditModReport]@('Breaks Rule 12', 'markekraus') 55 | ``` 56 | 57 | # SEE ALSO 58 | 59 | [about_RedditModReport](https://psraw.readthedocs.io/en/latest/Module/about_RedditModReport) 60 | 61 | [about_RedditComment](https://psraw.readthedocs.io/en/latest/Module/about_RedditComment) 62 | 63 | [about_RedditLink](https://psraw.readthedocs.io/en/latest/Module/about_RedditLink) 64 | 65 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 66 | 67 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 68 | -------------------------------------------------------------------------------- /docs/Module/about_RedditOAuthDuration.md: -------------------------------------------------------------------------------- 1 | # RedditOAuthDuration 2 | ## about_RedditOAuthDuration 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditOAuthDuration Enum 6 | 7 | # LONG DESCRIPTION 8 | The `RedditOAuthDuration` enumerator represents the available options for Access Token durations during Authorization code requests to the Reddit API. 9 | 10 | 11 | # Fields 12 | ## Permanent 13 | Requests for permanent OAuth Access Tokens will issue an OAuth Refresh Token. Access Tokens are valid for 60 minutes. When the Access Token expires the Refresh Token can be used to request a new access token without requiring the application to be authorized again. Refresh tokens are valid until a user or developer revokes the authorization for the application. 14 | 15 | When `Permanent` Access Tokens are "renewed" the do not require a new grant flow and the Refresh Token will be used to request a new Access Token. 16 | 17 | `Permanent` is currently not support in PSRAW. 18 | 19 | ## Temporary 20 | Requests for temporary OAuth Access Tokens will not issue Refresh Tokens and when they expire the user will need to authorize the applications again. Access Tokens are valid for 60 minutes. 21 | 22 | When `Temporary` Access Tokens are "renewed" a new grant flow is started. 23 | 24 | `Temporary` can be used with any grant flow. 25 | 26 | # EXAMPLES 27 | ## Permanent 28 | ```powershell 29 | $Permanent = [RedditOAuthDuration]::Permanent 30 | ``` 31 | 32 | ## Temporary 33 | ```powershell 34 | $Temporary = [RedditOAuthDuration]::Temporary 35 | ``` 36 | 37 | # SEE ALSO 38 | 39 | [about_RedditOAuthDuration](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthDuration) 40 | 41 | [about_RedditApplication](https://psraw.readthedocs.io/en/latest/Module/about_RedditApplication) 42 | 43 | [about_RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthToken) 44 | 45 | [New-RedditApplication](https://psraw.readthedocs.io/en/latest/Module/New-RedditApplication) 46 | 47 | [Request-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/New-RedditApplication) 48 | 49 | [https://ssl.reddit.com/prefs/apps](https://ssl.reddit.com/prefs/apps) 50 | 51 | [https://github.com/reddit/reddit/wiki/API](https://github.com/reddit/reddit/wiki/API) 52 | 53 | [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 54 | 55 | [https://www.reddit.com/prefs/apps](https://www.reddit.com/prefs/apps) 56 | 57 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 58 | 59 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 60 | -------------------------------------------------------------------------------- /docs/Module/about_RedditOAuthGrantType.md: -------------------------------------------------------------------------------- 1 | # RedditOAuthGrantType 2 | ## about_RedditOAuthGrantType 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditOAuthGrantType Enum 6 | 7 | # LONG DESCRIPTION 8 | The `RedditOAuthGrantType` enumerator contains the available grant types available for OAuth Access Tokens requests on Reddit. this is visible on `RedditOAuthToken` objects as the `GrantType` property. It is used by various functions in this module to determine the actions and endpoints required to request Access Tokens. 9 | 10 | # Fields 11 | 12 | ## Client_Credentials 13 | This grant method uses the Client ID and Client Secret to request an anonymous Access Token. This method will not act under a user context but will allow "logged out" access to the OAuth API endpoints for `Script` and `WebApp` applications. For more information see the `Client` parameter description of `Request-RedditOAuthToken` or the Reddit OAuth documentation at https://github.com/reddit/reddit/wiki/OAuth2#application-only-oauth 14 | 15 | ## Installed_Client 16 | This grant flow allows anonymous access to the Reddit API for `Installed` applications. This method will not act under a user context but will allow "logged out" access to the OAuth API endpoints. For more information see the `Installed` parameter description of `Request-RedditOAuthToken` or the Reddit OAuth documentation at https://github.com/reddit/reddit/wiki/OAuth2#application-only-oauth 17 | 18 | ## Password 19 | This grant flow allows for the developer of `Script` applications to access the Reddit API as themselves. This uses the Username, Password, Client ID, and Client Secret to request an OAuth Access Token. For more information see the `Script` parameter description of `Request-RedditOAuthToken` or the Reddit OAuth documentation at https://github.com/reddit/reddit/wiki/OAuth2#application-only-oauth 20 | 21 | 22 | 23 | # SEE ALSO 24 | 25 | [about_RedditOAuthGrantType](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthGrantType) 26 | 27 | [about_RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthToken) 28 | 29 | [Request-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Request-RedditOAuthToken) 30 | 31 | [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 32 | 33 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 34 | -------------------------------------------------------------------------------- /docs/Module/about_RedditOAuthResponse.md: -------------------------------------------------------------------------------- 1 | # RedditOAuthResponse 2 | ## about_RedditOAuthResponse 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditOAuthResponse Class 6 | 7 | # LONG DESCRIPTION 8 | The `RedditOAuthResponse` Class encapsulates the responses from Reddit OAuth grant flows. 9 | 10 | 11 | # Constructors 12 | ## RedditOAuthResponse() 13 | Default Constructor creates an empty `RedditOAuthResponse` object. 14 | 15 | ```powershell 16 | [RedditOAuthResponse]::new() 17 | ``` 18 | 19 | 20 | # Properties 21 | ## Content 22 | The Content returned from the Reddit. It may be either plain text or an object created from JSON. 23 | 24 | ```yaml 25 | Name: Content 26 | Type: System.Management.Automation.PSObject 27 | Hidden: False 28 | Static: False 29 | ``` 30 | 31 | ## ContentType 32 | The `Content-Type` response header returned from Reddit. 33 | 34 | ```yaml 35 | Name: ContentType 36 | Type: String 37 | Hidden: False 38 | Static: False 39 | ``` 40 | 41 | ## Parameters 42 | The parameters that were passed to `Invoke-WebRequest`. 43 | 44 | ```yaml 45 | Name: Parameters 46 | Type: System.Collections.Hashtable 47 | Hidden: False 48 | Static: False 49 | ``` 50 | 51 | ## RequestDate 52 | The date the request was made. 53 | 54 | ```yaml 55 | Name: RequestDate 56 | Type: DateTime 57 | Hidden: False 58 | Static: False 59 | ``` 60 | 61 | ## Response 62 | The `Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject` or `Microsoft.PowerShell.Commands.HtmlWebResponseObject` returned from `Invoke-WebRequest` 63 | 64 | ```yaml 65 | Name: Response 66 | Type: Microsoft.PowerShell.Commands.WebResponseObject 67 | Hidden: False 68 | Static: False 69 | ``` 70 | 71 | 72 | # Methods 73 | 74 | # EXAMPLES 75 | 76 | ## Example 1 77 | ```powershell 78 | [RedditOAuthResponse]@{ 79 | Response = $Response 80 | RequestDate = $Response.Headers.Date[0] 81 | Parameters = $Params 82 | Content = $Response.Content 83 | ContentType = $Response | Get-HttpResponseContentType 84 | } 85 | ``` 86 | 87 | This is an example of how the `RedditOAuthResponse` class is used in `Request-RedditOAuthTokenPassword`. 88 | 89 | 90 | # SEE ALSO 91 | 92 | [about_RedditOAuthResponse](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthResponse) 93 | 94 | [Request-RedditOAuthTokenClient](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenClient) 95 | 96 | [Request-RedditOAuthTokenInstalled](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled) 97 | 98 | [Request-RedditOAuthTokenPassword](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenPassword) 99 | 100 | [about_RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthToken) 101 | 102 | [Request-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Request-RedditOAuthToken) 103 | 104 | [Update-RedditOAuthToken](https://psraw.readthedocs.io/en/latest/Module/Update-RedditOAuthToken) 105 | 106 | [Invoke-WebRequest](https://go.microsoft.com/fwlink/?LinkID=217035) 107 | 108 | [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 109 | 110 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 111 | -------------------------------------------------------------------------------- /docs/Module/about_RedditOAuthResponseType.md: -------------------------------------------------------------------------------- 1 | # RedditOAuthResponseType 2 | ## about_RedditOAuthResponseType 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditOAuthResponseType Enum 6 | 7 | # LONG DESCRIPTION 8 | The `RedditOAuthResponseType` enumerator represents the available options for authorization requests made to Reddit. 9 | 10 | # Fields 11 | ## Code 12 | Used to request OAuth Authorization Code in Code Flow Token requests 13 | 14 | ## Token 15 | Used to request OAuth Access Tokens. 16 | 17 | # SEE ALSO 18 | 19 | [about_RedditOAuthResponseType](https://psraw.readthedocs.io/en/latest/Module/about_RedditOAuthResponseType) 20 | 21 | [about_RedditApplication](https://psraw.readthedocs.io/en/latest/Module/about_RedditApplication) 22 | 23 | [https://github.com/reddit/reddit/wiki/OAuth2](https://github.com/reddit/reddit/wiki/OAuth2) 24 | 25 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 26 | -------------------------------------------------------------------------------- /docs/Module/about_RedditSubmission.md: -------------------------------------------------------------------------------- 1 | # RedditSubmission 2 | ## about_RedditSubmission 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditSubmission Class (experimental) 6 | 7 | # LONG DESCRIPTION 8 | A `RedditSubmission` object contains the link and comments returned from a Reddit submission. 9 | 10 | 11 | # Constructors 12 | ## RedditSubmission() 13 | Creates an empty `RedditSubmission` object 14 | 15 | ```powershell 16 | [RedditSubmission]::new() 17 | ``` 18 | 19 | ## RedditSubmission(RedditApiResponse ApiResponse) 20 | Creates a `RedditSubmission` from a `RedditApiResponse` returned from `Invoke-RedditRequest`. 21 | 22 | ```powershell 23 | [RedditSubmission]::new([RedditApiResponse]$ApiResponse) 24 | ``` 25 | 26 | 27 | # Properties 28 | ## Comments 29 | An array of comments in reply to the submission. 30 | 31 | ```yaml 32 | Name: Comments 33 | Type: RedditComment[] 34 | Hidden: False 35 | Static: False 36 | ``` 37 | 38 | ## Link 39 | The link or self-post of the submission. 40 | 41 | ```yaml 42 | Name: Link 43 | Type: RedditLink 44 | Hidden: False 45 | Static: False 46 | ``` 47 | 48 | 49 | # Methods 50 | 51 | # NOTES 52 | 53 | Experimental: This is an experimental feature. Expect radical changes between versions. Do not write production code against this until it has been marked stable. 54 | 55 | # DERIVED FROM 56 | 57 | [RedditDataObject](https://psraw.readthedocs.io/en/latest/Module/about_RedditDataObject) 58 | 59 | # SEE ALSO 60 | 61 | [about_RedditSubmission](https://psraw.readthedocs.io/en/latest/Module/about_RedditSubmission) 62 | 63 | [about_RedditApiResponse](https://psraw.readthedocs.io/en/latest/Module/about_RedditApiResponse) 64 | 65 | [about_RedditComment](https://psraw.readthedocs.io/en/latest/Module/about_RedditComment) 66 | 67 | [about_RedditDataObject](https://psraw.readthedocs.io/en/latest/Module/about_RedditDataObject) 68 | 69 | [about_RedditLink](https://psraw.readthedocs.io/en/latest/Module/about_RedditLink) 70 | 71 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 72 | 73 | [https://github.com/reddit/reddit/wiki/JSON](https://github.com/reddit/reddit/wiki/JSON) 74 | 75 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 76 | -------------------------------------------------------------------------------- /docs/Module/about_RedditThingKind.md: -------------------------------------------------------------------------------- 1 | # RedditThingKind 2 | ## about_RedditThingKind 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditThingKind Enum 6 | 7 | # LONG DESCRIPTION 8 | This s used by `RedditThing` objects to determine their kind. 9 | 10 | # Fields 11 | ## listing 12 | A listing is a list of Reddit Things 13 | 14 | ## more 15 | A list of String ids that are the additional things that can be downloaded but are not because there are too many to list. 16 | 17 | ## t1 18 | Reddit Comment 19 | 20 | ## t2 21 | Reddit Account 22 | 23 | ## t3 24 | Reddit Submission Link 25 | 26 | ## t4 27 | Reddit Message 28 | 29 | ## t5 30 | Reddit Subreddit 31 | 32 | ## t6 33 | Reddit Award 34 | 35 | ## t8 36 | Reddit Promotion Campaign 37 | 38 | 39 | # EXAMPLES 40 | 41 | ## Example 1 42 | 43 | ```powershell 44 | $Listing = [RedditThingKind]::listing 45 | ``` 46 | 47 | # SEE ALSO 48 | 49 | [about_RedditThingKind](https://psraw.readthedocs.io/en/latest/Module/about_RedditThingKind) 50 | 51 | [about_RedditThing](https://psraw.readthedocs.io/en/latest/Module/about_RedditThing) 52 | 53 | [Invoke-RedditRequest](https://psraw.readthedocs.io/en/latest/Module/Import-RedditRequest) 54 | 55 | [https://github.com/reddit/reddit/wiki/JSON](https://github.com/reddit/reddit/wiki/JSON) 56 | 57 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 58 | 59 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 60 | -------------------------------------------------------------------------------- /docs/Module/about_RedditThingPrefix.md: -------------------------------------------------------------------------------- 1 | # RedditThingPrefix 2 | ## about_RedditThingPrefix 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditThingPrefix Enum 6 | 7 | # LONG DESCRIPTION 8 | An data object returned from the Reddit API will have a type prefix to identify what kind of Reddit Thing it is. This is subset of `RedditThingKind` is only used with data objects such as comments, accounts, and links and not with collection objects such as `more`s and `listing`s. 9 | 10 | # Fields 11 | ## t1 12 | Comment 13 | 14 | ## t2 15 | Account 16 | 17 | ## t3 18 | Link 19 | 20 | ## t4 21 | Message 22 | 23 | ## t5 24 | Subreddit 25 | 26 | ## t6 27 | Award 28 | 29 | ## t8 30 | Promotion campaign 31 | 32 | 33 | # EXAMPLES 34 | 35 | ## Example 1 36 | 37 | ```powershell 38 | $Comment = [RedditThingPrefix]::t1 39 | ``` 40 | 41 | # SEE ALSO 42 | 43 | [about_RedditThingPrefix](https://psraw.readthedocs.io/en/latest/Module/about_RedditThingPrefix) 44 | 45 | [about_RedditThingKind](https://psraw.readthedocs.io/en/latest/Module/about_RedditThingKind) 46 | 47 | [about_RedditThing](https://psraw.readthedocs.io/en/latest/Module/about_RedditThing) 48 | 49 | [Invoke-RedditRequest](https://psraw.readthedocs.io/en/latest/Module/Import-RedditRequest) 50 | 51 | [https://github.com/reddit/reddit/wiki/JSON](https://github.com/reddit/reddit/wiki/JSON) 52 | 53 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 54 | 55 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 56 | -------------------------------------------------------------------------------- /docs/Module/about_RedditUserReport.md: -------------------------------------------------------------------------------- 1 | # RedditUserReport 2 | ## about_RedditUserReport 3 | 4 | # SHORT DESCRIPTION 5 | Describes the RedditUserReport Class 6 | 7 | # LONG DESCRIPTION 8 | `RedditUserReport` represent reports made by a users on a link or comment. These will only be visible to subreddit moderators. 9 | 10 | # Constructors 11 | ## RedditUserReport() 12 | Creates an empty `RedditUserReport` object. 13 | 14 | ```powershell 15 | [RedditUserReport]::new() 16 | ``` 17 | 18 | 19 | ## RedditUserReport(Object[] InputObjects) 20 | Creates `RedditUserReport` from an object array 21 | 22 | ```powershell 23 | [RedditUserReport]::new([Object[]]$InputObjects) 24 | ``` 25 | 26 | 27 | # Properties 28 | ## Count 29 | The number of times this reason has been reported 30 | 31 | ```yaml 32 | Name: Count 33 | Type: Int64 34 | Hidden: False 35 | Static: False 36 | ``` 37 | 38 | ## Reason 39 | The reason provided by the user(s). 40 | 41 | ```yaml 42 | Name: Reason 43 | Type: String 44 | Hidden: False 45 | Static: False 46 | ``` 47 | 48 | 49 | # Methods 50 | 51 | # EXAMPLES 52 | ```powershell 53 | [RedditUserReport]@{ 54 | Reason = 'Spam' 55 | Count = 5 56 | } 57 | ``` 58 | 59 | # SEE ALSO 60 | 61 | [about_RedditUserReport](https://psraw.readthedocs.io/en/latest/Module/about_RedditUserReport) 62 | 63 | [about_RedditComment](https://psraw.readthedocs.io/en/latest/Module/about_RedditComment) 64 | 65 | [about_RedditLink](https://psraw.readthedocs.io/en/latest/Module/about_RedditLink) 66 | 67 | [https://www.reddit.com/wiki/api](https://www.reddit.com/wiki/api) 68 | 69 | [https://psraw.readthedocs.io/](https://psraw.readthedocs.io/) 70 | -------------------------------------------------------------------------------- /docs/PrivateFunctions/Get-AuthorizationHeader.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: 3 | Module Name: 4 | online version: https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-AuthorizationHeader 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-AuthorizationHeader 9 | 10 | ## SYNOPSIS 11 | Returns an rfc2617 Authorization header 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-AuthorizationHeader [-Credential] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Private Function that converts the provided `PSCredential` in to a rfc2617 Authorization header. Reddit's API requires `Basic` `Authorization` when requesting certain Access Token types. PowerShell does not currently support this method directly via `Invoke-WebRequest` or `Invoke-RestMethod`, therefore this function provides that missing functionality. This is not the same header sent when using the `Credential` parameter on either command. 21 | 22 | This function is not intended for direct usage by the module consumer and is not exported by the module. Documentation is provided for developers and contributors. 23 | 24 | ## EXAMPLES 25 | 26 | ### -------------------------- EXAMPLE 1 -------------------------- 27 | ``` 28 | $AuthHeader = $Application.ClientCredential | Get-AuthorizationHeader 29 | ``` 30 | 31 | This example demonstrates how the `Request-RedditOAuthToken` function uses `Get-AuthorizationHeader` to generate an authorization header to send in the Access Token request. 32 | 33 | ## PARAMETERS 34 | 35 | ### -Credential 36 | The `PSCredential` object from which to create the Authorization header. 37 | 38 | ```yaml 39 | Type: PSCredential 40 | Parameter Sets: (All) 41 | Aliases: 42 | 43 | Required: True 44 | Position: 0 45 | Default value: None 46 | Accept pipeline input: True (ByPropertyName, ByValue) 47 | Accept wildcard characters: False 48 | ``` 49 | 50 | ### CommonParameters 51 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 52 | 53 | ## INPUTS 54 | 55 | ### PSCredential 56 | 57 | ## OUTPUTS 58 | 59 | ### System.String 60 | 61 | ## NOTES 62 | This function is used in the following functions: 63 | 64 | * [Request-RedditOAuthTokenClient](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenClient) 65 | * [Request-RedditOAuthTokenInstalled](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled) 66 | * [Request-RedditOAuthTokenPassword](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenPassword) 67 | 68 | ## RELATED LINKS 69 | 70 | [Get-AuthorizationHeader](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-AuthorizationHeader) 71 | 72 | [Request-RedditOAuthTokenClient](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenClient) 73 | 74 | [Request-RedditOAuthTokenInstalled](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled) 75 | 76 | [Request-RedditOAuthTokenPassword](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenPassword) 77 | 78 | [https://tools.ietf.org/html/rfc2617#section-2](https://tools.ietf.org/html/rfc2617#section-2) 79 | 80 | [https://github.com/reddit/reddit/wiki/OAuth2#retrieving-the-access-token](https://github.com/reddit/reddit/wiki/OAuth2#retrieving-the-access-token) -------------------------------------------------------------------------------- /docs/PrivateFunctions/Get-HttpResponseContentType.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: 3 | Module Name: 4 | online version: https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-HttpResponseContentType 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-HttpResponseContentType 9 | 10 | ## SYNOPSIS 11 | Retrieves the `Content-Type` header from a `WebResponseObject`. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-HttpResponseContentType [-Response] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | Retrieves the `Content-Type` header from a `WebResponseObject`. 21 | 22 | PowerShell 6.0 has switched from `System.Net.HttpWebResponse` to `System.Net.Http.HttpResponseMessage` for the underlying base object. `HttpResponseMessage` separates content related headers from response headers. This private function provides compatibility between 5.0, 5.1, and 6.0+. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | ``` 28 | Invoke-WebRequest -Uri 'reddit.com' | Get-HttpResponseContentType 29 | ``` 30 | 31 | ## PARAMETERS 32 | 33 | ### -Response 34 | `Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject` or `Microsoft.PowerShell.Commands.HtmlWebResponseObject` returned from `Invoke-WebRequest` 35 | 36 | ```yaml 37 | Type: WebResponseObject 38 | Parameter Sets: (All) 39 | Aliases: 40 | 41 | Required: True 42 | Position: 0 43 | Default value: None 44 | Accept pipeline input: True (ByPropertyName, ByValue) 45 | Accept wildcard characters: False 46 | ``` 47 | 48 | ### CommonParameters 49 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 50 | 51 | ## INPUTS 52 | 53 | ### Microsoft.PowerShell.Commands.WebResponseObject 54 | 55 | ## OUTPUTS 56 | 57 | ### System.String 58 | 59 | ## NOTES 60 | For more information see [Issue #4467](https://github.com/PowerShell/PowerShell/issues/4467) and [Pull Request #4494](https://github.com/PowerShell/PowerShell/pull/4494). 61 | 62 | This function is used in the following functions: 63 | 64 | * [Invoke-RedditRequest](https://psraw.readthedocs.io/en/latest/Module/Invoke-RedditRequest) 65 | * [Request-RedditOAuthTokenClient](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenClient) 66 | * [Request-RedditOAuthTokenInstalled](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled) 67 | * [Request-RedditOAuthTokenPassword](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenPassword) 68 | 69 | ## RELATED LINKS 70 | 71 | [https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-HttpResponseContentType](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Get-HttpResponseContentType) 72 | 73 | [Invoke-RedditRequest](https://psraw.readthedocs.io/en/latest/Module/Invoke-RedditRequest) 74 | 75 | [Request-RedditOAuthTokenClient](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenClient) 76 | 77 | [Request-RedditOAuthTokenInstalled](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenInstalled) 78 | 79 | [Request-RedditOAuthTokenPassword](https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenPassword) --------------------------------------------------------------------------------