-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!deploy v2.10.0 add support for Tasks API and resolve #67
## 2.10.0 * Added: `Clear-GSTasklist`, `Get-GSTask`, `Get-GSTasklist`, `Move-GSTask`, `New-GSTask`, `New-GSTasklist`, `Remove-GSTask`, `Remove-GSTasklist`, `Update-GSTask` & `Update-GSTasklist` * These will allow full use of the Tasks API from Google. * **Please see the updated [Initial Setup guide](https://github.com/scrthq/PSGSuite/wiki/Initial-Setup#adding-api-client-access-in-admin-console) to update your API access for the new Scope list and enable the Tasks API in your project in the Developer Console!**
- Loading branch information
Showing
62 changed files
with
1,001 additions
and
202,835 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<# | ||
This is a quick helper script to get PSGSuite loaded in Debug Mode. | ||
Debug Mode exports the following additional functions with PSGSuite: | ||
- Get-GSToken: Used for legacy functions that require calling Google's REST API directly | ||
- New-GoogleService: Used in all SDK based functions to build out the service client | ||
#> | ||
|
||
# Enable Debug Mode to export the New-GoogleService function during module import | ||
# by setting the environment variable '$env:EnablePSGSuiteDebug' to $true | ||
$env:EnablePSGSuiteDebug = $true | ||
|
||
# Force import the module in the repo path so that updated functions are reloaded | ||
Import-Module (Join-Path (Join-Path "$PSScriptRoot" "PSGSuite") "PSGSuite.psd1") -Force |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
function Clear-GSTasklist { | ||
<# | ||
.SYNOPSIS | ||
Clears all completed tasks from the specified task list. The affected tasks will be marked as 'hidden' and no longer be returned by default when retrieving all tasks for a task list | ||
.DESCRIPTION | ||
Clears all completed tasks from the specified task list. The affected tasks will be marked as 'hidden' and no longer be returned by default when retrieving all tasks for a task list | ||
.PARAMETER Tasklist | ||
The unique Id of the Tasklist to clear | ||
.PARAMETER User | ||
The User who owns the Tasklist. | ||
Defaults to the AdminUser's email. | ||
.EXAMPLE | ||
Clear-GSTasklist -Tasklist 'MTA3NjIwMjA1NTEzOTk0MjQ0OTk6NTMyNDY5NDk1NDM5MzMxO' -Confirm:$false | ||
Clears the specified Tasklist owned by the AdminEmail user and skips the confirmation check | ||
#> | ||
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact = "High")] | ||
Param | ||
( | ||
[parameter(Mandatory = $true,Position = 0,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true)] | ||
[Alias('Id')] | ||
[String[]] | ||
$Tasklist, | ||
[parameter(Mandatory = $false,Position = 1)] | ||
[Alias("PrimaryEmail","UserKey","Mail","Email")] | ||
[ValidateNotNullOrEmpty()] | ||
[String] | ||
$User = $Script:PSGSuite.AdminEmail | ||
) | ||
Begin { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/tasks' | ||
ServiceType = 'Google.Apis.Tasks.v1.TasksService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
} | ||
Process { | ||
foreach ($list in $Tasklist) { | ||
try { | ||
if ($PSCmdlet.ShouldProcess("Clearing Tasklist '$list' for user '$User'")) { | ||
$request = $service.Tasks.Clear($list) | ||
$request.Execute() | ||
Write-Verbose "Successfully cleared Tasklist '$list' for user '$User'" | ||
} | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
function Get-GSTask { | ||
<# | ||
.SYNOPSIS | ||
Gets a specific Task or the list of Tasks | ||
.DESCRIPTION | ||
Gets a specific Task or the list of Tasks | ||
.PARAMETER User | ||
The User who owns the Task. | ||
Defaults to the AdminUser's email. | ||
.PARAMETER Task | ||
The unique Id of the Task. | ||
If left blank, returns the list of Tasks on the Tasklist | ||
.PARAMETER Tasklist | ||
The unique Id of the Tasklist the Task is on. | ||
.PARAMETER PageSize | ||
Page size of the result set | ||
.EXAMPLE | ||
Get-GSTasklist | ||
Gets the list of Tasklists owned by the AdminEmail user | ||
.EXAMPLE | ||
Get-GSTasklist -Tasklist MTUzNTU0MDYscM0NjKDMTIyNjQ6MDow -User john@domain.com | ||
Gets the Tasklist matching the provided Id owned by John | ||
#> | ||
[cmdletbinding(DefaultParameterSetName = "List")] | ||
Param | ||
( | ||
[parameter(Mandatory = $false,Position = 0,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")] | ||
[Alias('Id')] | ||
[String[]] | ||
$Task, | ||
[parameter(Mandatory = $true,Position = 1)] | ||
[String] | ||
$Tasklist, | ||
[parameter(Mandatory = $false)] | ||
[Alias("PrimaryEmail","UserKey","Mail","Email")] | ||
[ValidateNotNullOrEmpty()] | ||
[String] | ||
$User = $Script:PSGSuite.AdminEmail, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[DateTime] | ||
$CompletedMax, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[DateTime] | ||
$CompletedMin, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[DateTime] | ||
$DueMax, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[DateTime] | ||
$DueMin, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[DateTime] | ||
$UpdatedMin, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[Switch] | ||
$ShowCompleted, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[Switch] | ||
$ShowDeleted, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[Switch] | ||
$ShowHidden, | ||
[parameter(Mandatory = $false,ParameterSetName = "List")] | ||
[ValidateRange(1,100)] | ||
[Alias("MaxResults")] | ||
[Int] | ||
$PageSize | ||
) | ||
Begin { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/tasks.readonly' | ||
ServiceType = 'Google.Apis.Tasks.v1.TasksService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
} | ||
Process { | ||
switch ($PSCmdlet.ParameterSetName) { | ||
Get { | ||
foreach ($T in $Task) { | ||
try { | ||
Write-Verbose "Getting Task '$T' from Tasklist '$Tasklist' for user '$User'" | ||
$request = $service.Tasks.Get($Tasklist,$T) | ||
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
List { | ||
try { | ||
Write-Verbose "Getting all Tasks from Tasklist '$Tasklist' for user '$User'" | ||
$request = $service.Tasks.List($Tasklist) | ||
foreach ($key in $PSBoundParameters.Keys | Where-Object {$request.PSObject.Properties.Name -contains $_}) { | ||
switch ($key) { | ||
Tasklist {} | ||
{$_ -in @('CompletedMax','CompletedMin','DueMax','DueMin','UpdatedMin')} { | ||
$request.$key = ($PSBoundParameters[$key]).ToString('o') | ||
} | ||
default { | ||
if ($request.PSObject.Properties.Name -contains $key) { | ||
$request.$key = $PSBoundParameters[$key] | ||
} | ||
} | ||
} | ||
} | ||
if ($PSBoundParameters.Keys -contains 'PageSize') { | ||
$request.MaxResults = $PSBoundParameters['PageSize'] | ||
} | ||
[int]$i = 1 | ||
do { | ||
$result = $request.Execute() | ||
$result.Items | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
$request.PageToken = $result.NextPageToken | ||
[int]$retrieved = ($i + $result.Items.Count) - 1 | ||
Write-Verbose "Retrieved $retrieved Tasks..." | ||
[int]$i = $i + $result.Items.Count | ||
} | ||
until (!$result.NextPageToken) | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.