-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Updated as of sankaku-client version 2.0.0.
Sankaku-api client
Kind: global class
-
Client
- new Client([extra_headers])
-
.login(account) ⇒
Promise.<void>
-
.logout() ⇒
Promise.<void>
-
.isLoggedIn() ⇒
boolean
-
.getUserInfo([config]) ⇒
Promise.<object>
-
.setUserInfo(change) ⇒
Promise.<object>
-
.getNotificationSettings() ⇒
Promise.<object>
-
.setNotificationSettings(change) ⇒
Promise.<object>
-
.searchSubmissions(config) ⇒
Promise.<Array.<{meta: object, data: Array.<object>}>>
-
.searchBooks(config) ⇒
Promise.<Array.<{meta: object, data: Array.<object>}>>
-
.getSubmission(id) ⇒
Promise.<object>
-
.getBook(id) ⇒
Promise.<object>
-
.getComments(config) ⇒
Promise.<object>
-
.getDMs([config]) ⇒
Promise.<object>
-
.sendDM(config) ⇒
Promise.<object>
-
.scoreComment(config) ⇒
Promise.<object>
-
.like(config) ⇒
Promise.<{success: boolean, post_id: number, favorited_users: string, score: number}>
-
.vote(config) ⇒
Promise.<{success: boolean, post_id: number, vote_count: number, score: number}>
Param | Type | Description |
---|---|---|
[extra_headers] | object |
Headers added to every request. |
Example
const client = new Client({header1: 'header1_info', header2: 'header2_info'});
⚠ 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
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).
Returns whether the Client is logged in or not.
Kind: instance method of Client
Returns: boolean
- Log-in status
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'
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})
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));
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
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)] });
⚠ 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'})
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)
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));
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 |
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 |
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' });
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 }