-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublish-BloggerPost.ps1
More file actions
101 lines (76 loc) · 1.94 KB
/
Publish-BloggerPost.ps1
File metadata and controls
101 lines (76 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<#
.SYNOPSIS
Publish a blog post to Blogger.
.DESCRIPTION
Publish a blog post to blogger as a final or draft post
.PARAMETER BlogId
Required. The Id of the blog to publish the post to.
.PARAMETER PostId
Optional. The Id of the post to update. If not specified, a new post will be created.
.PARAMETER Title
Required. The title of the post.
.PARAMETER Content
Required. The content of the post in HTML format.
.PARAMETER Labels
Optional. An array of labels (tags) to apply to the post.
.PARAMETER Draft
Optional. If specified, the post will be saved as a draft instead of being published.
.PARAMETER Open
Optional. If specified, launches a browser to view the post after publishing.
#>
Function Publish-BloggerPost {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$BlogId,
[Parameter()]
[string]$PostId,
[Parameter(Mandatory = $true)]
[string]$Title,
[Parameter(Mandatory = $true)]
[string]$Content,
[Parameter(Mandatory = $false)]
[string[]]$Labels,
[Parameter(Mandatory = $false)]
[switch]$Draft,
[Parameter(Mandatory = $false)]
[switch]$Open
)
$uri = "https://www.googleapis.com/blogger/v3/blogs/$BlogId/posts"
$method = "POST"
# if the postId exists, we're performing an update
if ($PostId) {
$uri += "/$PostId"
$method = "PUT"
if (-not $Draft) {
$uri += "?publish=true"
}
}
else {
if ($Draft) {
$uri += "?isDraft=true"
}
}
$body = @{
kind = "blogger#post"
blog = @{
id = $BlogId
}
title = $Title
content = $Content
labels = $Labels
}
$body | ConvertTo-Json | Write-Verbose
$post = Invoke-GApi -Uri $uri -Body ($body | ConvertTo-Json) -Method $method
if ($Open) {
$postUrl = `
if ($Draft) {
"https://www.blogger.com/blog/post/edit/preview/$BlogId/$($post.id)"
}
else {
$post.url
}
Start-Process $postUrl
}
return $post
}