Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
erwindevreugd committed Nov 2, 2017
0 parents commit 6fbc087
Show file tree
Hide file tree
Showing 26 changed files with 1,759 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
111 changes: 111 additions & 0 deletions PSTruPortal.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@{

# Script module or binary module file associated with this manifest.
RootModule = 'PSTruPortal.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'

# ID used to uniquely identify this module
GUID = '2fad793b-41bf-4236-afc1-44a345bf8f30'

# Author of this module
Author = 'Erwin de Vreugd'

# Company or vendor of this module
#CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) 2017 Erwin de Vreugd. All rights reserved.'

# Description of the functionality provided by this module
Description = 'PowerShell module for the Interlogix TruPortal API'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '3.0'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
#FormatsToProcess = ''

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess.
# This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Interlogix','TruPortal')

# A URL to the license for this module.
LicenseUri = 'https://github.com/erwindevreugd/PSTruPortal/blob/master/LICENSE.txt'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/erwindevreugd/PSTruPortal'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}
35 changes: 35 additions & 0 deletions PSTruPortal.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (($PSVersionTable.PSVersion).Major -lt 3) {
Write-Warning ("PSTruPortal is not supported on PowerShell $($psv) and requires at least PowerShell 3.0`n" +
"To download version 3.0, please visit https://www.microsoft.com/en-us/download/details.aspx?id=34595`n")

return
}

Foreach($import in @(Get-ChildItem -Path $PSScriptRoot\Private\*.ps1))
{
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}

$functions = New-Object System.Collections.ArrayList

Foreach($import in @(Get-ChildItem -Path $PSScriptRoot\Public\*.ps1))
{
Try
{
. $import.fullname
$functions.Add($import.Basename)
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}

Export-ModuleMember -Function $functions
Empty file added Private/Enumerations.ps1
Empty file.
27 changes: 27 additions & 0 deletions Private/Functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function HashTableToUrlQuery([HashTable]$hashTable) {
$i = 0
$query = ''

foreach($key in $hashTable.Keys) {
$value = $hashTable[$key]

if($i -eq 0) {
$query = $query + "?$($key)=$($value)"
} else {
$query = $query + "&$($key)=$($value)"
}

$i++
}

return $query
}

function MapEnum($enum, $value, $default = $null) {
try {
[Enum]::GetValues($enum) | Where-Object { $_ -eq $value }
} catch {
Write-Error $_
return $default
}
}
6 changes: 6 additions & 0 deletions Private/ScriptContext.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$Script:Host=$null
$Script:Username=$null
$Script:SessionKey=$null
$Script:UseSSL=$true
$Script:IgnoreCertificateErrors=$false
$Script:Timestamp=$null
83 changes: 83 additions & 0 deletions Public/Get-AccessLevel.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function Get-AccessLevel {
[CmdletBinding()]
param (
[Parameter(
Position=0,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true
)]
[string]$Host = $Script:Host,

[Parameter(
Position=1,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true
)]
[string]$SessionKey = $Script:SessionKey,

[Parameter(
ValueFromPipelineByPropertyName=$true
)]
[switch]$UseSSL = $Script:UseSSL,

[Parameter(
ValueFromPipelineByPropertyName=$true
)]
[switch]$IgnoreCertificateErrors = $Script:IgnoreCertificateErrors,

[Parameter()]
[int]$Id,

[Parameter()]
[ValidateRange(1,250)]
[int]$Limit = 250
)

begin {
if($IgnoreCertificateErrors) {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
}
}

process {
$endPoint = "api/accessLevels"
$method = "GET"
$contentType = "application/json"
$uri = "http" + $(if($UseSSL) { "s" }) + "://$($Host)/$($endPoint)"

$headers = @{
Authorization=$SessionKey;
}

$query = @{
limit=$Limit;
}

if($Id) {
$uri = "$uri/$Id"
}

Write-Verbose -Message "$($method) $($uri) $($contentType)"
Write-Verbose -Message "Query:`n$(ConvertTo-Json $query)"

$message = @{
Uri=$uri;
Method=$method;
Body=$query;
ContentType=$contentType;
Headers=$headers;
UseBasicParsing=$true;
}
$response = Invoke-RestMethod @message
$response | ForEach-Object {
New-Object -TypeName PSObject -Property @{
Id=$_.id;
Name=$_.name;
}
}
}

end {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $null }
}
}
83 changes: 83 additions & 0 deletions Public/Get-ActionTrigger.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function Get-ActionTrigger {
[CmdletBinding()]
param (
[Parameter(
Position=0,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true
)]
[string]$Host = $Script:Host,

[Parameter(
Position=1,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true
)]
[string]$SessionKey = $Script:SessionKey,

[Parameter(
ValueFromPipelineByPropertyName=$true
)]
[switch]$UseSSL = $Script:UseSSL,

[Parameter(
ValueFromPipelineByPropertyName=$true
)]
[switch]$IgnoreCertificateErrors = $Script:IgnoreCertificateErrors,

[Parameter()]
[int]$Id,

[Parameter()]
[ValidateRange(1,250)]
[int]$Limit = 250
)

begin {
if($IgnoreCertificateErrors) {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
}
}

process {
$endPoint = "api/actionTriggers"
$method = "GET"
$contentType = "application/json"
$uri = "http" + $(if($UseSSL) { "s" }) + "://$($Host)/$($endPoint)"

$headers = @{
Authorization=$SessionKey;
}

$query = @{
limit=$Limit;
}

if($Id) {
$uri = "$uri/$Id"
}

Write-Verbose -Message "$($method) $($uri) $($contentType)"
Write-Verbose -Message "Query:`n$(ConvertTo-Json $query)"

$message = @{
Uri=$uri;
Method=$method;
Body=$query;
ContentType=$contentType;
Headers=$headers;
UseBasicParsing=$true;
}
$response = Invoke-RestMethod @message
$response | ForEach-Object {
New-Object -TypeName PSObject -Property @{
Id=$_.id;
Name=$_.name;
}
}
}

end {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $null }
}
}
Loading

0 comments on commit 6fbc087

Please sign in to comment.