voatapi

1.0.0 • Public • Published

Voat API for Node.js

Compatible with Voat Version: 1.0.5638.22054

Usage

Credentials

First make sure you export your voat credentials to environment variable like so:

export VOATURL="https://www.voat.co"
export VOATAPIPATH="/api/v1"
export VOATAPIKEY="<YOUR_API_KEY>"
export VOATUID="<YOUR_VOAT_USER_ID>"
export VOATPWD="<YOUR_VOAT_PASSWD>"

IMPORTANT: NEVER EVER COMMIT YOUR CREDENTIALS TO PUBLIC

A good way to do this is to include the shell script you use to .gitignore

API Token

Next, you need to login to acquire the token. You need to do this very infrequently after the first time. Check your token expiration date from your response.

api.login().then( function( result ) {
  // do something with token
  console.log( result.access_token );
});

All other functions

Next, all functions within this package return promises. That means that you can organize your code in the followind fashion:

api.loadToken( token ).then( api.getUserPreference ).then( function ( res ) {
  console.log( res );
}, function ( err ) {
  console.log( err );
});
 

In most cases, you will need to pass a parameter, so bind the function to correct context:

api.loadToken( token ).then(
  api.postUserMessage.bind(this, { body: 
                                   { recipient: "dchem",
                                     subject: "Yo DAWG",
                                     message: "I heard you like voat" } } )
).then( function ( res ) {
  console.log( res );
}, function ( err ) {
  console.log( err );
});

License

See LICENSE file.

Readme

Keywords

Package Sidebar

Install

npm i voatapi

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • dchem