Skip to content

Latest commit

 

History

History
1432 lines (798 loc) · 30.3 KB

reference.md

File metadata and controls

1432 lines (798 loc) · 30.3 KB

Classes

cohost-api / Exports / Client

Class: Client

A Cohost API client. Instantiate this class to interact with the Cohost API.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Client(): Client

Creates a new Cohost API client. Requires no arguments.

Returns

Client

Defined in

objects/client.ts:57

Properties

loggedIn

loggedIn: boolean = false

Whether the client is logged in.

Defined in

objects/client.ts:49


user

user: null | User = null

The currently logged in user. Once logged in, can be used to access the user's information and projects.

Defined in

objects/client.ts:52

Methods

login

login(email, password): Promise<null | User>

Logs in to Cohost, creating a new session.

Parameters
Name Type Description
email string The email of the User.
password string The User's password.
Returns

Promise<null | User>

The logged in User, or null if the login failed.

Defined in

objects/client.ts:77

cohost-api / Exports / EditedProject

Class: EditedProject

A class representing a project on Cohost that the user has editing privileges for.

Hierarchy

Table of contents

Properties

Methods

Properties

atomFeedURL

atomFeedURL: string

Inherited from

Project.atomFeedURL

Defined in

objects/project.ts:50


avatarShape

avatarShape: string

Inherited from

Project.avatarShape

Defined in

objects/project.ts:47


avatarURL

avatarURL: string

Inherited from

Project.avatarURL

Defined in

objects/project.ts:40


dek

dek: string

The project subheading.

Inherited from

Project.dek

Defined in

objects/project.ts:37


description

description: string

The description/bio of the project.

Inherited from

Project.description

Defined in

objects/project.ts:39


displayName

displayName: string

The display name, which shows up on the timeline.

Inherited from

Project.displayName

Defined in

objects/project.ts:35


flags

flags: string[]

Inherited from

Project.flags

Defined in

objects/project.ts:46


frequentlyUsedTags

frequentlyUsedTags: string[]

Inherited from

Project.frequentlyUsedTags

Defined in

objects/project.ts:49


handle

handle: string

The handle of the project, without the @.

Inherited from

Project.handle

Defined in

objects/project.ts:33


headerPreviewURL

headerPreviewURL: string

Inherited from

Project.headerPreviewURL

Defined in

objects/project.ts:42


headerURL

headerURL: string

Inherited from

Project.headerURL

Defined in

objects/project.ts:41


id

id: number

The unique ID of the project.

Inherited from

Project.id

Defined in

objects/project.ts:31


loggedOutPostVisibility

loggedOutPostVisibility: Privacy

Inherited from

Project.loggedOutPostVisibility

Defined in

objects/project.ts:48


privacy

privacy: Privacy

Inherited from

Project.privacy

Defined in

objects/project.ts:43


pronouns

pronouns: string

Inherited from

Project.pronouns

Defined in

objects/project.ts:45


url

url: string

Inherited from

Project.url

Defined in

objects/project.ts:44

Methods

addAttachment

addAttachment(post, filepath): Promise<number>

Adds an attachment to a post. This must be done after the post is created. This is a limitation of the Cohost API.

Parameters
Name Type Description
post Post The post to add the attachment to.
filepath string The path to the file to upload.
Returns

Promise<number>

The ID of the attachment.

Defined in

objects/project.ts:240

addAttachment(post, filename, mimeType, attachment, width, height): Promise<number>

Adds an attachment to a post. This must be done after the post is created. This is a limitation of the Cohost API.

Parameters
Name Type Description
post Post The post to add the attachment to.
filename string The name of the file to upload.
mimeType string The MIME type of the file.
attachment Buffer A Buffer containing the file to upload.
width number The width of the image.
height number The height of the image.
Returns

Promise<number>

The ID of the attachment.

Defined in

objects/project.ts:251


createDraft

createDraft(post): Promise<Post>

Creates a draft of a post in the project.

Parameters
Name Type Description
post Post The post to send to the project's drafts.
Returns

Promise<Post>

The post with its postId set.

Defined in

objects/project.ts:182


createPost

createPost(post): Promise<Post>

Publishes a post to the project.

Parameters
Name Type Description
post Post The post to publish.
Returns

Promise<Post>

The post with its postId set.

Defined in

objects/project.ts:170


deletePost

deletePost(post): Promise<void>

Deletes a post from the project.

Parameters
Name Type Description
post number | Post The post or ID of the post to delete.
Returns

Promise<void>

Defined in

objects/project.ts:193


getPosts

getPosts(page?, options?): Promise<any>

Gets a page of posts from the project. The Cohost API returns 20 posts per page.

Parameters
Name Type Default value Description
page number 0 The page of posts to get. Defaults to 0.
options Object undefined Options for filtering the returned posts.
options.hideAsks boolean undefined -
options.hideReplies boolean undefined -
options.hideShares boolean undefined -
options.pinnedPostsAtTop boolean undefined -
Returns

Promise<any>

An array of TimelinePosts from the project.

Inherited from

Project.getPosts

Defined in

objects/project.ts:114


likePost

likePost(post): Promise<void>

Gives a like from this project to a post.

Parameters
Name Type Description
post number | Post The post to like.
Returns

Promise<void>

Defined in

objects/project.ts:351


publishDraft

publishDraft(draftPost): Promise<void>

Publishes a post from the project's drafts.

In the future, this function will also accept a number as the first argument, which will be the ID of the draft post to publish.

Parameters
Name Type Description
draftPost Post The draft post to publish.
Returns

Promise<void>

Defined in

objects/project.ts:224


unlikePost

unlikePost(post): Promise<void>

Removes a like from this project to a post.

Parameters
Name Type Description
post number | Post The post to unlike.
Returns

Promise<void>

Defined in

objects/project.ts:363


updatePost

updatePost(postToUpdate, newPost): Promise<void>

Updates a post in the project.

Parameters
Name Type Description
postToUpdate number | Post The post or ID of the post to update.
newPost Post The new post data.
Returns

Promise<void>

Defined in

objects/project.ts:206

cohost-api / Exports / Post

Class: Post

A class representing a post on Cohost.

This class does not contain all the data that a post can have. See the TimelinePost class for a more complete representation of a post.

This class is not used for creating posts. Instead, use the PostBuilder class to create a new post.

Table of contents

Properties

Properties

content

content: Object

Type declaration
Name Type
adultContent boolean
blocks object[]
cws string[]
headline string
postState PostState
tags string[]
Defined in

objects/post.ts:21


postId

postId: number

Defined in

objects/post.ts:20


projectHandle

projectHandle: string

Defined in

objects/post.ts:19

cohost-api / Exports / PostBuilder

Class: PostBuilder

A class for creating Post objects.

Example usage:

let postBuilder = new PostBuilder("Hello, world!");
postBuilder.addMarkdownBlock("This is a test post from cohost-api.");
postBuilder.addTag("cohost-api");
let finishedPost = postBuilder.build();

Table of contents

Constructors

Methods

Constructors

constructor

new PostBuilder(headline?, adultContent?): PostBuilder

Creates a new PostBuilder, used for easily constructing a Post object.

Parameters
Name Type Default value Description
headline string "" The headline for the post. Appears at the top of a post. Defaults to an empty string.
adultContent boolean false Whether the post contains adult content. Defaults to false.
Returns

PostBuilder

Defined in

objects/post.ts:143

Methods

addBlock

addBlock(type, block): PostBuilder

Adds a block of content to the post. Only use this if you are familiar with the types of content blocks that Cohost supports. Otherwise, use addMarkdownBlock().

Parameters
Name Type Description
type string The type of content block to add.
block object The content of the block.
Returns

PostBuilder

The PostBuilder object, for chaining.

Defined in

objects/post.ts:154


addCw

addCw(cw): PostBuilder

Adds a content warning to the post.

Parameters
Name Type Description
cw string The content warning to add to the post.
Returns

PostBuilder

The PostBuilder object, for chaining.

Defined in

objects/post.ts:176


addMarkdownBlock

addMarkdownBlock(content): PostBuilder

Adds a block of markdown text to the post.

Parameters
Name Type Description
content string The markdown string to add to the post.
Returns

PostBuilder

The PostBuilder object, for chaining.

Defined in

objects/post.ts:166


addTag

addTag(tag): PostBuilder

Adds a #tag to the post.

Parameters
Name Type Description
tag string The #tag to add to the post. You do not need to include the # symbol.
Returns

PostBuilder

The PostBuilder object, for chaining.

Defined in

objects/post.ts:186


build

build(): Post

Builds the Post object from the data in the PostBuilder.

Returns

Post

The Post object.

Defined in

objects/post.ts:195

cohost-api / Exports / Project

Class: Project

A class representing a project on Cohost. A user can have multiple projects.

Do not instantiate this class directly. Projects can only be obtained from the API. cohost-api does not yet support creating new projects.

Hierarchy

Table of contents

Properties

Methods

Properties

atomFeedURL

atomFeedURL: string

Defined in

objects/project.ts:50


avatarShape

avatarShape: string

Defined in

objects/project.ts:47


avatarURL

avatarURL: string

Defined in

objects/project.ts:40


dek

dek: string

The project subheading.

Defined in

objects/project.ts:37


description

description: string

The description/bio of the project.

Defined in

objects/project.ts:39


displayName

displayName: string

The display name, which shows up on the timeline.

Defined in

objects/project.ts:35


flags

flags: string[]

Defined in

objects/project.ts:46


frequentlyUsedTags

frequentlyUsedTags: string[]

Defined in

objects/project.ts:49


handle

handle: string

The handle of the project, without the @.

Defined in

objects/project.ts:33


headerPreviewURL

headerPreviewURL: string

Defined in

objects/project.ts:42


headerURL

headerURL: string

Defined in

objects/project.ts:41


id

id: number

The unique ID of the project.

Defined in

objects/project.ts:31


loggedOutPostVisibility

loggedOutPostVisibility: Privacy

Defined in

objects/project.ts:48


privacy

privacy: Privacy

Defined in

objects/project.ts:43


pronouns

pronouns: string

Defined in

objects/project.ts:45


url

url: string

Defined in

objects/project.ts:44

Methods

getPosts

getPosts(page?, options?): Promise<any>

Gets a page of posts from the project. The Cohost API returns 20 posts per page.

Parameters
Name Type Default value Description
page number 0 The page of posts to get. Defaults to 0.
options Object undefined Options for filtering the returned posts.
options.hideAsks boolean undefined -
options.hideReplies boolean undefined -
options.hideShares boolean undefined -
options.pinnedPostsAtTop boolean undefined -
Returns

Promise<any>

An array of TimelinePosts from the project.

Defined in

objects/project.ts:114

cohost-api / Exports / User

Class: User

The currently logged in user. Do not instantiate this class; instead, use the login() method of the Client class to log in.

This class is not used for any other users because the Cohost API does not provide a way to get other users; it only provides other users' projects.

Table of contents

Properties

Methods

Properties

email

email: string

The email address of this user.

Defined in

objects/user.ts:18


id

id: number

The unique ID of this user.

Defined in

objects/user.ts:16


projects

projects: EditedProject[] = []

The projects that this user is able to edit.

Defined in

objects/user.ts:14

Methods

getFollowers

getFollowers(offset?, limit?): Promise<Project[]>

Gets the projects that follow the current project. Use switchProject() to change the current project.

This method is paginated, and the default offset is 0 and the default limit is 10.

Parameters
Name Type Default value Description
offset number 0 How many projects to skip.
limit number 10 The maximum number of projects to get.
Returns

Promise<Project[]>

The followers of this project.

Defined in

objects/user.ts:56


getFollowing

getFollowing(sortOrder, offset?, limit?, beforeTimestamp?): Promise<Project[]>

Gets the projects that the current project follows. Use switchProject() to change the current project.

Parameters
Name Type Default value Description
sortOrder SortOrder undefined What order to sort the projects in.
offset number 0 How many projects to skip.
limit number 10 The maximum number of projects to get.
beforeTimestamp number undefined Not sure yet. Likely has to do with the last time the project posted.
Returns

Promise<Project[]>

The projects that this project follows.

Defined in

objects/user.ts:80


liked

liked(post): any

Checks if the current project has liked a post. Use switchProject() to change the current project.

Parameters
Name Type Description
post number | Post The post to check if the project has liked.
Returns

any

Whether the project has liked the post.

Defined in

objects/user.ts:40


switchProject

switchProject(project): void

Switches the currently active project to the given project. This is relevant for API calls related to notifications and getting the "liked" state of posts.

Parameters
Name Type Description
project EditedProject The project to switch to.
Returns

void

Defined in

objects/user.ts:31

Enums

cohost-api / Exports / PostState

Enumeration: PostState

Whether a post is a draft or published.

Table of contents

Enumeration Members

Enumeration Members

DRAFT

DRAFT = 0

Defined in

objects/post.ts:7


PUBLISHED

PUBLISHED = 1

Defined in

objects/post.ts:8

cohost-api / Exports / Privacy

Enumeration: Privacy

Table of contents

Enumeration Members

Enumeration Members

PRIVATE

PRIVATE = "private"

Defined in

objects/project.ts:11


PUBLIC

PUBLIC = "public"

Defined in

objects/project.ts:10

cohost-api / Exports / SortOrder

Enumeration: SortOrder

Table of contents

Enumeration Members

Enumeration Members

ALPHA_ASC

ALPHA_ASC = "alpha-asc"

Defined in

objects/project.ts:18


ALPHA_DESC

ALPHA_DESC = "alpha-desc"

Defined in

objects/project.ts:19


FOLLOWED_ASC

FOLLOWED_ASC = "followed-asc"

Defined in

objects/project.ts:16


FOLLOWED_DESC

FOLLOWED_DESC = "followed-desc"

Defined in

objects/project.ts:17


RECENTLY_POSTED

RECENTLY_POSTED = "recently-posted"

Defined in

objects/project.ts:15