2024-05-07 22:03:15 +00:00
|
|
|
package wordpress
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"federated.computer/wp-sync-slowtwitch/utilities"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CreatePost struct {
|
|
|
|
Title string `json:"title"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
Excerpt string `json:"excerpt"`
|
|
|
|
FeaturedMedia int `json:"featured_media"`
|
|
|
|
Author int `json:"author"`
|
|
|
|
Tags []int `json:"tags"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Categories []int `json:"categories"`
|
|
|
|
Slug string `json:"slug"`
|
2024-05-08 22:06:15 +00:00
|
|
|
Date string `json:"date"`
|
2024-05-07 22:03:15 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 00:52:47 +00:00
|
|
|
type CreatePostResponse struct {
|
|
|
|
Id int `json:"id"`
|
|
|
|
Link string `json:"link"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (parameters *CreatePost) Execute(baseUrl, user, pass string) CreatePostResponse {
|
2024-05-15 23:37:42 +00:00
|
|
|
endpoint := baseUrl + "wp/v2/posts"
|
2024-05-07 22:03:15 +00:00
|
|
|
body := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters)
|
2024-05-08 00:52:47 +00:00
|
|
|
var post CreatePostResponse
|
2024-05-07 22:03:15 +00:00
|
|
|
err := json.Unmarshal(body, &post)
|
|
|
|
utilities.CheckError(err)
|
|
|
|
return post
|
|
|
|
}
|