Skip to content

Commit a906ea6

Browse files
committed
Added Export-Raindrop cmdlet
1 parent b55c9e1 commit a906ea6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function Export-Raindrop {
2+
param (
3+
[Parameter(Mandatory)]
4+
[string] $ApiToken,
5+
6+
[Parameter(Mandatory = $false)]
7+
[int] $CollectionId = 0,
8+
9+
[Parameter(Mandatory = $true)]
10+
[ValidateSet("csv", "html", "zip")]
11+
[string] $Format,
12+
13+
[Parameter(Mandatory = $false)]
14+
[string] $OutFile,
15+
16+
[Parameter(Mandatory = $false)]
17+
[ValidateSet('-created', 'created', 'score', '-sort', 'title', '-title', 'domain', '-domain')]
18+
[string] $Sort,
19+
20+
[Parameter(Mandatory = $false)]
21+
[string] $Search
22+
)
23+
24+
$headers = Get-RaindropAuthHeader -ApiToken $ApiToken
25+
26+
$params = @{}
27+
if ($PSBoundParameters.ContainsKey('Sort')) { $params['sort'] = $Sort }
28+
if ($PSBoundParameters.ContainsKey('Search')) { $params['search'] = $Search }
29+
30+
$queryString = ($params.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join '&'
31+
32+
$url = "$Global:RaindropBaseUrl/raindrops/$CollectionId/export.$($Format)?$queryString"
33+
34+
try {
35+
if ([string]::IsNullOrEmpty($OutFile)) {
36+
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
37+
return $response
38+
}
39+
else {
40+
Invoke-WebRequest -Uri $url -Headers $headers -Method Get -OutFile $OutFile
41+
}
42+
}
43+
catch {
44+
Write-Error "Failed to retrieve projects: $_"
45+
}
46+
}

0 commit comments

Comments
 (0)