Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
RobFaie committed Dec 11, 2019
1 parent 8810ee8 commit 4e82458
Show file tree
Hide file tree
Showing 56 changed files with 2,905 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
193 changes: 193 additions & 0 deletions PwshZendesk.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#
# Module manifest for module 'PwshZendesk'
#
# Generated by: Robert McLeod
#
# Generated on: 15/9/19
#

@{

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

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

# Supported PSEditions
CompatiblePSEditions = @(
'Core'
'Desktop'
)

# ID used to uniquely identify this module
GUID = 'fd14fe05-21fb-4dfb-969b-7012632b461e'

# Author of this module
Author = 'Telstra Purple DevSecOps'

# Company or vendor of this module
CompanyName = 'Telstra Purple Pty Ltd'

# Copyright statement for this module
Copyright = '(c) 2019 Telstra Purple Pty Ltd. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Wrapper for the Zendesk Rest API'

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

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

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

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# 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, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Add-Tag', 'Add-ZendeskTag'
'Connect-', 'Connect-Zendesk'
'Export-Organization', 'Export-ZendeskOrganization'
'Export-Sample', 'Export-ZendeskSample'
'Export-Ticket', 'Export-ZendeskTicket'
'Export-TicketEvent', 'Export-ZendeskTicketEvent'
'Export-User', 'Export-ZendeskUser'
'Get-Attachment', 'Get-ZendeskAttachment'
'Get-AuthenticatedUser', 'Get-ZendeskAuthenticatedUser'
'Get-Comment', 'Get-ZendeskComment'
'Get-Connection', 'Get-ZendeskConnection'
'Get-DeletedTicket', 'Get-ZendeskDeletedTicket'
'Get-DeletedUser', 'Get-ZendeskDeletedUser'
'Get-Group', 'Get-ZendeskGroup'
'Get-GroupMembership', 'Get-ZendeskGroupMembership'
'Get-Incident', 'Get-ZendeskIncident'
'Get-JobStatus', 'Get-ZendeskJobStatus'
'Get-OrganizationMembership', 'Get-ZendeskOrganizationMembership'
'Get-Problem', 'Get-ZendeskProblem'
'Get-SearchCount', 'Get-ZendeskSearchCount'
'Get-SuspendedTicket', 'Get-ZendeskSuspendedTicket'
'Get-Tag', 'Get-ZendeskTag'
'Get-Ticket', 'Get-ZendeskTicket'
'Get-TicketCollaborator', 'Get-ZendeskTicketCollaborator'
'Get-TicketEmailCC', 'Get-ZendeskTicketEmailCC'
'Get-TicketFollower', 'Get-ZendeskTicketFollower'
'Get-TicketRelated', 'Get-ZendeskTicketRelated'
'Get-User', 'Get-ZendeskUser'
'Get-UserRelated', 'Get-ZendeskUserRelated'
'Hide-Comment', 'Hide-ZendeskComment'
'Import-Ticket', 'Import-ZendeskTicket'
'Invoke-Method', 'Invoke-ZendeskMethod'
'Merge-Ticket', 'Merge-ZendeskTicket'
'Merge-User', 'Merge-ZendeskUser'
'New-Attachment', 'New-ZendeskAttachment'
'New-Group', 'New-ZendeskGroup'
'New-GroupMembership', 'New-ZendeskGroupMembership'
'New-OrganizationMembership', 'New-ZendeskOrganizationMembership'
'New-Ticket', 'New-ZendeskTicket'
'Remove-Attachment', 'Remove-ZendeskAttachment'
'Remove-Group', 'Remove-ZendeskGroup'
'Remove-GroupMembership', 'Remove-ZendeskGroupMembership'
'Remove-OrganizationMembership', 'Remove-ZendeskOrganizationMembership'
'Remove-SuspendedTicket', 'Remove-ZendeskSuspendedTicket'
'Remove-Tag', 'Remove-ZendeskTag'
'Remove-Ticket', 'Remove-ZendeskTicket'
'Remove-User', 'Remove-ZendeskUser'
'Restore-DeletedTicket', 'Restore-ZendeskDeletedTicket'
'Restore-SuspendedTicket', 'Restore-ZendeskSuspendedTicket'
'Search-', 'Search-Zendesk'
'Set-GroupMembershipAsDefault', 'Set-ZendeskGroupMembershipAsDefault'
'Set-OrganizationMembershipAsDefault', 'Set-ZendeskOrganizationMembershipAsDefault'
'Set-Tag', 'Set-ZendeskTag'
'Set-User', 'Set-ZendeskUser'
'Test-Connection', 'Test-ZendeskConnection'
'Update-Group', 'Update-ZendeskGroup'
'Update-Ticket', 'Update-ZendeskTicket'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
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 = @()

# A URL to the license for this module.
# LicenseUri = ''

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

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

# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# External dependent modules of this module
# ExternalModuleDependencies = @()

} # 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 = 'Zendesk'

}

10 changes: 10 additions & 0 deletions PwshZendesk.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Set-StrictMode -Version Latest

Get-ChildItem -Path "$PSScriptRoot\functions" -Filter '*.ps1' -Recurse | ForEach-Object {
. $_.FullName
Export-ModuleMember -Function $_.BaseName
}

$Script:NotConnectedMessage = 'No connection supplied or stored. Please either call `Connect-Zendesk` or call `Get-ZendeskConnection` and pass the result to all additional calls.'
$Script:InvalidConnection = 'Provided connection is invalid.'
61 changes: 61 additions & 0 deletions functions/Add-Tag.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

function Add-Tag {
[OutputType([PSCustomObject])]
[CmdletBinding(DefaultParameterSetName = 'Default')]
Param (

# Unique Id of ticket to add tags to
[Parameter(Mandatory = $true,
ParameterSetName = 'Ticket')]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$TicketId,

# Unique Id of organization to add tags to
[Parameter(Mandatory = $true,
ParameterSetName = 'Org')]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$OrganizationId,

# Unique Id of user to add tags to
[Parameter(Mandatory = $true,
ParameterSetName = 'User')]
[ValidateRange(1, [Int64]::MaxValue)]
[Int64]
$UserId,

# Tags to add to entity
[Parameter(Mandatory = $true)]
[String[]]
$Tag,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

switch ($PSCMDlet.ParameterSetName) {
'Ticket' {
$path = "/api/v2/tickets/$TicketId/tags.json"
}

'Org' {
$path = "/api/v2/organizations/$OrganizationId/tags.json"
}

'User' {
$path = "/api/v2/users/$UserId/tags.json"
}
}

$body = {
tags = $Tag
}

$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Body $body -Verbose:$VerbosePreference
$result

}
36 changes: 36 additions & 0 deletions functions/Connect-.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

function Connect- {
[OutputType([String])]
[CmdletBinding()]
Param (

# Zendesk subdomain
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Organization,

# Email address of user to log in
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Username,

# Zendesk API key retrieved from https://<organization>.zendesk.com/agent/admin/api/settings
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[SecureString]
$ApiKey
)

$context = Get-Connection @PSBoundParameters

if (Test-Connection -context $context) {
$Script:Context = $context
} else {
throw $Script:InvalidConnection
}

$true

}
25 changes: 25 additions & 0 deletions functions/Export-Organization.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

function Export-Organization {
[OutputType([PSCustomObject])]
[CMDletBinding()]
Param (

# Timestamp returned by the last Export or `0` for a new incremental export
[Parameter(Mandatory = $true)]
[ValidateRange(0, [Int64]::MaxValue)]
[Int64]
$Timestamp,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/incremental/organizations.json?start_time=$Timestamp"

$result = Invoke-Method -Context $Context -Path $path -Pagination $false -Verbose:$VerbosePreference
$result

}
31 changes: 31 additions & 0 deletions functions/Export-Sample.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

function Export-Sample {
[OutputType([PSCustomObject])]
[CMDletBinding()]
Param (

# Name of the entity to get a sample export for
[Parameter(Mandatory = $true)]
[ValidateSet('tickets', 'users', 'organizations')]
[String]
$EntityName,

# Timestamp returned by the last Export or `0` for a new incremental export
[Parameter(Mandatory = $true)]
[ValidateRange(0, [Int64]::MaxValue)]
[Int64]
$Timestamp,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/incremental/$EntityName/sample.json?start_time=$Timestamp"

$result = Invoke-Method -Context $Context -Path $path -Pagination $false -Verbose:$VerbosePreference
$result

}
26 changes: 26 additions & 0 deletions functions/Export-Ticket.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

function Export-Ticket {

[OutputType([PSCustomObject])]
[CMDletBinding()]
Param (

# Timestamp returned by the last Export or `0` for a new incremental export
[Parameter(Mandatory = $true)]
[ValidateRange(0, [Int64]::MaxValue)]
[Int64]
$Timestamp,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

$path = "/api/v2/incremental/tickets.json?start_time=$Timestamp"

$result = Invoke-Method -Context $Context -Path $path -Pagination $false -Verbose:$VerbosePreference
$result

}
Loading

0 comments on commit 4e82458

Please sign in to comment.