ghost

package module
v0.0.0-...-09aee83 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	BaseAdminPath = "/ghost/api/v3/admin/"
)

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to the bool.

func Int

func Int(i int) *int

Int returns a pointer to the int.

func NewAdminTokenSource

func NewAdminTokenSource(key string) (oauth2.TokenSource, error)

NewAdminTokenSource returns a reusable oauth2.TokenSource that is backed by the AdminTokenSource implementation. It handles properly creating and renewing the JWT needed for communication with Ghost for token-based auth.

func String

func String(s string) *string

String returns a pointer to the string.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a reasonable string representation of types in the Ghost library. It does things like resolve pointers to their values and omits struct fields with nil values.

func Time

func Time(s string) *time.Time

Time creates a timestamp from the RFC3339 string and returns a pointer, ignoring any errors that occur during construction.

Types

type AdminAuthenticationService

type AdminAuthenticationService adminService

AdminAuthenticationService handles setting up, invitations, and password resets.

func (*AdminAuthenticationService) Setup

func (s *AdminAuthenticationService) Setup(details *SetupDetails) error

Setup initializes the Ghost instance.

type AdminClient

type AdminClient struct {
	BaseURL   *url.URL
	UserAgent string

	Authentication *AdminAuthenticationService
	Database       *AdminDatabaseService
	Posts          *AdminPostsService
	Redirects      *AdminRedirectsService
	Session        *AdminSessionService
	// contains filtered or unexported fields
}

An AdminClient manages communication with the Ghost Admin API

func NewAdminClient

func NewAdminClient(baseURL string, httpClient *http.Client) (*AdminClient, error)

NewAdminClient returns a new client for interacting with Ghost Admin endpoints. baseURL should be the base admin url of the intance, in most cases taking the form of e.g., https://blah.pubbit.io with no trailing slash. It may additionally contain the subpath, but that too must omit the trailing slash. httpClient should handle authentication itself

Example
ts, err := NewAdminTokenSource(ExampleAdminKey)
if err != nil {
	log.Fatal(err)
}

httpClient := oauth2.NewClient(context.Background(), ts)
client, err := NewAdminClient("https://demo.pubbit.io", httpClient)
if err != nil {
	log.Fatal(err)
}

client.Posts.List(nil)
Output:

func (*AdminClient) Do

func (c *AdminClient) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*AdminClient) NewRequest

func (c *AdminClient) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*AdminClient) NewUploadRequest

func (c *AdminClient) NewUploadRequest(urlStr string, writePart WriteFilePart, params map[string]string) (*http.Request, error)

NewUploadRequest does an upload request by doing a POST against the provided path. It calls out to writePart to write out the principal file part of the payload, then populates additional multipart params provided in params.

type AdminDatabaseService

type AdminDatabaseService adminService

AdminDatabaseService handles fetching and uploading the database.

func (*AdminDatabaseService) Export

func (s *AdminDatabaseService) Export() (*Database, error)

Export the database.

func (*AdminDatabaseService) Import

Import the database. Returns the list of problems (warnings), if any.

type AdminPostsService

type AdminPostsService adminService

AdminPostsService provides access to Post related functions in the Ghost Admin API.

func (*AdminPostsService) Get

func (s *AdminPostsService) Get(id string) (*Post, error)

Get fetches a post by id.

func (*AdminPostsService) List

func (s *AdminPostsService) List(listParams *ListParams) (*PostsResponse, error)

List fetches all posts via the ListParams.

type AdminRedirectsService

type AdminRedirectsService adminService

AdminRedirectsService handles downloading and uploading the redirects.json file.

func (*AdminRedirectsService) Download

func (s *AdminRedirectsService) Download() ([]*Redirect, error)

Download fetches the redirectsq

func (*AdminRedirectsService) Upload

func (s *AdminRedirectsService) Upload(redirects []*Redirect) error

Upload uploads the redirects.

type AdminSessionService

type AdminSessionService adminService

AdminSessionService handles establishing a cookie-based session with Ghost.

func (*AdminSessionService) Create

func (s *AdminSessionService) Create(username, password string) error

Create creates the session. The cookie should be set in the underlying http.Client cookiejar, allowing use of the session for the duration of the client.

type AdminTokenSource

type AdminTokenSource struct {
	Key string
}

AdminTokenSource is a token source for token-based authentication with the Ghost Admin API.

func (*AdminTokenSource) Token

func (ats *AdminTokenSource) Token() (*oauth2.Token, error)

Token returns the Ghost jwt token needed for token based authenication.

type Author

type Author struct {
	ID              *string    `json:"id"`
	Name            *string    `json:"name"`
	Slug            *string    `json:"slug"`
	Email           *string    `json:"email"`
	ProfileImage    *string    `json:"profile_image"`
	CoverImage      *string    `json:"cover_image"`
	Bio             *string    `json:"bio"`
	Website         *string    `json:"website"`
	Location        *string    `json:"location"`
	Facebook        *string    `json:"facebook"`
	Twitter         *string    `json:"twitter"`
	Accessibility   *string    `json:"accessibility"`
	Status          *string    `json:"status"`
	MetaTitle       *string    `json:"meta_title"`
	MetaDescription *string    `json:"meta_description"`
	Tour            *bool      `json:"tour"`
	LastSeen        *time.Time `json:"last_seen"`
	CreatedAt       *time.Time `json:"created_at"`
	UpdatedAt       *time.Time `json:"updated_at"`
	Roles           []*Role    `json:"roles"`
	URL             *string    `json:"url"`
}

Author represents an author.

type Database

type Database struct {
	Meta *DatabaseMeta          `json:"meta"`
	Data map[string]interface{} `json:"data"`
}

Database is the representation of the database, with meta info.

type DatabaseImportProblem

type DatabaseImportProblem struct {
	Message string                 `json:"message"`
	Help    string                 `json:"help"`
	Context string                 `json:"context"`
	Err     map[string]interface{} `json:"err"`
}

DatabaseImportProblem represents any issues or strageness encountered during import.

type DatabaseMeta

type DatabaseMeta struct {
	Version    string `json:"version,omitempty"`
	ExportedOn int64  `json:"exported_on,omitempty"`
}

DatabaseMeta is metadata of the source of the db dump.

type ListParams

type ListParams struct {
	QueryParams
	Filter string `url:"filter,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Page   int    `url:"page,omitempty"`
	Order  string `url:"order,omitempty"`
}

ListParams are params that can be used for list requests.

func (ListParams) String

func (lp ListParams) String() string

type Meta

type Meta struct {
	Pagination *Pagination
}

Meta encompasses meta data from the response we get back from the API.

func (Meta) String

func (m Meta) String() string

type Pagination

type Pagination struct {
	Page  *int
	Limit *int
	Pages *int
	Total *int
	Next  *int
	Prev  *int
}

Pagination has all pagination related info for the response.

type Post

type Post struct {
	Slug               *string    `json:"slug"`
	ID                 *string    `json:"id"`
	UUID               *string    `json:"uuid"`
	Title              *string    `json:"title"`
	Mobiledoc          *string    `json:"mobiledoc"`
	HTML               *string    `json:"html"`
	CommentID          *string    `json:"comment_id"`
	FeatureImage       *string    `json:"feature_image"`
	Featured           *bool      `json:"featured"`
	Status             *string    `json:"status"`
	Visibility         *string    `json:"visibility"`
	CreatedAt          *time.Time `json:"created_at"`
	UpdatedAt          *time.Time `json:"updated_at"`
	PublishedAt        *time.Time `json:"published_at"`
	CustomExcerpt      *string    `json:"custom_excerpt"`
	CodeinjectionHead  *string    `json:"codeinjection_head"`
	CodeinjectionFoot  *string    `json:"codeinjection_foot"`
	CustomTemplate     *string    `json:"custom_template"`
	CanonicalURL       *string    `json:"canonical_url"`
	Tags               []*Tag     `json:"tags"`
	Authors            []*Author  `json:"authors"`
	PrimaryAuthor      *Author    `json:"primary_author"`
	PrimaryTag         *Tag       `json:"primary_tag"`
	URL                *string    `json:"url"`
	Excerpt            *string    `json:"excerpt"`
	ReadingTime        *int       `json:"reading_time"`
	OgImage            *string    `json:"og_image"`
	OgTitle            *string    `json:"og_title"`
	OgDescription      *string    `json:"og_description"`
	TwitterImage       *string    `json:"twitter_image"`
	TwitterTitle       *string    `json:"twitter_title"`
	TwitterDescription *string    `json:"twitter_description"`
	MetaTitle          *string    `json:"meta_title"`
	MetaDescription    *string    `json:"meta_description"`
}

Post represents a Ghost post.

func (Post) String

func (p Post) String() string

type PostsResponse

type PostsResponse struct {
	Posts []*Post
	Meta  *Meta
}

PostsResponse is the structure of the Post response.

func (PostsResponse) String

func (pr PostsResponse) String() string

type QueryParams

type QueryParams struct {
}

QueryParams are query params that can be used for get and list requests.

type Redirect

type Redirect struct {
	From string `json:"from"`
	To   string `json:"to"`
}

Redirect is a single redirect entry.

type Role

type Role struct {
	ID          *string    `json:"id"`
	Name        *string    `json:"name"`
	Description *string    `json:"description"`
	CreatedAt   *time.Time `json:"created_at"`
	UpdatedAt   *time.Time `json:"updated_at"`
}

Role represents the role a user may have.

type SetupDetails

type SetupDetails struct {
	Name      string `json:"name"`
	Email     string `json:"email"`
	Password  string `json:"password"`
	BlogTitle string `json:"blogTitle"`
}

SetupDetails is the information needed to setup the Ghost instance.

type Tag

type Tag struct {
	ID              *string    `json:"id"`
	Name            *string    `json:"name"`
	Slug            *string    `json:"slug"`
	Description     *string    `json:"description"`
	FeatureImage    *string    `json:"feature_image"`
	Visibility      *string    `json:"visibility"`
	MetaTitle       *string    `json:"meta_title"`
	MetaDescription *string    `json:"meta_description"`
	CreatedAt       *time.Time `json:"created_at"`
	UpdatedAt       *time.Time `json:"updated_at"`
	URL             *string    `json:"url"`
}

Tag represents a post/page tag.

func (Tag) String

func (t Tag) String() string

type WriteFilePart

type WriteFilePart func(mpw *multipart.Writer) error

WriteFilePart is the "callback" responsible for writing out the file of the multipart request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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