gohost

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 20 Imported by: 0

README

gohost

gohost logo
Gohost is a library that wraps Cohost's public API!

Current Features

  • Can start a user session given an email and password, or a cookie
  • Can retrieve posts from your projects
  • Can post and edit posts on editable projects
  • Can use the requests package to make custom requests to Cohost API endpoints

Installation

go get github.com/curtywill/gohost

Getting Started

Before anything can be done with Gohost, you need an authenticated user. This can be done with a cookie:
user, err := gohost.LoginWithCookie(nil, "your_cookie")
or with an email and password:
user, err := gohost.LoginWithPass(nil, "email", "password")
(Note: passing nil to these functions means http.DefaultClient will be used for all requests, send a custom client if that's unsatisfactory)
For more on what to do next, check out the example.

Cohost Terminology

  • Project: page that a user can edit
  • Blocks: the blocks of attachments and text that make up posts. Get representations of these using the Attachment and Markdown structs.

Upcoming Features

  • View a post's share tree
  • View comments on posts
  • More support for drafts
  • More stuff that hasn't crossed my mind yet

Thanks

  • cohost.py: HUGE shoutout to Valknight for giving me a great example to follow in building this
  • cohost.js: obligatory thank you by the transitive property
  • Go: had to dig through the Go source to figure out multipart forms and the mime package, most readable source for a language I've ever seen

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AstMap added in v0.2.0

type AstMap struct {
	Initial        string `json:"initial"`
	InitialLength  int    `json:"initialLength"`
	Expanded       string `json:"expanded"`
	ExpandedLength int    `json:"expandedLength"`
}

type Attachment

type Attachment struct {
	Filepath string
	AltText  string
	// contains filtered or unexported fields
}

func (Attachment) FileUrl added in v0.1.2

func (a Attachment) FileUrl() string

type Markdown

type Markdown struct {
	Content string
}

type Post

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

func (Post) AstMap added in v0.2.0

func (p Post) AstMap() AstMap

func (Post) Blocks

func (p Post) Blocks() ([]Markdown, []Attachment)

func (Post) ContentWarnings

func (p Post) ContentWarnings() []string

func (Post) Filename

func (p Post) Filename() string

func (Post) Headline

func (p Post) Headline() string

func (Post) Id

func (p Post) Id() int

func (Post) NumComments

func (p Post) NumComments() int

func (Post) NumSharedComments

func (p Post) NumSharedComments() int

func (Post) PlainTextBody

func (p Post) PlainTextBody() string

func (Post) PostingProject

func (p Post) PostingProject() Project

func (Post) PublishedAt

func (p Post) PublishedAt() time.Time

func (Post) RelatedProjects added in v0.2.0

func (p Post) RelatedProjects() []Project

func (Post) ShareTree added in v0.2.0

func (p Post) ShareTree() []Post

func (Post) State

func (p Post) State() int

func (Post) Tags

func (p Post) Tags() []string

func (Post) Url

func (p Post) Url() string

type Project

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

func (Project) AvatarShape

func (p Project) AvatarShape() string

func (Project) AvatarURL

func (p Project) AvatarURL() string

func (Project) Description

func (p Project) Description() string

func (Project) DisplayName

func (p Project) DisplayName() string

func (Project) EditPost

func (p Project) EditPost(postId int, adult bool, markdown []Markdown, attachments []Attachment, tags, cws []string, headline string, draft bool) (Post, error)

func (Project) Flags

func (p Project) Flags() [][]byte

func (Project) FrequentlyUsedTags

func (p Project) FrequentlyUsedTags() []string

func (Project) GetPosts

func (p Project) GetPosts(page int) ([]Post, error)

Returns all the posts on a given page of the current project.

func (Project) Handle

func (p Project) Handle() string

func (Project) HeaderURL

func (p Project) HeaderURL() string

func (Project) Headline

func (p Project) Headline() string

func (Project) Post

func (p Project) Post(adult bool, markdown []Markdown, attachments []Attachment, tags, cws []string, headline string, draft bool) (Post, error)

Makes a post on your current project Returns a Post struct that contains info about the post, including the postId needed for editing! Returns an empty Post in the case of a draft or an error

func (Project) Privacy

func (p Project) Privacy() string

func (Project) ProjectId

func (p Project) ProjectId() int

func (Project) Pronouns

func (p Project) Pronouns() string

func (Project) URL

func (p Project) URL() string

type User

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

func LoginWithCookie

func LoginWithCookie(client *http.Client, cookie string) (User, error)

Start a user session with your connect.sid cookie from Cohost If you don't have any special needs for an HTTP client, pass it as nil

func LoginWithPass

func LoginWithPass(client *http.Client, email, password string) (User, error)

Start a user session with your Cohost email and password If you don't have any special needs for an HTTP client, pass it as nil

func (User) Activated

func (u User) Activated() bool

func (User) DefaultProject

func (u User) DefaultProject() (Project, error)

Returns your first project.

func (User) Email

func (u User) Email() string

func (User) GetEditedProjects

func (u User) GetEditedProjects() ([]Project, error)

Lists all the projects for an authenticated user

func (User) GetProject

func (u User) GetProject(handle string) (Project, error)

Retrieve one of your projects by its handle

func (User) Id

func (u User) Id() int

func (User) ModMode

func (u User) ModMode() bool

func (User) ProjectId

func (u User) ProjectId() int

func (User) ReadOnly

func (u User) ReadOnly() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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