create category
This commit is contained in:
parent
c0dacf4fb7
commit
45358bca52
31
main.go
31
main.go
@ -1,10 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"federated.computer/wp-sync-slowtwitch/services/wordpress"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
||||||
const wordpressKey = "admin"
|
const wordpressKey = "admin"
|
||||||
const wordpressSecret = "S34E keY1 A1uX 6ncs Rx4T f21W"
|
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 Create Category with or without parent + add to cache
|
||||||
// TODO Use cached data to correctly build post form submissions
|
// 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
22
services/wordpress/create-category.go
Normal file
22
services/wordpress/create-category.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user