From c6d7b3c647afd297af009774209af4a3d9b7267d Mon Sep 17 00:00:00 2001 From: Stephen Owen Date: Wed, 16 Sep 2015 09:44:55 -0400 Subject: [PATCH] Renaming to a standard name, PSReddit --- ...it.format.ps1xml => PSReddit.format.ps1xml | 6 +- PowerReddit.ps1xml => PSReddit.ps1xml | 0 PowerReddit.psd1 => PSReddit.psd1 | 7 +- PSReddit.psm1 | 24 ++++++ PowerReddit.psm1 | 77 ------------------- 5 files changed, 31 insertions(+), 83 deletions(-) rename PowerReddit.format.ps1xml => PSReddit.format.ps1xml (95%) rename PowerReddit.ps1xml => PSReddit.ps1xml (100%) rename PowerReddit.psd1 => PSReddit.psd1 (94%) create mode 100644 PSReddit.psm1 delete mode 100644 PowerReddit.psm1 diff --git a/PowerReddit.format.ps1xml b/PSReddit.format.ps1xml similarity index 95% rename from PowerReddit.format.ps1xml rename to PSReddit.format.ps1xml index e1851a2..1ad84f9 100644 --- a/PowerReddit.format.ps1xml +++ b/PSReddit.format.ps1xml @@ -4,7 +4,7 @@ PowerReddit.Link - PowerReddit.Link + PSReddit.Link @@ -47,9 +47,9 @@ - PowerReddit.Comment + PSReddit.Comment - PowerReddit.Comment + PSReddit.Comment diff --git a/PowerReddit.ps1xml b/PSReddit.ps1xml similarity index 100% rename from PowerReddit.ps1xml rename to PSReddit.ps1xml diff --git a/PowerReddit.psd1 b/PSReddit.psd1 similarity index 94% rename from PowerReddit.psd1 rename to PSReddit.psd1 index b32f29f..0681297 100644 --- a/PowerReddit.psd1 +++ b/PSReddit.psd1 @@ -5,7 +5,7 @@ @{ # Script module or binary module file associated with this manifest -RootModule = 'PowerReddit.psm1' +RootModule = 'PSReddit.psm1' # Version number of this module. ModuleVersion = '1.0' @@ -15,6 +15,7 @@ GUID = '3dede632-fde4-4cc6-85df-9f5cfd6cd124' # Author of this module Author = 'Tobin Jones' +Author = 'Stephen Owen' # Copyright statement for this module Copyright = 'Licensed under the MIT license' @@ -50,10 +51,10 @@ PowerShellVersion = '3.0' # ScriptsToProcess = @() # Type files (.ps1xml) to be loaded when importing this module -TypesToProcess = @('PowerReddit.ps1xml') +TypesToProcess = @('PSReddit.ps1xml') # Format files (.ps1xml) to be loaded when importing this module -FormatsToProcess = @('PowerReddit.format.ps1xml') +FormatsToProcess = @('PSReddit.format.ps1xml') # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess # NestedModules = @() diff --git a/PSReddit.psm1 b/PSReddit.psm1 new file mode 100644 index 0000000..a192e46 --- /dev/null +++ b/PSReddit.psm1 @@ -0,0 +1,24 @@ +#Get public and private function definition files. + $PublicFunction = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Exclude *tests* -ErrorAction SilentlyContinue ) + $PrivateFunction = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Exclude *tests* -ErrorAction SilentlyContinue ) + +#Dot source the files + Foreach($import in @($PublicFunction + $PrivateFunction)) + { + "importing $import" + Try + { + . $import.fullname + } + Catch + { + Write-Error -Message "Failed to import function $($import.fullname): $_" + } + } + +# Here I might... + # Read in or create an initial config file and variable + # Export Public functions ($Public.BaseName) for WIP modules + # Set variables visible to the module and its functions only + +Export-ModuleMember -Function $PublicFunction.Basename \ No newline at end of file diff --git a/PowerReddit.psm1 b/PowerReddit.psm1 deleted file mode 100644 index b5a4a23..0000000 --- a/PowerReddit.psm1 +++ /dev/null @@ -1,77 +0,0 @@ -<# -.SYNOPSIS - Gets a list of Reddit links - -.DESCRIPTION - Uses the Reddit API to get Reddit links from given subreddit(s) - -.PARAMETER Name - Name of the Subreddit to fetch from. Can be an array. - -#> -function Get-RedditLink -{ -[CmdletBinding()] -Param ( - [Parameter(Position=1, Mandatory=$false, ValueFromPipelineByPropertyName=$true)] - [Alias("r","Subreddit")] - [string[]] - $Name = 'frontpage' - ) - - # Construct the Uri. Multiple subreddits can be joined with plusses - $uri = 'http://www.reddit.com/r/{0}.json' -f [string]::Join('+', $Name) - - # This is the listing. Contains before/after for pagination, and links - $listing = (Invoke-RestMethod $uri) | Where kind -eq 'Listing' | Select -Expand data - - # Links have type "t3" in Reddit API - $links = $listing.children | Where kind -eq 't3' | select -expand data - - # Return the links with a custom type of [PowerReddit.Link]. We do this so - # that they can be extended by psxml files, etc. - $links | %{ $_.PSObject.TypeNames.Insert(0,'PowerReddit.Link'); $_ } - -} - - -<# -.SYNOPSIS - Gets comments of a Reddit link - -.DESCRIPTION - Uses the Reddit API to get comments made on a given link - -.PARAMETER id - Internal id of the Reddit link - -#> -function Get-RedditComment -{ -[CmdletBinding()] -Param ( - [Parameter( - Position = 1, - Mandatory = $true, - ValueFromPipelineByPropertyName = $true - )] - [Alias("Link")] - [string] - $id - ) - - Process - { - $uri = 'http://www.reddit.com/comments/{0}.json' -f $id - - $listings = (Invoke-RestMethod $uri) | Where kind -eq 'Listing' - - # Comments have a type 't1' in Reddit API - $comments = $listings | %{ $_.data.children } | Where kind -eq 't1' | Select -Expand data - - $comments | %{ $_.PSObject.TypeNames.Insert(0,'PowerReddit.Comment'); $_ } - } -} - - -Export-ModuleMember -function Get-RedditLink, Get-RedditComment