Post-Migrator/services/wordpress/create-post.go
2024-05-19 15:00:33 -06:00

39 lines
1013 B
Go

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"`
Date string `json:"date"`
}
type CreatePostResponse struct {
Id int `json:"id"`
Link string `json:"link"`
}
func (parameters *CreatePost) Execute(baseUrl, user, pass string) (CreatePostResponse, error) {
endpoint := baseUrl + "wp-json/wp/v2/posts"
body, err := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters)
if err != nil {
return CreatePostResponse{}, err
}
var post CreatePostResponse
err = json.Unmarshal(body, &post)
if err != nil {
return CreatePostResponse{}, err
}
utilities.CheckError(err)
return post, nil
}