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

pavlok

v0.3.2

Published

A module to connect with Pavlok's API easily and quickly.

Downloads

10

Readme

Pavlok API Module

Purpose

The Pavlok module makes it easy to play with your Pavlok device.

It works in two modes

  • local development mode
  • server mode

Local Mode

It can be used to play around with your device in a local development environment. It spins up a simple express server and needs permission to listen on one of your system's ports.

Server Mode

It can be used to plug the module into your existing express server and build features/workflows for your pavlok device.

Installation

Using NPM

npm install --save pavlok

Using YARN

yarn add pavlok

Setup

You would need two keys for the module to work

  • client ID
  • client secret

Navigate here and login with your Pavlok account to get one.

You'll need to choose a callback URL of http://localhost:<PORT>/auth/pavlok/result for local mode. Here, the PORT is the port you would like the module to run on in local mode. By default the value of PORT is 3000.

Custom callback URLs are supported in server mode and is required while the module initialization.

Usage

First thing you'd need to do is import the module into your app.

const pavlok = require('pavlok');

The simplest and quickest way to start using the module is to try it in the local mode.

pavlok.init(CLIENT_ID, CLIENT_SECRET);
pavlok.login(function (result, code) {
	if (result) {
		console.log("Code is " + code);
		pavlok.vibrate(); // or you can call other methods like beep() or zap()
	}
});

This spins up a server on port 3000. (ex: http://localhost:3000/). It initializes the Pavlok module and logs you in. Now you can start sending the stimuli to your device.

If you would like to configure a custom port for the local mode, you can do so by passing a custom options object as the third paramater to the init method. Make sure to mention the port in the callback URL of application you created here

pavlok.init(CLIENT_ID, CLIENT_SECRET, { "port": 8080 }); // runs on port 8080
pavlok.login(function (result, code) {
	if (result) {
		console.log("Code is " + code);
	}
});

Here's short gif on how to use the pavlok module in local mode

Local mode pavlok module - yarn

Or, if you prefer NPM, here's how you can add it to your npm project

Local mode pavlok module - npm

To Use the module in the server mode, you would need to pass a couple of more options in the the init method and ensure you call it before your server starts listening

pavlok.init(CLIENT_ID, CLIENT_SECRET, {
	"verbose": true,
	"app": app, //Express server
	"message": "Hello from the server example!", //Default message for all stimuli
	"callbackUrl": "<Your Server Root URL>/pavlok/result",
	"callbackUrlPath": "/pavlok/result",
	"successPath": "/success", //Where to redirect when the token has been saved to session
	"failurePath": "/error" //Where to redirect when the token couldn't be gotten/saved
});
app.get("/auth", function (req, res) {
	pavlok.auth(req, res);
});

Now that you are authenticated, you can start sending the stimuli to your Pavlok device from the server.

Stimuli methods for the server mode take a required parameter in the options object i.e. request. It is the request object that an express server gets when one of it's api is called. Stimuli methods expects an authorization token stored on the request object to verify the user.

So a simple call to one of the stimuli method would look like

// REQUEST is the request object in one of the express routes
pavlok.vibrate({request: REQUEST});

You can send in more optional paramters to configure the device stimuli. For example, you can increase the zap intensity to it's maximum by using the following code

pavlok.zap({request:REQUEST, intensity: 255})

Here's short gif on how to use the pavlok module in server mode

server mode pavlok module - yarn

Further Reading

See the full documentation and examples for full documentation and a walkthrough.

Notes for Users Coming from Versions < 2

Though simliar, older versions of the module use slightly different syntax. All the stimuli messages (zap, beep, etc.) now take their arguments in a single object with named parameters instead of the old ordered argument list. Versions before 2 also didn't support server mode of the pattern option.

License

Licensed under the ISC license.