Skip to content

Yurba.js / @yurbajs/rest / PostResource

Class: PostResource

Post Comments

addComment()

addComment(postId, content, photos): Promise<Comment>

Adds comment to post

Parameters

postId

number

Post identifier

content

string

Comment content

photos

number[] = []

Photo IDs array

Returns

Promise<Comment>

Created comment

Since

1.0.0

Throws

If parameters are invalid

Example

javascript
await rest.posts.addComment(123, "Nice post!");
await rest.posts.addComment(123, "With photo", [456]);

deleteComment()

deleteComment(commentId): Promise<BaseOkay>

Deletes a comment

Parameters

commentId

number

Comment identifier

Returns

Promise<BaseOkay>

Delete response

Since

1.0.0

Throws

If comment ID is invalid

Example

javascript
await rest.posts.deleteComment(789);

getComments()

getComments(postId, lastId): Promise<Comment[]>

Gets comments from post

Parameters

postId

number

Post identifier

lastId

number = 0

Last comment ID for pagination

Returns

Promise<Comment[]>

Array of comments

Since

1.0.0

Throws

If parameters are invalid

Example

javascript
const comments = await rest.posts.getComments(123);
const olderComments = await rest.posts.getComments(123, 456);

Posts Core

create()

create(user, payload): Promise<Post>

Creates a new post

Parameters

user

User ({tag}/{id}/u{id}/@me)

string | number

payload

CreatePostPayload

CreatePostPayload Post data

Returns

Promise<Post>

Post Created post

Since

1.0.0

Throws

If user or data is invalid

Example

javascript
// Text post
const post = await rest.posts.create('@me', {
  content: "Hello world!"
});

// Post with photos
const postWithPhotos = await rest.posts.create('username', {
  content: "Check out these photos!",
  photos_list: [123, 456]
});

// Post with attachments
const postWithAttachments = await rest.posts.create(12345, {
  content: "Sharing some content",
  attachments: [
    { Type: "video", Item: 28 },
    { Type: "track", Item: 6422 }
  ]
});

// Edit existing post
const editedPost = await rest.posts.create('@me', {
  content: "Updated content",
  edit: 98765
});

// Repost
const repost = await rest.posts.create('@me', {
  content: "Great post!",
  repost: 54321
});

delete()

delete(postId): Promise<BaseOkay>

Deletes a post

Parameters

postId

number

Post identifier

Returns

Promise<BaseOkay>

DeletePostResponse Delete response

Since

1.0.0

Throws

If post ID is invalid

Example

javascript
await rest.posts.delete(12345);

edit()

edit(postId, data): Promise<Post>

Edits a post

Parameters

postId

number

Post identifier

data

CreatePostPayload

CreatePostPayload Updated post data

Returns

Promise<Post>

Post Updated post

Since

1.0.0

Throws

If parameters are invalid

Example

javascript
const updatedPost = await rest.posts.edit(12345, {
  text: "Updated content"
});

get()

get(user, payload): Promise<Post[]>

Gets posts from user

Parameters

user

User ({tag}/{id}/u{id}/@me)

string | number

payload

GetPostPayload

GetPostPayload Get posts parameters

Returns

Promise<Post[]>

Array of Post objects

Since

1.0.0

Throws

If user is invalid

Example

javascript
const posts = await rest.posts.get('username', {});
const postsById = await rest.posts.get(12345, {});
const postsByUid = await rest.posts.get('u12345', {});
const myPosts = await rest.posts.get('@me', {});
const olderPosts = await rest.posts.get('username', { lastId: 123 });