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'})
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
})
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)
})
}
})
All credit to MujyKun for reverse-engineering most of the Weverse endpoints used by this module.
- WeverseEmitter
WeverseEmitter allows the WeverseClient to emit events and provides methods for doing so
- WeverseClient
Client for the private Weverse api
WeverseEmitter allows the WeverseClient to emit events and provides methods for doing so
Kind: global class
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
err | Error |
The error to be emitted |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
initialized | boolean |
whether initialization succeeded |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
notification | WeverseNotification |
new Notification to be emitted |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
post | WeversePost |
new Post to be emitted |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
media | WeverseMedia |
new Media to be emitted |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
comment | WeverseComment |
the Comment that was retrieved |
post | WeversePost |
the Post associated with the Comment |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
result | boolean |
boolean result of the login attempt |
Kind: instance method of WeverseEmitter
Param | Type | Description |
---|---|---|
status | boolean |
result of the poll attempt. If true, Weverse was successfully polled |
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"
Param | Type | Description |
---|---|---|
authorization | WeverseAuthorization |
either {token: string} or {username: string, password: string} |
verbose | boolean |
optional; defaults to false |
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 |
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 |
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 |
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
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 |
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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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
Check if the current token (provided or recieved from Weverse) is valid
Kind: instance method of WeverseClient
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 |
Log something if verbose = true
Kind: instance method of WeverseClient
Param | Type |
---|---|
...vals | any |
Check the community hashmap for a given id
Kind: instance method of WeverseClient
Param | Type |
---|---|
id | number |
Check the artist hashmap for a given id
Kind: instance method of WeverseClient
Param | Type |
---|---|
id | number |
Check the post hashmap for a given id
Kind: instance method of WeverseClient
Param | Type |
---|---|
id | number |
Error event
Kind: event emitted by WeverseClient
Init event Whether initialization was successful
Kind: event emitted by WeverseClient
Notification event New notification
Kind: event emitted by WeverseClient
Post event New post
Kind: event emitted by WeverseClient
Media event New media
Kind: event emitted by WeverseClient
Comment event New comment. Provides comment and post.
Kind: event emitted by WeverseClient
Login event Result of login attempt.
Kind: event emitted by WeverseClient
Poll event Result of poll attempt.
Kind: event emitted by WeverseClient