weverse
v0.1.4
Published
Wrapper for weverse private API
Downloads
4
Readme
Usage
Provide credentials
See MujyKun's guide on finding your Weverse access token.
import { WeverseClient } from "weverse";
const myClient = new WeverseClient({token: 'my-access-token'})
// or
const myClient = new WeverseClient({username: 'jonah', password: 'top-secret'})
Initialize
import { WeverseClient } from "weverse";
const myClient = new WeverseClient({token: 'my-access-token'})
await myClient.init({allPosts: true, allNotifications: false})
myClient.communities.forEach(community => {
// typesafe objects with autocompletion
const details = {
name: community.name
posts: community.posts.length
}
// do something
})
Listen for new notifications
import { WeverseClient } from "weverse";
const myClient = new WeverseClient({token: 'my-access-token'})
myClient.init({allPosts: true, allNotifications: false})
myClient.on('init', async (ready) => {
if (ready) {
myClient.listen({listen: true, interval: 5000})
}
})
myClient.on('comment', (comment, post) => {
// all objects are typed
const commenter = myClient.artistById(comment.artist.id)
const postAuthor = myClient.artistById(post.artist.id)
console.log(`${commenter.name} commented on ${postAuthor.name}'s post!`)
})
myClient.on('post', (post) => {
if (post.photos.length) {
post.photos.forEach(photo => {
downloadImage(photo.orgImgUrl)
})
}
})
Credit
All credit to MujyKun for reverse-engineering most of the Weverse endpoints used by this module.
Classes
WeverseEmitter
WeverseEmitter allows the WeverseClient to emit events and provides methods for doing so
Kind: global class
weverseEmitter.newError(err)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | err | Error | The error to be emitted |
weverseEmitter.ready(initialized)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | initialized | boolean | whether initialization succeeded |
weverseEmitter.newNotif(notification)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | notification | WeverseNotification | new Notification to be emitted |
weverseEmitter.newPost(post)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | post | WeversePost | new Post to be emitted |
weverseEmitter.newMedia(media)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | media | WeverseMedia | new Media to be emitted |
weverseEmitter.newComment(comment, post)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | comment | WeverseComment | the Comment that was retrieved | | post | WeversePost | the Post associated with the Comment |
weverseEmitter.loginResult(result)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | result | boolean | boolean result of the login attempt |
weverseEmitter.polled(status)
Kind: instance method of WeverseEmitter
| Param | Type | Description | | --- | --- | --- | | status | boolean | result of the poll attempt. If true, Weverse was successfully polled |
WeverseClient
Client for the private Weverse api
Kind: global class
Emits: error, init, notification, post, media, comment, login, poll
Properties
| Name | Type | Description | | --- | --- | --- | | communities | Array.<WeverseCommunity> | The communities associated with the Weverse account | | artists | Array.<WeverseArtist> | All artists in all communities associated with the account | | notifications | ClientNotifications | Subclass handling all notifications for the account | | posts | Array.<WeversePost> | All posts that have been retrieved by this client |
- WeverseClient
- new WeverseClient(authorization, verbose)
- .init(options) ⇒ Promise.<void>
- .listen(opts)
- .checker(process) ⇒ Promise.<void>
- .tryRefreshToken() ⇒ Promise.<boolean>
- .login(credentials) ⇒ Promise.<void>
- .checkLogin() ⇒ Promise.<boolean>
- .getCommunities(opts) ⇒ Promise.<Array.<WeverseCommunity>>
- .getCommunityArtists(c, opts) ⇒ Promise.<(Array.<WeverseArtist>|null)>
- .getNotifications(pages, process) ⇒ Promise.<(Array.<WeverseNotification>|null)>
- .getNewNotifications(opts) ⇒ Promise.<(Array.<WeverseNotification>|null)>
- .getMedia(id, community) ⇒ Promise.<(WeverseMedia|null)>
- .getComments(p, c, cId?) ⇒ Promise.<(Array.<WeverseComment>|null)>
- .getPost(id, communityId) ⇒ Promise.<(WeversePost|null)>
- .processNotification(n) ⇒ Promise.<void>
- .createLoginPayload() ⇒ void
- .checkToken() ⇒ Promise.<boolean>
- .handleResponse(response, url) ⇒ Promise.<boolean>
- .log()
- .communityById(id) ⇒ WeverseCommunity | null
- .artistById(id) ⇒ WeverseArtist | null
- .post(id)
- "error"
- "init"
- "notification"
- "post"
- "media"
- "comment"
- "login"
- "poll"
new WeverseClient(authorization, verbose)
| Param | Type | Description | | --- | --- | --- | | authorization | WeverseAuthorization | either {token: string} or {username: string, password: string} | | verbose | boolean | optional; defaults to false |
weverseClient.init(options) ⇒ Promise.<void>
init options: allPosts: boolean - Whether to load all posts from each community into memory. This will be slow allNotifications: boolean - Whether to load all notifications for the Weverse account. Will be slow. allMedia: boolean - not currently implemented
Kind: instance method of WeverseClient
Access: public
| Param | Type | Description | | --- | --- | --- | | options | WeverseInitOptions | optional |
weverseClient.listen(opts)
Tells the client to start or stop listening for new notifications. Options: listen: boolean - Whether the client should be listening interval: boolean - Interval in MS to listen on process: boolean (optional) - Whether new notifications should be processed into Posts/Comments/Media
Kind: instance method of WeverseClient
Access: public
| Param | Type | | --- | --- | | opts | ListenOptions |
weverseClient.checker(process) ⇒ Promise.<void>
Method passed to setInterval if client is listening for new notifications
Kind: instance method of WeverseClient
Access: protected
| Param | Type | Description | | --- | --- | --- | | process | boolean | Whether to process new notifications into Posts/Comments/Media |
weverseClient.tryRefreshToken() ⇒ Promise.<boolean>
Attempts to use a refresh token to get a new Weverse access token
Kind: instance method of WeverseClient
Returns: Promise.<boolean> - Whether a new access token was granted
Access: public
weverseClient.login(credentials) ⇒ Promise.<void>
Only used for password authentication. Attempts to login either with login given when the client was created, or with optional credentials parameter
Kind: instance method of WeverseClient
Access: public
| Param | Type | Description | | --- | --- | --- | | credentials | WeversePasswordAuthorization | optional, will override initial credentials |
weverseClient.checkLogin() ⇒ Promise.<boolean>
Force a credentials check. If login has already been converted to a token, token will be checked.
Kind: instance method of WeverseClient
Returns: Promise.<boolean> - - whether the check was successful
Access: public
weverseClient.getCommunities(opts) ⇒ Promise.<Array.<WeverseCommunity>>
Load all communities associated with this Weverse account. Returns the communities but also adds them to the cache. Options: init: boolean - Whether this method was called by the init method and should skip the login check
Kind: instance method of WeverseClient
Access: public
| Param | Type | Description | | --- | --- | --- | | opts | GetOptions | optional |
weverseClient.getCommunityArtists(c, opts) ⇒ Promise.<(Array.<WeverseArtist>|null)>
Get the artists in a community. Adds them to the cache and returns. Options: init - whether this method was called by init method and the login check should be skipped
Kind: instance method of WeverseClient
Returns: Promise.<(Array.<WeverseArtist>|null)> - returns null if failed to fetch artists
| Param | Type | Description | | --- | --- | --- | | c | WeverseCommunity | | | opts | GetOptions | optional |
weverseClient.getNotifications(pages, process) ⇒ Promise.<(Array.<WeverseNotification>|null)>
Note: If process = true, events will be emitted for new notifications AND new Posts/Comments/Media
Kind: instance method of WeverseClient
Returns: Promise.<(Array.<WeverseNotification>|null)> - - Returns only new notifications not already in cache, or null on failure
| Param | Type | Description | | --- | --- | --- | | pages | number | Optional number of pages to get; defaults to 1 | | process | boolean | Whether notifications should be processed into Posts/Comments/Media |
weverseClient.getNewNotifications(opts) ⇒ Promise.<(Array.<WeverseNotification>|null)>
Get one page of the most recent notifications
Kind: instance method of WeverseClient
| Param | Type | Description | | --- | --- | --- | | opts | NewNotifications | {process: boolean} - whether to process notifications into content |
weverseClient.getMedia(id, community) ⇒ Promise.<(WeverseMedia|null)>
Get a specific media object by id Will first check local cache, then request from Weverse
Kind: instance method of WeverseClient
Returns: Promise.<(WeverseMedia|null)> - - Returns only if media did not exist in cache
| Param | Type | | --- | --- | | id | number | | community | WeverseCommunity |
weverseClient.getComments(p, c, cId?) ⇒ Promise.<(Array.<WeverseComment>|null)>
Gets all artist comments on a given post. Returns only new comments.
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | p | WeversePost | | c | WeverseCommunity | | cId? | number |
weverseClient.getPost(id, communityId) ⇒ Promise.<(WeversePost|null)>
Get one post by id. First checks the cache, then requests from Weverse.
Kind: instance method of WeverseClient
Access: public
| Param | Type | | --- | --- | | id | number | | communityId | number |
weverseClient.processNotification(n) ⇒ Promise.<void>
Process one notification. If it refers to a post, comment, or media, attempt to add to cache
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | n | WeverseNotification |
weverseClient.createLoginPayload() ⇒ void
Encrypt provided password with Weverse public RSA key and create payload to send to login endpoint Adds the payload as a property of the client, returns void
Kind: instance method of WeverseClient
weverseClient.checkToken() ⇒ Promise.<boolean>
Check if the current token (provided or recieved from Weverse) is valid
Kind: instance method of WeverseClient
weverseClient.handleResponse(response, url) ⇒ Promise.<boolean>
If the client receives a 401 unauthorized from Weverse, will attempt to refresh credentials
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | response | AxiosResponse | | url | string |
weverseClient.log()
Log something if verbose = true
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | ...vals | any |
weverseClient.communityById(id) ⇒ WeverseCommunity | null
Check the community hashmap for a given id
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | id | number |
weverseClient.artistById(id) ⇒ WeverseArtist | null
Check the artist hashmap for a given id
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | id | number |
weverseClient.post(id)
Check the post hashmap for a given id
Kind: instance method of WeverseClient
| Param | Type | | --- | --- | | id | number |
"error"
Error event
Kind: event emitted by WeverseClient
"init"
Init event Whether initialization was successful
Kind: event emitted by WeverseClient
"notification"
Notification event New notification
Kind: event emitted by WeverseClient
"post"
Post event New post
Kind: event emitted by WeverseClient
"media"
Media event New media
Kind: event emitted by WeverseClient
"comment"
Comment event New comment. Provides comment and post.
Kind: event emitted by WeverseClient
"login"
Login event Result of login attempt.
Kind: event emitted by WeverseClient
"poll"
Poll event Result of poll attempt.
Kind: event emitted by WeverseClient