forem

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 17 Imported by: 0

README

Go Report Card GoDoc

Forem client SDK

Documentation

Overview

Package forme provides an API client for communication with forem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID int `json:"id"`

	// The following fields may be modified via the API, as well as read.
	Title        string       `json:"title,omitempty"`
	Description  string       `json:"description,omitempty"`
	Frontmatter  *Frontmatter `json:"-"`
	Body         string       `json:"-"`
	CanonicalURL string       `json:"canonical_url,omitempty"`
	Tags         []string     `json:"tags,omitempty"`

	// These fields are write-only.
	Published      bool   `json:"published,omitempty"`
	Series         string `json:"series,omitempty"`
	MainImage      string `json:"main_image,omitempty"`
	OrganizationID int32  `json:"organization_id,omitempty"`

	// The remaining fields are read-only via the API. Some may be set via
	// front matter in Body
	ReadablePublishDate    string        `json:"readable_publish_date"`
	Slug                   string        `json:"slug"`
	Path                   string        `json:"path"`
	URL                    string        `json:"url"`
	CommentsCount          int           `json:"comments_count"`
	CollectionID           *int          `json:"collection_id"`
	PublishedTimestamp     time.Time     `json:"published_timestamp"`
	PositiveReactionsCount int           `json:"positive_reactions_count"`
	CoverImage             string        `json:"cover_image"`
	SocialImage            string        `json:"social_image"`
	CreatedAt              time.Time     `json:"created_at"`
	EditedAt               *time.Time    `json:"edited_at"`
	CrosspostedAt          *time.Time    `json:"crossposted_at"`
	PublishedAt            time.Time     `json:"published_at"`
	LastCommentAt          *time.Time    `json:"last_comment_at"`
	ReadingTimeMinutes     int           `json:"reading_time_minutes"`
	User                   *User         `json:"user"`
	Organization           *Organization `json:"organization"`
	FlareTag               *FlareTag     `json:"flare_tag"`
	PageViewsCount         int           `json:"page_views_count"`
	PublicReactionsCount   int           `json:"public_reactions_count"`
}

Article represents a Forem article.

func (*Article) MarshalJSON

func (a *Article) MarshalJSON() ([]byte, error)

MarshalJSON impements json.Marshaler.

func (*Article) UnmarshalJSON

func (a *Article) UnmarshalJSON(p []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ArticlesQuery

type ArticlesQuery struct {
	// Page is the pagination page requested.
	Page int32 `url:"page,omitempty"`
	// PerPage is the page size (items to return per page). Defaults to 30.
	PerPage      int32    `url:"per_page,omitempty"`
	Tag          string   `url:"tag,omitempty"`
	Tags         []string `url:"tags,omitempty"`
	TagsExclude  []string `url:"tags_exclude,omitempty"`
	Username     string   `url:"username,omitempty"`
	State        string   `url:"state,omitempty"`
	Top          int32    `url:"top,omitempty"`
	CollectionID int32    `url:"collection_id,omitempty"`
}

ArticlesQuery are the query parameters possible when fetching a list of articles.

type Client

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

Client represents a connection to a Forem instance.

func New

func New(baseURL, apiKey string) (*Client, error)

New returns a new client instance with a default HTTP client.

func (*Client) Article

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

Article retrieves a single published article given its id.

See https://developers.forem.com/api/v0#tag/articles/operation/getArticleById

func (*Client) ArticleBySlug

func (c *Client) ArticleBySlug(ctx context.Context, username, slug string) (*Article, error)

ArticleBySlug retrieve a single published article given its username and slug.

See https://developers.forem.com/api/v0#tag/articles/operation/getArticleByPath

func (*Client) Articles

func (c *Client) Articles(ctx context.Context, query *ArticlesQuery) ([]*Article, error)

Articles retrieves a list of articles.

"Articles" are all the posts that users create on Forem that typically show up in the feed. They can be a blog post, a discussion question, a help thread etc. but is referred to as article within the code.

By default it will return featured, published articles ordered by descending popularity.

It supports pagination, and each page will contain 30 articles by default.

See https://developers.forem.com/api/v1#tag/articles/operation/getArticles

func (*Client) CreateArticle

func (c *Client) CreateArticle(ctx context.Context, article *Article) (*Article, error)

CreateArticle creates a new article.

See https://developers.forem.com/api/v0#tag/articles/operation/createArticle

func (*Client) LatestArticles

func (c *Client) LatestArticles(ctx context.Context, query *PaginationQuery) ([]*Article, error)

LatestArticles retrieves a list of articles. ordered by descending publish date.

See https://developers.forem.com/api/v0#tag/articles/operation/getLatestArticles

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(client *http.Client)

SetHTTPClient allows setting a custom HTTP client to be used for making requests.

func (*Client) UpdateArticle

func (c *Client) UpdateArticle(ctx context.Context, article *Article) (*Article, error)

UpdateArticle updates an existing article.

article.ID must be set.

See https://developers.forem.com/api/v0#tag/articles/operation/updateArticle

func (*Client) UsersAllArticles

func (c *Client) UsersAllArticles(ctx context.Context, query *PaginationQuery) ([]*Article, error)

UsersAllArticles retrieves a list of all articles on behalf of an authenticated user.

See https://developers.forem.com/api/v0#tag/articles/operation/getUserAllArticles

func (*Client) UsersArticles

func (c *Client) UsersArticles(ctx context.Context, query *PaginationQuery) ([]*Article, error)

UsersArticles retrieves a list of published articles on behalf of an authenticated user.

See https://developers.forem.com/api/v0#tag/articles/operation/getUserArticles

func (*Client) UsersPublishedArticles

func (c *Client) UsersPublishedArticles(ctx context.Context, query *PaginationQuery) ([]*Article, error)

UsersPublishedArticles retrieves a list of published articles on behalf of an authenticated user.

See https://developers.forem.com/api/v0#tag/articles/operation/getUserPublishedArticles

func (*Client) UsersUnpublishedArticles

func (c *Client) UsersUnpublishedArticles(ctx context.Context, query *PaginationQuery) ([]*Article, error)

UsersUnpublishedArticles retrieves a list of unpublished articles on behalf of an authenticated user.

See https://developers.forem.com/api/v0#tag/articles/operation/getUserUnpublishedArticles

func (*Client) Videos

func (c *Client) Videos(ctx context.Context, query *PaginationQuery) ([]*Video, error)

Videos retrieves a list of articles that are uploaded with a video.

See https://developers.forem.com/api/v0#tag/articles/operation/getArticlesWithVideo

type FlareTag

type FlareTag struct {
	Name         string `json:"name"`
	BgColorHex   string `json:"bg_color_hex"`
	TextColorHex string `json:"text_color_hex"`
}

FlareTag is...

type Frontmatter added in v0.0.4

type Frontmatter struct {
	Title        string    `yaml:"title"`
	Description  string    `yaml:"description"`
	Series       string    `yaml:"series"`
	Published    bool      `yaml:"published"`
	Date         time.Time `yaml:"date"`
	Tags         []string  `yaml:"tags"`
	CanonicalURL string    `yaml:"canonical_url"`
	CoverImage   string    `yaml:"cover_image"`
	// Extra are any unrecognized frontmatter values.
	Extra map[string]string
}

Frontmatter represents the frontmatter for an article.

func (*Frontmatter) Encode added in v0.0.10

func (f *Frontmatter) Encode() []byte

Encode marshals Frontmatter using Forem's peculiar YAML-ish format.

type Organization

type Organization struct {
	Name           string `json:"name"`
	Username       string `json:"username"`
	Slug           string `json:"slug"`
	ProfileImage   string `json:"profile_image"`
	ProfileImage90 string `json:"profile_image_90"`
}

Organization ...

type PaginationQuery

type PaginationQuery struct {
	// Page is the pagination page requested.
	Page int32 `url:"page,omitempty"`
	// PerPage is the page size (items to return per page). Defaults to 30.
	PerPage int32 `url:"per_page,omitempty"`
}

PaginationQuery are the query options to change pagination of results.

type User

type User struct {
	Name            string  `json:"name"`
	Username        string  `json:"username"`
	TwitterUsername *string `json:"twitter_username"`
	GithubUsername  *string `json:"github_username"`
	UserID          int     `json:"user_id"`
	WebsiteURL      *string `json:"sebsite_url"`
	ProfileImage    string  `json:"profile_image"`
	ProfileImage90  string  `json:"profile_image_90"`
}

User represents a Forem user.

type Video

type Video struct {
	ID                 int    `json:"id"`
	Path               string `json:"path"`
	CloudinaryVideoURL string `json:"cloudinary_video_url"`
	Title              string `json:"title"`
	UserID             int    `json:"user_id"`
	Duration           string `json:"video_duration_in_minutes"`
	SourceURL          string `json:"video_source_url"`
	User               *User  `json:"user"`
}

Video represents an article with a video.

Jump to

Keyboard shortcuts

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