Created
July 3, 2018 02:38
-
-
Save brandonjjon/7ed8018e1bdffdd900a51786227b2564 to your computer and use it in GitHub Desktop.
Checks the status of a Jeep/Dodge/Chrysler order
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
[Jeep]::statusCheck("1C4HJXFG3JWXXXXXX") | |
class Jeep { | |
# Class properties | |
hidden $Options = @{ | |
Vin = ""; | |
Timer = 28800; | |
Types = @{ | |
BuildSheet = @{ | |
url = "https://www.jeep.com/webselfservice/BuildSheetServlet?vin="; | |
found = $false; | |
} | |
WindowSticker = @{ | |
url = "https://www.jeep.com/hostd/windowsticker/getWindowStickerPdf.do?vin="; | |
found = $false; | |
} | |
}; | |
Loop = $true | |
} | |
# Named Constructor | |
static [Jeep] statusCheck($Vin) { | |
return [Jeep]::New($Vin) | |
} | |
# Constructor | |
Jeep ([String] $Vin) { | |
$this.Options.Vin = $Vin | |
While ($this.Options.Loop) { | |
$this.checkBuildSheet() | |
$this.checkWindowSticker() | |
$this.handleLoop() | |
# Sleep for 8 hours before checking again | |
# Start-Sleep -Seconds 28800 | |
Start-Sleep -Seconds $this.Options.Timer | |
} | |
} | |
# Creates a timer to continually check for status updates | |
[Void] handleLoop() { | |
$continueLoop = $true | |
foreach ($type in $this.Options.Types.Keys) { | |
if ($this.Options.Types.$type.found) { | |
$continueLoop = $false | |
} else { | |
$continueLoop = $true | |
} | |
} | |
if (!$continueLoop) { | |
$this.log("Nothing left to check! Now exiting...") | |
exit | |
} | |
$this.log("I will check for you again soon!") | |
Write-Host "" | |
$this.Options.Loop = $continueLoop | |
} | |
# Sets the found status for the type of check | |
[Void] setStatus([String] $type, [Bool] $status) { | |
$this.Options.Types.$type.found = $status | |
} | |
# Gets the status for the type of check | |
[Bool] getStatus([String] $type) { | |
return $this.Options.Types.$type.found | |
} | |
# Wrapper for Write-Host, appends datetime or whatever you want to the output | |
[String] log([String] $data) { | |
return Write-Host "[$(Get-Date -Format g)] $data" | |
} | |
# Creates the request to the webpage | |
[Bool] Request([String] $type) { | |
if (!$this.Options.Types.ContainsKey($type)) { | |
throw "An incompatible type was provided. Please specify wether you want to check for a buildsheet or windowsticker" | |
} | |
$url = $this.Options.Types.$type.url + $this.Options.Vin | |
return (Invoke-WebRequest -Uri $url).Rawcontentlength -gt 1200 | |
} | |
# Checks for build sheet availability | |
[Void] checkBuildSheet() { | |
$type = "BuildSheet" | |
if (!$this.getStatus($type)) { | |
if ($this.Request($type)) { | |
$this.log("Build sheet available! Stand by, launching your browser...") | |
$this.setStatus($type, $true) | |
Start-Process ($this.Options.Types.$type.url + $this.Options.Vin) | |
} else { | |
$this.log("No build sheet detected :(") | |
} | |
} | |
} | |
# Checks for window sticker availability | |
[Void] checkWindowSticker() { | |
$type = "WindowSticker" | |
if (!$this.getStatus($type)) { | |
if ($this.Request($type)) { | |
$this.log("Window sticker available! Stand by, launching your browser...") | |
$this.setStatus($type, $true) | |
Start-Process ($this.Options.Types.$type.url + $this.Options.Vin) | |
} else { | |
$this.log("No window sticker detected :(") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment