npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

habitica

v4.0.0

Published

A node wrapper for the habitica api

Downloads

785

Readme

Habitica

Build Status

A very thin wrapper for the Habitica API

Installation

npm install habitica --save

Usage

This package is intentionally light and unopinionated. It should be used in conjunction with Habitica's API documentation.

Setup

The first thing you need to do is instantiate your client. All the configuration properties are optional and can be set later.

var Habitica = require('habitica');
var api = new Habitica({
  id: 'your-habitica.com-user-id',
  apiToken: 'your-habitica.com-api-token',
  endpoint: 'http://custom-url.com/', // defaults to https://habitica.com/
  platform: 'Your-Integration-Name' // defaults to Habitica-Node
});

Using the register or localLogin methods will set the User Id and API token automatically.

api.register(
  'username',
  'email',
  'password'
).then((res) => {
  var user = res.data

  // do something with user
  // hit a route with the authenticated client
  return api.get('/groups')
}).then((res) => {
  var groups = res.data

  // do something
});

api.localLogin(
  'username or email',
  'password'
).then((res) => {
  var creds = res.data

  // do something with the credentials
  // hit a route with the authenticated client
  return api.get('/groups')
}).then((res) => {
  var groups = res.data

  // do something
});

If your integration prompts the user to enter their credentials, you can use the setOptions method.

api.setOptions({
  id: 'the-uuid',
  apiToken: 'the-api-token'
})

Request Methods

There are four main methods to make requests to the API. get, post, put and del. Each corresponds to one of the main HTTP verbs.

get takes an optional second argument that is an object that gets converted to a query string. The rest have an optional second argument that is the post body and a third optional argument that will be converted to a query string.

Each method returns a promise which resolves the raw data back from the API. The data will reside on the data property.

api.get('/user').then((res) => {
  var user = res.data

  return api.put('/user', {
    'profile.name': 'New Name'
  })
}).then((res) => {
  var user = res.data
  user.profile.name // 'New Name'

  return api.post('/tasks/user', {
    type: 'todo',
    text: 'A new todo'
  })
}).then((res) => {
  var task = res.data

  return api.post('/tasks/' + task.id + '/score/up')
}).then((res) => {
  // Your task was scored!
}).catch((err) => {
  if (err.message) {
    // API Error, display the message
  } else {
    // something else in your integration went wrong
  }
})

For full documentation with examples visit the docs site.

Documentation

The documentation is generated automatically using JSDoc.

Testing

To run all the tests:

$ npm t
  • The bulk of the tests are integration tets that expect a Habitica dev instance to be running.

  • A mongodb instance must be running already in order to run the tests locally.

  • By default, the test infrastructure assumes that the repo for Habitica is '../../habitica', relative to the test directory. You may pass in your own path by exporting the environmental variable PATH_TO_HABITICA.

    $ export PATH_TO_HABITICA='../../some/other/path';
  • By default, the app will be served on port 3321. This can be configured with the environmental variable HABITICA_PORT:

    $ export HABITICA_PORT=3001;
  • By default, the mongodb uri is 'mongodb://localhost/habitica-node-test'. You can configure this variable with the environmental variable HABITICA_DB_URI:

    $ export HABITICA_DB_URI='mongodb://localhost/some-other-db';

Support

This module requires the Promise object to function. If you are using this module in a context without Promises (such as Browserifying for IE9), you will need to polyfill them.

Supports Node >= 4