cohost.js-fork/README.md

91 lines
2.0 KiB
Markdown
Raw Permalink Normal View History

2022-06-29 13:24:33 +01:00
# cohost.js
2022-09-09 14:51:10 +01:00
2022-06-29 13:24:33 +01:00
Unofficial API for cohost.org
## Install
2022-09-09 14:51:10 +01:00
2022-06-29 13:24:33 +01:00
```bash
npm i cohost
```
## Usage
```js
const cohost = require("cohost");
2022-09-09 14:51:10 +01:00
(async function () {
// Create User and authenticate
let user = new cohost.User();
await user.login("YOUR_EMAIL", "YOUR_PASSWORD");
// Get first Project of user
let [project] = await user.getProjects();
// Create Post
let myPostID = await cohost.Post.create(project, {
2022-09-09 14:51:10 +01:00
postState: 1,
headline: "hello world from cohost.js",
adultContent: false,
blocks: [],
cws: [],
tags: []
});
// Edit Post
await cohost.Post.update(project, myPostID, {
postState: 1,
headline: "Hello world from cohost.js!",
adultContent: false,
blocks: [],
cws: [],
tags: ["cohost.js"]
});
2022-09-09 14:51:10 +01:00
// Get Posts of Project
let posts = await project.getPosts();
// Create a draft with attachments
// 1. Create a draft
const draftId = await cohost.Post.create(myProject, basePost);
// 2. Upload the attachment
const attachmentData = await myProject.uploadAttachment(
draftId,
path.resolve(__dirname, "./02-15_One_pr.png")
);
// 3. Add the attachment block to the draft and publish it
await cohost.Post.update(myProject, draftId, {
...basePost,
postState: 1,
blocks: [
...basePost.blocks,
{ type: "attachment", attachment: { ...attachmentData } }
]
});
2022-06-29 13:24:33 +01:00
})();
```
## Features
Works:
2022-09-09 14:51:10 +01:00
- Logging in
- Getting the posts of a project
- Creating a post
- Editing a post
2022-06-29 13:24:33 +01:00
Doesn't work:
2022-09-09 14:51:10 +01:00
- Sharing a post: possible, haven't done it
- Liking a post: possible, haven't done it
- Getting notifications: possible, haven't done it
- Getting the home feed: possible, haven't done it
- Editing profiles: possible, haven't done it
- Getting followers and following: possible, haven't done it
- Getting bookmarks and bookmarking: possible, haven't done it
- Getting a post by its ID: **seems impossible? endpoint seems to be disabled**
- Getting posts from a tag: haven''t checked
- ...everything else