Post-Migrator/services/wordpress/create-category.go

27 lines
659 B
Go
Raw Normal View History

2024-05-09 21:25:13 +00:00
package wordpress
import (
"encoding/json"
"federated.computer/wp-sync-slowtwitch/utilities"
)
type CreateCategory struct {
Name string `json:"name"`
Description string `json:"description"`
ParentId int `json:"parent"`
}
2024-05-17 18:49:55 +00:00
func (parameters *CreateCategory) Execute(baseUrl, user, pass string) (CategoryData, error) {
endpoint := baseUrl + "wp-json/wp/v2/categories"
2024-05-17 18:49:55 +00:00
body, err := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters)
if err != nil {
return CategoryData{}, err
}
2024-05-09 21:25:13 +00:00
var category CategoryData
2024-05-17 18:49:55 +00:00
err = json.Unmarshal(body, &category)
if err != nil {
return CategoryData{}, err
}
return category, nil
2024-05-09 21:25:13 +00:00
}