diff --git a/main.go b/main.go index efd4401..49168ed 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,5 @@ package main -import ( - "federated.computer/wp-sync-slowtwitch/services/wordpress" - "fmt" -) - const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/" const wordpressKey = "admin" const wordpressSecret = "S34E keY1 A1uX 6ncs Rx4T f21W" @@ -15,30 +10,4 @@ func main() { // TODO Create Category with or without parent + add to cache // TODO Use cached data to correctly build post form submissions - categoryNames := []string{"testcat", "testcat3", "you wont find me"} - - for _, categoryName := range categoryNames { - categoryData, ok := wordpress.GetCategory(categoryName, baseUrl, wordpressKey, wordpressSecret) - - if ok { - appCache.SetCategory(categoryData) - fmt.Println(categoryData.Name, categoryData.Id, categoryData.ParentId) - } else { - fmt.Println("not found on website: ", categoryName) - } - } - - for _, categoryName := range categoryNames { - category, ok := appCache.GetCategory(categoryName) - - if ok { - fmt.Println("Found single in cache: ", category.Name) - } else { - fmt.Println("Not found in cache:", categoryName) - } - } - - for _, category := range appCache.CategoryCache { - fmt.Println("From Cache: ", category.Name) - } } diff --git a/services/wordpress/create-category.go b/services/wordpress/create-category.go new file mode 100644 index 0000000..98190b2 --- /dev/null +++ b/services/wordpress/create-category.go @@ -0,0 +1,22 @@ +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"` + Slug string `json:"slug"` +} + +func (parameters *CreateCategory) Execute(baseUrl, user, pass string) CategoryData { + endpoint := baseUrl + "categories" + body := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters) + var category CategoryData + err := json.Unmarshal(body, &category) + utilities.CheckError(err) + return category +}