Skip to content

Commit

Permalink
utf-8 support on requests
Browse files Browse the repository at this point in the history
  • Loading branch information
MVKozlov committed Jan 27, 2021
1 parent fcaabb0 commit 9ad1bbe
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 40 deletions.
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Add-GDriveItemPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Params = New-Object System.Collections.ArrayList
# Always return all properties.
Expand All @@ -102,6 +101,7 @@ param(
}
}
$Uri = '{0}{1}/permissions?supportsAllDrives=true&{2}' -f $GDriveUri, $ID, ($Params -join '&')
Write-Verbose "URI: $Uri"
$Body = @{
role = $Role
type = $Type
Expand All @@ -121,6 +121,11 @@ param(
}
$JsonProperty = ConvertTo-Json $Body
Write-Verbose "RequestBody: $JsonProperty"
Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers @GDriveProxySettings -Body $JsonProperty
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Post -Body $JsonProperty @GDriveProxySettings
}
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/Clear-GDriveTrash.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
Invoke-RestMethod -Uri $GDriveTrashUri -Method Delete -Headers $Headers @GDriveProxySettings
$requestParams = @{
Uri = $GDriveTrashUri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Delete @GDriveProxySettings
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/Copy-GDriveItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}

# Full property set will be supported after the rain on Thursday ;-)
Expand All @@ -70,6 +69,11 @@ param(
Write-Verbose "Copy URI: $Uri"
Write-Verbose "Copy Metadata: $JsonProperty"
if ($PSCmdlet.ShouldProcess("Copy item $ID")) {
Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $JsonProperty @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Post -Body $JsonProperty @GDriveProxySettings
}
}
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Find-GDriveItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ param(

$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
Write-Verbose "URI: $GDriveUri"
$Params = New-Object System.Collections.ArrayList
Expand Down Expand Up @@ -91,6 +90,12 @@ param(
}
else {
$Uri = '{0}?supportsAllDrives=true&{1}' -f $GDriveUri, ($Params -join '&')
Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings
Write-Verbose "URI: $Uri"
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings
}
}
8 changes: 4 additions & 4 deletions GMGoogleDrive/Public/Get-GDriveError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Get GoogleDrive Error responce
.DESCRIPTION
Get GoogleDrive Error responce
.PARAMETER Error
.PARAMETER ErrorRecord
Error record to decode
.PARAMETER Exception
Exception object to decode
Expand All @@ -20,7 +20,7 @@ function Get-GDriveError {
[CmdletBinding(DefaultParameterSetName='ex')]
param(
[Parameter(Mandatory, Position=0, ParameterSetName='er')]
[System.Management.Automation.ErrorRecord]$Error,
[System.Management.Automation.ErrorRecord]$ErrorRecord,

[Parameter(Mandatory, Position=0, ParameterSetName='ex')]
[Exception]$Exception
Expand All @@ -31,8 +31,8 @@ param(
Message = ''
Error = ''
}
if ($Error) {
$Exception = $Error.Exception
if ($ErrorRecord) {
$Exception = $ErrorRecord.Exception
}
if ($Exception) {
$result.Type = $Exception.GetType()
Expand Down
2 changes: 1 addition & 1 deletion GMGoogleDrive/Public/Get-GDriveItemContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ param(
}

$wr.Method = 'Get'
$wr.ContentType = "application/json"
$wr.ContentType = "application/json; charset=utf-8"
$wr.Headers.Add("Authorization", "Bearer $($AccessToken)")
Write-Verbose "ParameterSetName: $($PSCmdlet.ParameterSetName)"
Write-Verbose "Content Url: $Uri"
Expand Down
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Get-GDriveItemPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Params = New-Object System.Collections.ArrayList
# Always return all properties.
Expand All @@ -52,5 +51,11 @@ param(
[void]$Params.Add('useDomainAdminAccess=true')
}
$Uri = '{0}{1}/permissions/{2}?supportsAllDrives=true&{3}' -f $GDriveUri, $ID, $PermissionID, ($Params -join '&')
Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings
Write-Verbose "URI: $Uri"
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings
}
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Get-GDriveItemPermissionList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
if ($AllResults) {
[void]$PSBoundParameters.Remove('AllResults')
Expand Down Expand Up @@ -85,6 +84,12 @@ param(
[void]$Params.Add('pageToken=' + $NextPageToken)
}
$Uri = '{0}{1}/permissions/?supportsAllDrives=true&{2}' -f $GDriveUri, $ID, ($Params -join '&')
Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings
Write-Verbose "URI: $Uri"
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings
}
}
9 changes: 6 additions & 3 deletions GMGoogleDrive/Public/Get-GDriveItemProperty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Revision = if ($RevisionID) { '/revisions/' + $RevisionID } else { '' }
if ($Property -contains "*") {
Expand All @@ -64,6 +63,10 @@ param(
$Uri += '&fields={0}' -f ($Property -join ',')
}
Write-Verbose "URI: $Uri"

Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings
}
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Get-GDriveItemRevisionList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
if ($AllResults) {
[void]$PSBoundParameters.Remove('AllResults')
Expand Down Expand Up @@ -74,6 +73,12 @@ param(
[void]$Params.Add('pageToken=' + $NextPageToken)
}
$Uri = '{0}{1}/revisions/?supportsAllDrives=true&{2}' -f $GDriveUri, $ID, ($Params -join '&')
Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings
Write-Verbose "URI: $Uri"
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings
}
}
9 changes: 6 additions & 3 deletions GMGoogleDrive/Public/Get-GDriveSummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}

Invoke-RestMethod -Uri $GDriveAboutURI -Method Get -Headers $Headers @GDriveProxySettings
$requestParams = @{
Uri = $GDriveAboutURI
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/Move-GDriveItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ param(

$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
if ($PSCmdlet.ShouldProcess("Move item $ID to $($NewParentID -join ',')")) {
Invoke-RestMethod -Uri $Uri -Method Patch -Headers $Headers @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Patch @GDriveProxySettings
}
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/New-GDriveFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Uri = $GDriveUri + '?supportsAllDrives=true'
Write-Verbose "URI: $Uri"
$RequestBody = '{{ "name": "{0}", "mimeType": "application/vnd.google-apps.folder", "parents": ["{1}"] }}' -f $Name, ($ParentID -join '","')
Write-Verbose "RequestBody: $RequestBody"
if ($PSCmdlet.ShouldProcess("Create new folder $Name")) {
Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $RequestBody @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Post -Body $RequestBody @GDriveProxySettings
}
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/New-GDriveItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ function New-GDriveItem {

$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
# Full property set will be supported after the rain on Thursday ;-)
$Property = 'kind','id','name','mimeType','parents'
$Uri = '{0}?supportsAllDrives=true&fields={1}' -f $GDriveUri, ($Property -join ',')
Write-Verbose "URI: $Uri"
Write-Verbose "RequestBody: $JsonProperty"
if ($PSCmdlet.ShouldProcess("Create new item $Name")) {
Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $JsonProperty @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Post -Body $JsonProperty @GDriveProxySettings
}
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/Remove-GDriveItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ param(
if ($Permanently -or $RevisionID) {
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Revision = if ($RevisionID) { '/revisions/' + $RevisionID } else { '' }
$Uri = '{0}{1}{2}?{3}' -f $GDriveUri, $ID, $Revision, "?supportsAllDrives=true"
Write-Verbose "URI: $Uri"

if ($PSCmdlet.ShouldProcess("Remove Item $ID")) {
Invoke-RestMethod -Uri $Uri -Method Delete -Headers $Headers @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Delete @GDriveProxySettings
}
}
else {
Expand Down
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Remove-GDriveItemPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Params = New-Object System.Collections.ArrayList
# Always return all properties.
Expand All @@ -51,5 +50,11 @@ param(
[void]$Params.Add('useDomainAdminAccess=true')
}
$Uri = '{0}{1}/permissions/{2}?supportsAllDrives=true&{3}' -f $GDriveUri, $ID, $PermissionID, ($Params -join '&')
Invoke-RestMethod -Uri $Uri -Method Delete -Headers $Headers @GDriveProxySettings
Write-Verbose "URI: $Uri"
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Delete @GDriveProxySettings
}
2 changes: 1 addition & 1 deletion GMGoogleDrive/Public/Set-GDriveItemContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ function Set-GDriveItemContent {
try {
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
"X-Upload-Content-Type" = $ContentType
"X-Upload-Content-Length" = $stream.Length
}

$WebRequestParams = @{
Headers = $Headers
ContentType = "application/json; charset=utf-8"
MaximumRedirection = 0
UseBasicParsing = $true
Body = $JsonProperty
Expand Down
9 changes: 7 additions & 2 deletions GMGoogleDrive/Public/Set-GDriveItemPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Params = New-Object System.Collections.ArrayList
# Always return all properties.
Expand All @@ -76,6 +75,7 @@ param(
}
}
$Uri = '{0}{1}/permissions/{2}?supportsAllDrives=true&{3}' -f $GDriveUri, $ID, $PermissionID, ($Params -join '&')
Write-Verbose "URI: $Uri"
$Body = @{
role = $Role
}
Expand All @@ -84,5 +84,10 @@ param(
}
$JsonProperty = ConvertTo-Json $Body
Write-Verbose "RequestBody: $JsonProperty"
Invoke-RestMethod -Uri $Uri -Method Patch -Headers $Headers @GDriveProxySettings -Body $JsonProperty
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Patch -Body $JsonProperty @GDriveProxySettings
}
8 changes: 6 additions & 2 deletions GMGoogleDrive/Public/Set-GDriveItemProperty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ param(
)
$Headers = @{
"Authorization" = "Bearer $AccessToken"
"Content-type" = "application/json"
}
$Revision = if ($RevisionID) { '/revisions/' + $RevisionID } else { '' }
$Uri = '{0}{1}{2}?{3}' -f $GDriveUri, $ID, $Revision, "?supportsAllDrives=true"
Write-Verbose "URI: $Uri"

if ($PSCmdlet.ShouldProcess("Set property for item $ID")) {
Invoke-RestMethod -Uri $Uri -Method Patch -Headers $Headers -Body $JsonProperty @GDriveProxySettings
$requestParams = @{
Uri = $Uri
Headers = $Headers
ContentType = "application/json; charset=utf-8"
}
Invoke-RestMethod @requestParams -Method Patch -Body $JsonProperty @GDriveProxySettings
}
}

0 comments on commit 9ad1bbe

Please sign in to comment.