wordpress

package
v0.0.0-...-4e09bf3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionUsers      = "users"
	CollectionPosts      = "posts"
	CollectionPages      = "pages"
	CollectionMedia      = "media"
	CollectionMeta       = "meta"
	CollectionRevisions  = "revisions"
	CollectionComments   = "comments"
	CollectionTaxonomies = "taxonomies"
	CollectionTerms      = "terms"
	CollectionStatuses   = "statuses"
	CollectionTypes      = "types"
)

Collection names for WordPress that are used in the API after the base URL.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a WordPress API client.

func New

func New(opts Options) (*Client, error)

New creates a new WordPress API client.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get sends a GET request to the specified WordPress URL and returns the response body. The base URL is prepended to the URL, for example: https://wordpress/wp-json/wp/v2/posts/21

func (*Client) GetAndUnmarshal

func (c *Client) GetAndUnmarshal(ctx context.Context, url string, v any) error

GetAndUnmarshal performs an HTTP GET request to the specified WordPress URL, unmarshal the response body into the provided struct type, and returns any error.

func (*Client) Media

func (c *Client) Media(ctx context.Context, id int) (Media, error)

Media retrieves information about a media item by its ID.

type Content

type Content struct {
	Raw      string `json:"raw,omitempty"`
	Rendered string `json:"rendered,omitempty"`
}

Content represents a WordPress content.

type Excerpt

type Excerpt struct {
	Raw      string `json:"raw,omitempty"`
	Rendered string `json:"rendered,omitempty"`
}

Excerpt represents a WordPress excerpt.

type GUID

type GUID struct {
	Raw      string `json:"raw,omitempty"`
	Rendered string `json:"rendered,omitempty"`
}

GUID represents a WordPress GUID.

type Media

type Media struct {
	ID           int          `json:"id,omitempty"`
	Date         string       `json:"date,omitempty"`
	DateGMT      string       `json:"date_gmt,omitempty"`
	GUID         GUID         `json:"guid,omitempty"`
	Link         string       `json:"link,omitempty"`
	Modified     string       `json:"modified,omitempty"`
	ModifiedGMT  string       `json:"modifiedGMT,omitempty"` //nolint
	Password     string       `json:"password,omitempty"`
	Slug         string       `json:"slug,omitempty"`
	Status       string       `json:"status,omitempty"`
	Type         string       `json:"type,omitempty"`
	Title        Title        `json:"title,omitempty"`
	Author       int          `json:"author,omitempty"`
	MediaStatus  string       `json:"comment_status,omitempty"`
	PingStatus   string       `json:"ping_status,omitempty"`
	AltText      string       `json:"alt_text,omitempty"`
	Caption      any          `json:"caption,omitempty"`
	Description  any          `json:"description,omitempty"`
	MediaType    string       `json:"media_type,omitempty"`
	MediaDetails MediaDetails `json:"media_details,omitempty"`
	Post         int          `json:"post,omitempty"`
	SourceURL    string       `json:"source_url,omitempty"`
}

Media represents a media item in WordPress.

type MediaDetails

type MediaDetails struct {
	Raw       string                 `json:"raw,omitempty"`
	Rendered  string                 `json:"rendered,omitempty"`
	Width     int                    `json:"width,omitempty"`
	Height    int                    `json:"height,omitempty"`
	File      string                 `json:"file,omitempty"`
	Sizes     MediaDetailsSizes      `json:"sizes,omitempty"`
	ImageMeta map[string]interface{} `json:"image_meta,omitempty"`
}

MediaDetails represents details of a media item.

type MediaDetailsSizes

type MediaDetailsSizes struct {
	Thumbnail MediaDetailsSizesItem `json:"thumbnail,omitempty"`
	Medium    MediaDetailsSizesItem `json:"medium,omitempty"`
	Large     MediaDetailsSizesItem `json:"large,omitempty"`
}

MediaDetailsSizes represents different sizes of a media item.

type MediaDetailsSizesItem

type MediaDetailsSizesItem struct {
	File      string `json:"file,omitempty"`
	Width     int    `json:"width,omitempty"`
	Height    int    `json:"height,omitempty"`
	MimeType  string `json:"mime_type,omitempty"`
	SourceURL string `json:"source_url,omitempty"`
}

MediaDetailsSizesItem represents details of a specific size of a media item.

type MediaUploadOptions

type MediaUploadOptions struct {
	Filename    string
	ContentType string
	Data        []byte
}

MediaUploadOptions represents options for uploading media.

type Options

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

Options represents options for configuring the WordPress client.

func NewOptions

func NewOptions() *Options

NewOptions creates a new Options instance.

func (Options) Validate

func (o Options) Validate() error

Validate checks if all required fields in Options are set.

func (Options) WithBaseURL

func (o Options) WithBaseURL(baseURL string) Options

WithBaseURL sets the base URL for the WordPress client.

func (Options) WithBasicAuth

func (o Options) WithBasicAuth(user, password string) Options

WithBasicAuth sets the basic authentication credentials for the WordPress client.

type Post

type Post struct {
	ID            int     `json:"id,omitempty"`
	Date          string  `json:"date,omitempty"`
	DateGMT       string  `json:"date_gmt,omitempty"`
	GUID          GUID    `json:"guid,omitempty"`
	Link          string  `json:"link,omitempty"`
	Modified      string  `json:"modified,omitempty"`
	ModifiedGMT   string  `json:"modifiedGMT,omitempty"` //nolint
	Password      string  `json:"password,omitempty"`
	Slug          string  `json:"slug,omitempty"`
	Status        string  `json:"status,omitempty"`
	Type          string  `json:"type,omitempty"`
	Title         Title   `json:"title,omitempty"`
	Content       Content `json:"content,omitempty"`
	Author        int     `json:"author,omitempty"`
	Excerpt       Excerpt `json:"excerpt,omitempty"`
	FeaturedImage int     `json:"featured_image,omitempty"`
	CommentStatus string  `json:"comment_status,omitempty"`
	PingStatus    string  `json:"ping_status,omitempty"`
	Format        string  `json:"format,omitempty"`
	Sticky        bool    `json:"sticky,omitempty"`
}

Post represents a WordPress post.

type Title

type Title struct {
	Raw      string `json:"raw,omitempty"`
	Rendered string `json:"rendered,omitempty"`
}

Title represents a WordPress title.

Jump to

Keyboard shortcuts

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