Skip to content
GiorgioBrux edited this page Apr 5, 2024 · 3 revisions

Updated as of sankaku-client version 2.0.0.

Client

Sankaku-api client

Kind: global class

new Client([extra_headers])

Param Type Description
[extra_headers] object Headers added to every request.

Example

const client = new Client({header1: 'header1_info', header2: 'header2_info'});

client.login(account) ⇒ Promise.<void>

⚠ If the credentials are changed, some functions may stop working and you will have to logout().>

Kind: instance method of Client Throws:

  • Error Will throw an error if the login/password combination is invalid or for generic network issues.
Param Type Description
account object Account you want to login
account.login string Email or username
account.password string Plain password

Example

 .catch(e => console.log(e)); // Invalid login and password combination

client.logout() ⇒ Promise.<void>

It calls the api logout endpoint and deletes the saved account data.

Kind: instance method of Client Throws:

  • Error WIll throw an error for generic network issues or if the logout api call fails (the latter can be usually ignored safely).

client.isLoggedIn() ⇒ boolean

Returns whether the Client is logged in or not.

Kind: instance method of Client Returns: boolean - Log-in status

client.getUserInfo([config]) ⇒ Promise.<object>

Get user info fetching latest data from api, either by id or name.

Kind: instance method of Client Returns: Promise.<object> - Object with user info Throws:

  • Error Will throw error if not logged in AND no id/name is specified, or for generic network issues.
Param Type Description
[config] object The request config.
[config.id] number The id of the user you want to get info about.
[config.name] string The name of the user you want to get info about.

Example

 .then(r => console.log(r));account

Example

 .then(r => console.log(r));mith'})ith'

client.setUserInfo(change) ⇒ Promise.<object>

Edit user info/general settings.

Kind: instance method of Client Returns: Promise.<object> - Object with success property set to true or false. Throws:

  • Error Will throw error if not logged in or for generic network issues.
Param Type Description
change object The object with the change you want to want.

Example

client.setUserInfo({receive_dmails: false})

client.getNotificationSettings() ⇒ Promise.<object>

Get user settings fetching latest data from api

Kind: instance method of Client Returns: Promise.<object> - Object with user info Throws:

  • Error Will throw error if not logged in or for generic network issues.

Example

 .then(r => console.log(r));

client.setNotificationSettings(change) ⇒ Promise.<object>

Edit notifications settings.

Kind: instance method of Client Returns: Promise.<object> - Object with success property set to true or false. Throws:

  • Error Will throw error if not logged in or for generic network issues.
Param Type Description
change object The object with the change you want to make.

Example

client.setNotificationSettings({category_id: 1, is_email: true, is_push: true})push

client.searchSubmissions(config) ⇒ Promise.<Array.<{meta: object, data: Array.<object>}>>

It can fail with an error 408 if the search time is exceeded.logged in.
you are logged in.

Kind: instance method of Client Returns: Promise.<Array.<{meta: object, data: Array.<object>}>> - Array containing the meta and data part, the latter with submissions as objects. Throws:

  • Error Will throw an error not logged in, the search time is exceeded or for generic network issues.

Todo

  • Add personalized recommended parameter
Param Type Description
config object The request config
[config.order_by] 'popularity' | 'date' | 'quality' | 'random' | 'recently_favorited' | 'recently_voted' Sort order.
[config.limit] number Number of submissions wanted at once. Maximum is 100.
[config.next] string The metadata used to scroll through the submission. If set, it will return the next 'page' of a request.
[config.prev] string The metadata used to scroll through the submission. If set, it will return the previous 'page' of a request.
[config.rating] object Nudity rating filters.
[config.rating.g] boolean Everyone.
[config.rating.r15] boolean Younger teenagers.
[config.rating.r18] boolean Adults.
[config.date] Date | Array.<Date> Specify the search day or the search interval in an array.
[config.hide_posts_in_books] 'never' | 'always' | 'in-larger-tags' Hide book pages grouped into books
[config.threshold] number Filters away everything under the threshold. Ranges from one to five.
[config.size] 'any' | 'large' | 'huge' | 'long' | 'wallpaper' | '16:9' | '4:3' | '3:2' | '1:1' Size of the media.
[config.file_type] 'any' | 'video' | 'gif' Type of the media.
[config.recommended_for] string Show media recommended for username.
[config.favorited_by] string Show media favorited by username.
[config.voted_by] string Show media voted by username.
[config.uploaded_by] string Show media uploaded by username.
[config.tags] Array.<string> Tags following the format 'yuri','-yaoi'

Example

client.searchSubmissions({limit: 1, order_by: 'random'})

Example

client.searchSubmissions({order_by: 'random', rating: {g: false, r15: false, r18: true}, tags: ['yuri', '-yaoi']})

Example

client.searchSubmissions({tags: ['-video']})

Example

console.log(r1 === r3); // trueubmissions({ prev: r2.meta.prev, tags: ['yuri'] }); // Page 2 -> Page 1

Example

// Would probably return code 408 without premium 1), new Date(2020, 1, 30)] });

client.searchBooks(config) ⇒ Promise.<Array.<{meta: object, data: Array.<object>}>>

⚠ The "Search by article title" filter is not implemented because as of 31/03/2021 it is broken (tested with a free account only).

Kind: instance method of Client Returns: Promise.<Array.<{meta: object, data: Array.<object>}>> - Array containing the meta and data part, the latter with books as objects. Throws:

  • Error Will throw an error not logged in or for generic network issues.
Param Type Description
config object The request config
[config.order_by] 'popularity' | 'date' | 'quality' | 'random' | 'recently_favorited' | 'recently_voted' Sort order
[config.limit] number Number of submissions wanted.
[config.next] string The metadata used to scroll through the submission. If set, it will return the next 'page' of a request.
[config.prev] string The metadata used to scroll through the submission. If set, it will return the previous 'page' of a request.
[config.rating] object Nudity rating filters.
[config.rating.g] boolean Everyone.
[config.rating.r15] boolean Younger teenagers.
[config.rating.r18] boolean Adults.
[config.favorited_by] string Show media favorited by username.
[config.voted_by] string Show media voted by username.
[config.show_empty] boolean Show books with no posts.
[config.tags] Array.<string> Tags following the format 'yuri','-yaoi'

Example

 .then(r => console.log(r.data))andom'})

client.getSubmission(id) ⇒ Promise.<object>

If logged it, it will also return the user_vote, and is_favorited.

Kind: instance method of Client Returns: Promise.<object> - Submission object

Param Type Description
id number id of the submission

Example

 .then(r => console.log(r));8)

client.getBook(id) ⇒ Promise.<object>

If logged it, it will also return the user_vote, and is_favorited.

Kind: instance method of Client Returns: Promise.<object> - Book object Throws:

  • Error Throws error for generic network issues, or if a book with the id doesn't exist.
Param Type Description
id number id of the book

Example

 .then(r => console.log(r));

client.getComments(config) ⇒ Promise.<object>

Get comments of a post/submission

Kind: instance method of Client Returns: Promise.<object> - Object with all the returned data. Throws:

  • Error Throws error for generic network issues, or if the submission is premium and client isn't logged in with a premium account
Param Type Description
config object The request config
[config.type] 'books' | 'posts' Whether you want to get comments for a book or a submission
[config.limit] number Number of comments wanted.
[config.page] number Page number
config.id number id of the book/submission

client.getDMs([config]) ⇒ Promise.<object>

Get private messages

Kind: instance method of Client Returns: Promise.<object> - Object with all the returned data. Throws:

  • Error Throws error if not logged in and for generic network issues.
Param Type Description
[config] object The request config
[config.limit] number Number of private messages wanted.
[config.page] number Page number

client.sendDM(config) ⇒ Promise.<object>

Send DM to user with id.

Kind: instance method of Client Returns: Promise.<object> - Object with returned data
Throws:

  • Error Throws error if not logged in, for generic network issues, in case of invalid request data or if you try to send a message to yourself.
Param Type Description
config object The request config
config.id number id of the user
config.title string The title of the DM
config.body string The body of the DM

Example

await client.sendDM({ id: user.id, title: 'test', body: 'test' });

client.scoreComment(config) ⇒ Promise.<object>

Upvote or downvote comment

Kind: instance method of Client Returns: Promise.<object> - Object with all the returned data.

Param Type Description
config object The request config
config.id number id of the comment
config.score 'minus' | 'plus' Whether you want to upvote (plus) or downvote (minus)

Example

client.scoreComment({ id: 111319, score: 'plus' });

client.like(config) ⇒ Promise.<{success: boolean, post_id: number, favorited_users: string, score: number}>

Add like to a book or post.

Kind: instance method of Client Returns: Promise.<{success: boolean, post_id: number, favorited_users: string, score: number}> - - Object with all the returned data. Throws:

  • Error Will throw an error not logged in or for generic network issues.
Param Type Description
config object The request config
[config.type] 'books' | 'posts' Whether you want to like a book or a submission
config.id number id of the post/submission
[config.remove] boolean If you want to remove the like instead of adding it, set this to true.

Example

 //  { success: true, post_id: 24838772, favorited_users: '', score: 40 }

client.vote(config) ⇒ Promise.<{success: boolean, post_id: number, vote_count: number, score: number}>

Add, edit or remove vote to a book or post.

Kind: instance method of Client Returns: Promise.<{success: boolean, post_id: number, vote_count: number, score: number}> - Object with all the returned data. Throws:

  • Error Will throw an error not logged in or for generic network issues.
Param Type Description
config object The request config
[config.type] 'books' | 'posts' Whether you want to like a book or a submission
config.id number id of the post/submission
config.score number Score to give. Goes from one to five. Give zero to remove the vote.

Example

 // { "success":true, "post_id":24835970, "vote_count":2, "score":10 }