Skip to content

Commit

Permalink
!deploy v2.10.0 add support for Tasks API and resolve #67
Browse files Browse the repository at this point in the history
## 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
scrthq committed Jul 3, 2018
2 parents 3971ab8 + 52b7f2b commit 9747e64
Show file tree
Hide file tree
Showing 62 changed files with 1,001 additions and 202,835 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- TOC -->

- [Changelog](#changelog)
- [2.10.0](#2100)
- [2.9.0](#290)
- [2.8.1](#281)
- [2.8.0](#280)
Expand Down Expand Up @@ -39,6 +40,12 @@

<!-- /TOC -->

## 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!**

## 2.9.0

* Updated: Added `IsAdmin` switch parameter to `Update-GSUser`, allowing set or revoke SuperAdmin privileges for a user ([Issue #54](https://github.com/scrthq/PSGSuite/issues/54))
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Please follow these guidelines for any content being added:

### Enabling Debug Mode

To enable debug mode and export the `New-GoogleService` function with the module, you can run the `Debub Mode.ps1` script in the `tools` folder in the root of the repo or the following lines of code from the root of the repo in PowerShell:
To enable debug mode and export the `New-GoogleService` function with the module, you can run the `Debub Mode.ps1` script in the root of the repo or the following lines of code from the root of the repo in PowerShell:

```powershell
$env:EnablePSGSuiteDebug = $true
Expand Down
13 changes: 13 additions & 0 deletions DebugMode.ps1
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
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.9.0'
ModuleVersion = '2.10.0'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
4 changes: 3 additions & 1 deletion PSGSuite/PSGSuite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ catch {
}
finally {
$functionsToExport = if ($env:EnablePSGSuiteDebug) {
($Public.Basename + 'New-GoogleService')
$Public.Basename
'New-GoogleService'
'Get-GSToken'
}
else {
$Public.Basename
Expand Down
68 changes: 68 additions & 0 deletions PSGSuite/Public/Tasks/Clear-GSTasklist.ps1
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 $_
}
}
}
}
}
155 changes: 155 additions & 0 deletions PSGSuite/Public/Tasks/Get-GSTask.ps1
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 $_
}
}
}
}
}
}
Loading

0 comments on commit 9747e64

Please sign in to comment.