Skip to content

Commit

Permalink
Create Docs and Presentations
Browse files Browse the repository at this point in the history
Resolves #370
  • Loading branch information
FISHMANPET committed Mar 28, 2022
1 parent 9fd3e6d commit 4bfefc6
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
76 changes: 76 additions & 0 deletions PSGSuite/Public/Docs/New-GSDocument.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function New-GSDocument {
<#
.SYNOPSIS
Creates a new Document
.DESCRIPTION
Creates a new Document
.PARAMETER Title
The name of the new Document
.PARAMETER User
The user to create the Document for
.PARAMETER Launch
If $true, opens the new Document Url in your default browser
.EXAMPLE
New-GSDocument -Title "Finance Document" -Launch
Creates a new Document titled "Finance Document" and opens it in the browser on creation
#>
[OutputType('Google.Apis.Docs.v1.Data.Document')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $false,ValueFromPipeline = $true,Position = 0)]
[String]
$Title = "Untitled document",
[parameter(Mandatory = $false)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $false)]
[Alias('Open')]
[Switch]
$Launch
)
Begin {
if ($User -ceq 'me') {
$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Docs.v1.DocsService'
User = $User
}
$service = New-GoogleService @serviceParams
}
Process {
try {
$body = New-Object 'Google.Apis.Docs.v1.Data.Document'
$body.Title = $Title
Write-Verbose "Creating Document '$Title' for user '$User'"
$request = $service.Documents.Create($body)
$response = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru
if ($Launch) {
$DocumentUrl = (Get-GSDriveFile $response.DocumentId).WebViewLink
Write-Verbose "Launching new document at $DocumentUrl"
Start-Process $DocumentUrl
}
$response
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
76 changes: 76 additions & 0 deletions PSGSuite/Public/Slides/New-GSPresentation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function New-GSPresentation {
<#
.SYNOPSIS
Creates a new Presentation
.DESCRIPTION
Creates a new Presentation
.PARAMETER Title
The name of the new Presentation
.PARAMETER User
The user to create the Presentation for
.PARAMETER Launch
If $true, opens the new Presentation Url in your default browser
.EXAMPLE
New-GSPresentation -Title "Finance Presentation" -Launch
Creates a new Presentation titled "Finance Presentation" and opens it in the browser on creation
#>
[OutputType('Google.Apis.Slides.v1.Data.Presentation')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $false,ValueFromPipeline = $true,Position = 0)]
[String]
$Title = "Untitled presentation",
[parameter(Mandatory = $false)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $false)]
[Alias('Open')]
[Switch]
$Launch
)
Begin {
if ($User -ceq 'me') {
$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Slides.v1.SlidesService'
User = $User
}
$service = New-GoogleService @serviceParams
}
Process {
try {
$body = New-Object 'Google.Apis.Slides.v1.Data.Presentation'
$body.Title = $Title
Write-Verbose "Creating Presentation '$Title' for user '$User'"
$request = $service.Presentations.Create($body)
$response = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru
if ($Launch) {
$PresentationUrl = (Get-GSDriveFile $response.PresentationId).WebViewLink
Write-Verbose "Launching new presentation at $PresentationUrl"
Start-Process $PresentationUrl
}
$response
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}

0 comments on commit 4bfefc6

Please sign in to comment.