Last active
April 9, 2018 23:30
-
-
Save TylerLeonhardt/4783f45980948c95c8f06674f1ee3325 to your computer and use it in GitHub Desktop.
"Not Hotdog" VSCode PowerShell Demo for PowerShell Summit - https://github.com/powershell/vscode-powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"hotdogs":[ | |
{ | |
"url":"https://potatorolls.com/wp-content/uploads/Basic-Hot-Dogs.jpg", | |
"title":"Basic hotdogs" | |
}, | |
{ | |
"url":"https://www.dairyqueen.com/PageFiles/1089/dq-sides-hotdog.png?width=&height=810", | |
"title":"classic hotdog" | |
}, | |
{ | |
"url":"https://www.seriouseats.com/recipes/images/2016/06/20160623-cubano-roast-pork-sandwich-recipe-19-1500x1125.jpg", | |
"title":"Definitely a hotdog" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
USAGE: | |
# Basic usages | |
Invoke-NotHotdog $url | |
$urls | Invoke-NotHotdog | |
# With Raw that returns true/false | |
Invoke-NotHotdog $url -Raw | |
NOTE: | |
You need to follow along to: | |
https://docs.microsoft.com/en-us/sandbox/demos/nothotdog | |
And update the $functionUrl to yours. | |
WHY: | |
"Not Hotdog" VSCode PowerShell Demo for PowerShell Summit - https://github.com/powershell/vscode-powershell | |
#> | |
$functionUrl = "https://<YOUR_FUNCTION_NAME_HERE>.azurewebsites.net/api/NotHotdog" | |
function Invoke-NotHotdog { | |
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipeline=$true)] | |
[string] | |
$Url, | |
[switch] | |
$Raw | |
) | |
$result = Invoke-RestMethod "$functionUrl?url=$Url" | |
if ($Raw) { | |
return $result.isHotdog | |
} else { | |
return $result | |
} | |
} | |
function Get-NotHotdogNotes { | |
Write-Host "This is a super serious PowerShell script." | |
Write-Host ".`n.`n." | |
Write-Host "kinda.`n" | |
Write-Host "All it does is wrap the awesome Azure Function by Brian Peek." | |
Write-Host "Here's the url for reference:" | |
Write-Host "https://docs.microsoft.com/en-us/sandbox/demos/nothotdog" | |
} | |
# Easter egg | |
function Invoke-Octocat { | |
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipeline=$true)] | |
[string] | |
$Value | |
) | |
# If we got input, add it to the url | |
$url = "https://api.github.com/octocat" | |
If ($Value) { | |
$url = $url += "?s=$Value" | |
} | |
# Use GitHub's API | |
Invoke-RestMethod $url | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using module ./NotHotdog.psm1 | |
# ipmo ./NotHotdog.psm1 | |
$hotdogs = Get-Content ./hotdogs.json -Raw | ConvertFrom-Json | |
Get-NotHotdogNotes | |
$hotdogs.hotdogs | ForEach-Object { | |
$result = Invoke-NotHotdog $_.url | |
if ($result.IsHotdog -eq "false") { | |
throw "Expected Nothotdog test to return true for truthset!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment