ghost

package module
v0.0.0-...-b96d757 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 12 Imported by: 0

README

Go Client for Ghost Blogs

Ghost Client (ContentAPI + AdminAPI)

Supported features

Generic
  • Upload images
Posts
  • Add post
  • Get posts
  • Update post
  • Delete post
Pages
  • Add page
  • Get pages
  • Update page
  • Delete page
Tags
  • Add tag
  • Get tags
  • Update tag
  • Delete tag
Members
  • Add member
  • Get members
  • Update member
Images
  • Add image
package main

import (
	"fmt"
	"github.com/sklinkert/ghost"
)

func main() {
	contentAPIToken := "837484..."
	adminAPIToken := "90968696..."
	ghostAPI := ghost.New("https://example.com", contentAPIToken, adminAPIToken)

	posts, err := ghostAPI.GetPosts()
	if err != nil {
		fmt.Printf("cannot get posts from ghost api: %v\n", err)
		return
	}

	for _, post := range posts.Posts {
		fmt.Println(post.Title)

		// Update existing post
		post.Title = "new title"
		if err := ghostAPI.AdminUpdatePost(post); err != nil {
			fmt.Printf("update failed: %v\n", err)
			break
		}
	}
	
	// Upload new image
	imageURL, err := ghostAPI.AdminUploadImage("./myimage.jpg")
	if err != nil {
		fmt.Printf("Image upload failed: %v\n", err)
	}
	fmt.Println(imageURL)
}

Documentation

Index

Constants

View Source
const StatusPublished = "published"

StatusPublished indicates if a post or pages is already published

Variables

This section is empty.

Functions

This section is empty.

Types

type Ghost

type Ghost struct {
	// contains filtered or unexported fields
}

func New

func New(url, contentAPIToken, adminAPIToken string) *Ghost

New creates new instance of ghost API client

func (*Ghost) AdminCreateMember

func (g *Ghost) AdminCreateMember(member NewMember) (Members, error)

func (*Ghost) AdminCreatePost

func (g *Ghost) AdminCreatePost(post Post) (Posts, error)

func (*Ghost) AdminCreateTags

func (g *Ghost) AdminCreateTags(tags NewTags) error

func (*Ghost) AdminDeleteTag

func (g *Ghost) AdminDeleteTag(tag Tag) error

func (*Ghost) AdminGetMembers

func (g *Ghost) AdminGetMembers() (Members, error)

func (*Ghost) AdminGetPosts

func (g *Ghost) AdminGetPosts() (Posts, error)

func (*Ghost) AdminGetPostsByTag

func (g *Ghost) AdminGetPostsByTag(tag string) (Posts, error)

func (*Ghost) AdminGetTags

func (g *Ghost) AdminGetTags() (Tags, error)

func (*Ghost) AdminUpdatePost

func (g *Ghost) AdminUpdatePost(post Post) error

func (*Ghost) AdminUpdateTag

func (g *Ghost) AdminUpdateTag(tag Tag) error

func (*Ghost) AdminUploadImage

func (g *Ghost) AdminUploadImage(path string) (imageURL string, err error)

AdminUploadImage - Creates a new file upload http request

func (*Ghost) GetPages

func (g *Ghost) GetPages() (Pages, error)

func (*Ghost) GetPosts

func (g *Ghost) GetPosts() (Posts, error)

func (*Ghost) GetPostsByTag

func (g *Ghost) GetPostsByTag(tag string) (Posts, error)

type Image

type Image struct {
	URL string
}

type ImageResponse

type ImageResponse struct {
	Images []Image
}

type Member

type Member struct {
	Id          string      `json:"id"`
	Uuid        string      `json:"uuid"`
	Email       string      `json:"email"`
	Name        string      `json:"name"`
	Note        interface{} `json:"note"`
	Geolocation interface{} `json:"geolocation"`
	Subscribed  bool        `json:"subscribed"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
	Labels      []struct {
		Id        string    `json:"id"`
		Name      string    `json:"name"`
		Slug      string    `json:"slug"`
		CreatedAt time.Time `json:"created_at"`
		UpdatedAt time.Time `json:"updated_at"`
	} `json:"labels"`
	Subscriptions    []Subscription `json:"subscriptions"`
	AvatarImage      string         `json:"avatar_image"`
	EmailCount       int            `json:"email_count"`
	EmailOpenedCount int            `json:"email_opened_count"`
	EmailOpenRate    float64        `json:"email_open_rate"`
	Status           string         `json:"status"`
}

type Members

type Members struct {
	Members []Member `json:"members"`
}

type NewMember

type NewMember struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type NewMembers

type NewMembers struct {
	Members []NewMember `json:"members"`
}

type NewTag

type NewTag struct {
	CreatedAt          time.Time `json:"created_at,omitempty"`
	Description        string    `json:"description,omitempty"`
	FeatureImage       string    `json:"feature_image,omitempty"`
	Id                 string    `json:"id,omitempty"`
	MetaDescription    string    `json:"meta_description,omitempty"`
	MetaTitle          string    `json:"meta_title,omitempty"`
	Name               string    `json:"name,omitempty"`
	Slug               string    `json:"slug,omitempty"`
	UpdatedAt          time.Time `json:"updated_at,omitempty"`
	Url                string    `json:"url,omitempty"`
	Visibility         string    `json:"visibility,omitempty"`
	TwitterImage       string    `json:"twitter_image,omitempty"`
	TwitterTitle       string    `json:"twitter_title,omitempty"`
	TwitterDescription string    `json:"twitter_description,omitempty"`
	CodeInjectionHead  string    `json:"codeinjection_head,omitempty"`
	CodeInjectionFoot  string    `json:"codeinjection_foot,omitempty"`
	CanonicalURL       string    `json:"canonical_url,omitempty"`
	AccentColor        string    `json:"accent_color,omitempty"`
}

NewTag - two struct because field "Count" must not exist when creating a new tag

type NewTags

type NewTags struct {
	Tags []NewTag `json:"tags"`
}

type Page

type Page struct {
	ID                 string `json:"id,omitempty"`
	UUID               string `json:"uuid,omitempty"`
	Title              string `json:"title,omitempty"`
	MobileDoc          string `json:"mobiledoc"`
	Slug               string `json:"slug,omitempty"`
	HTML               string `json:"html,omitempty"`
	CommentID          string `json:"comment_id,omitempty"`
	FeatureImage       string `json:"feature_image,omitempty"`
	Featured           bool   `json:"featured,omitempty"`
	Page               bool   `json:"page,omitempty"`
	MetaTitle          string `json:"meta_title,omitempty"`
	MetaDescription    string `json:"meta_description,omitempty"`
	CreatedAt          string `json:"created_at,omitempty"`
	UpdatedAt          string `json:"updated_at,omitempty"`
	PublishedAt        string `json:"published_at,omitempty"`
	CustomExcerpt      string `json:"custom_excerpt,omitempty"`
	OGImage            string `json:"og_image,omitempty"`
	OGTitle            string `json:"og_title,omitempty"`
	OGDescription      string `json:"og_description,omitempty"`
	TwitterImage       string `json:"twitter_image,omitempty"`
	TwitterTitle       string `json:"twitter_title,omitempty"`
	TwitterDescription string `json:"twitter_description,omitempty"`
	CustomTemplate     string `json:"custom_template,omitempty"`
	URL                string `json:"url,omitempty"`
	Excerpt            string `json:"excerpt,omitempty"`
}

type Pages

type Pages struct {
	Pages []Page `json:"pages"`
}

type Post

type Post struct {
	ID                 string `json:"id,omitempty"`
	UUID               string `json:"uuid,omitempty"`
	Title              string `json:"title,omitempty"`
	MobileDoc          string `json:"mobiledoc,omitempty"`
	Slug               string `json:"slug,omitempty"`
	HTML               string `json:"html,omitempty"`
	CommentID          string `json:"comment_id,omitempty"`
	FeatureImage       string `json:"feature_image,omitempty"`
	Featured           bool   `json:"featured,omitempty"`
	Page               bool   `json:"page,omitempty"`
	MetaTitle          string `json:"meta_title,omitempty"`
	MetaDescription    string `json:"meta_description,omitempty"`
	CreatedAt          string `json:"created_at,omitempty"`   // "2022-01-05T22:39:28.000Z"
	UpdatedAt          string `json:"updated_at,omitempty"`   // "2022-04-02T16:01:24.000Z"
	PublishedAt        string `json:"published_at,omitempty"` // "2022-01-19T06:31:00.000Z"
	CustomExcerpt      string `json:"custom_excerpt,omitempty"`
	OGImage            string `json:"og_image,omitempty"`
	OGTitle            string `json:"og_title,omitempty"`
	OGDescription      string `json:"og_description,omitempty"`
	TwitterImage       string `json:"twitter_image,omitempty"`
	TwitterTitle       string `json:"twitter_title,omitempty"`
	TwitterDescription string `json:"twitter_description,omitempty"`
	CustomTemplate     string `json:"custom_template,omitempty"`
	URL                string `json:"url,omitempty"`
	Excerpt            string `json:"excerpt,omitempty"`
	Tags               []Tag  `json:"tags,omitempty"`
	Status             string `json:"status,omitempty"`     // "published"
	Visibility         string `json:"visibility,omitempty"` // "public"
}

type Posts

type Posts struct {
	Posts []Post `json:"posts"`
}

type Subscription

type Subscription struct {
	Id       string `json:"id"`
	Customer struct {
		Id    string `json:"id"`
		Name  string `json:"name"`
		Email string `json:"email"`
	} `json:"customer"`
	Status                  string    `json:"status"`
	StartDate               time.Time `json:"start_date"`
	DefaultPaymentCardLast4 string    `json:"default_payment_card_last4"`
	CancelAtPeriodEnd       bool      `json:"cancel_at_period_end"`
	CancellationReason      string    `json:"cancellation_reason"`
	CurrentPeriodEnd        time.Time `json:"current_period_end"`
	Price                   struct {
		Id       string `json:"id"`
		PriceId  string `json:"price_id"`
		Nickname string `json:"nickname"`
		Amount   int    `json:"amount"`
		Interval string `json:"interval"`
		Type     string `json:"type"`
		Currency string `json:"currency"`
	} `json:"price"`
}

type Tag

type Tag struct {
	CreatedAt          time.Time `json:"created_at,omitempty"`
	Description        string    `json:"description,omitempty"`
	FeatureImage       string    `json:"feature_image,omitempty"`
	Id                 string    `json:"id,omitempty"`
	MetaDescription    string    `json:"meta_description,omitempty"`
	MetaTitle          string    `json:"meta_title,omitempty"`
	Name               string    `json:"name,omitempty"`
	Slug               string    `json:"slug,omitempty"`
	UpdatedAt          time.Time `json:"updated_at,omitempty"`
	Url                string    `json:"url,omitempty"`
	Visibility         string    `json:"visibility,omitempty"`
	TwitterImage       string    `json:"twitter_image,omitempty"`
	TwitterTitle       string    `json:"twitter_title,omitempty"`
	TwitterDescription string    `json:"twitter_description,omitempty"`
	CodeInjectionHead  string    `json:"codeinjection_head,omitempty"`
	CodeInjectionFoot  string    `json:"codeinjection_foot,omitempty"`
	CanonicalURL       string    `json:"canonical_url,omitempty"`
	AccentColor        string    `json:"accent_color,omitempty"`
	Count              struct {
		Posts int `json:"posts,omitempty"`
	} `json:"count,omitempty,skip"`
}

type Tags

type Tags struct {
	Tags []Tag `json:"tags"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL