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

playoff

v1.0.0

Published

Playoff SDK for NodeJS

Downloads

12

Readme

Playoff Node SDK

Playoff Node SDK NPM version

Playoff API implementation in NodeJS. This module integrates seamlessly with the passport-playoff module for authentication support.

Visit the complete API reference

To learn more about how you can build applications on Playoff visit the official developer documentation

##Install To get started simply run

npm install playoff

The Playoff class allows you to make rest api calls like GET, POST, .. etc

var Playoff = require('playoff').Playoff;
var PlayoffException = require('playoff').PlayoffException;
var pl = new Playoff({
    type: 'client'
    version: 'v1',
    client_id: "Your client id",
    client_secret: "Your client secret"
});

// To get infomation of the player johny
pl.get('/player',{ player_id: 'johny' }) 
.then(function(player) {
    console.log(player);
})
.catch(PlayoffException, function(err) {
    console.log('Name', err.name);
    console.log('Message', err.message);
    console.log('Status', err.status);
})
.catch(function(err) {
    console.log(err);
    console.log(err.response);
});

pl.post("/definitions/processes/collect", { 'player_id': 'johny' }, { 'name': 'My First Process' })
.then(function(process) {
    console.log(process);
});

Usage

Create a client

If you haven't created a client for your game yet just head over to Playoff and login into your account, and go to the game settings and click on client.

1. Client Credentials Flow

In the client page select Yes for both the first and second questions client

var Playoff = require('playoff').Playoff;
var PlayoffException = require('playoff').PlayoffException;
var pl = new Playoff({
    type: 'client'
    version: 'v2',
    client_id: "Your client id",
    client_secret: "Your client secret",
    hostname: "yourplayoffinstallationdomain.com"
});
``
# Client Scopes
![Client](https://cloud.githubusercontent.com/assets/1687946/9349193/e00fe91c-465f-11e5-8094-6e03c64a662c.png)

Your client has certain access control restrictions. There are 3 kind of resources in the Playoff REST API they are

1.`/admin` -> routes for you to perform admin actions like making a player join a team

2.`/design` -> routes for you to make design changes programmatically

3.`/runtime` -> routes which the users will generally use like getting a player profile, playing an action

The resources accessible to this client can be configured to have a read permission that means only `GET` requests will work.

The resources accessible to this client can be configured to have a write permission that means only `POST`, `PATCH`, `PUT`, `DELETE` requests will work.

The version restriction is only for the design resource and can be used to restrict the client from accessing any version of the game design other than the one specified. By default it allows all.

If access to a route is not allowed and then you make a request to that route then you will get an error like this,
```json
{
  "error": "access_denied",
  "error_description": "You are not allowed to access this api route"
}

Documentation

You can initiate a client by giving the client_id and client_secret params

var Playoff = require('playoff').Playoff;
var PlayoffException = require('playoff').PlayoffException;
var pl = new Playoff({
    type: 'client' or 'code',
    client_id: 'Your client id',
    client_secret: 'Your client Secret',
    version: 'v1',
    redirect_uri: 'The url to redirect to', //only for auth code flow
    store: function(access_token, done) {
        //This function which will persist the access token to a database.
        //You  have to persist the token to a database if you want the access
        //token to remain the same in every request
        done(null, access_token);
    }, 
    load: function(done) {
        //This function which will load the access token. This is called 
        //internally by the sdk on every request so the the access token can 
        //be  persisted between requests
       done(null, access_token);
    }
});

In development the sdk caches the access token in memory so you dont need to provide the store and load functions. But in production it is highly recommended to persist the token to a database. It is very simple and easy to do it with redis. You can see the test cases for more examples.

var Playoff = require('playoff').Playoff;
var PlayoffException = require('playoff').PlayoffException;
var redis = require('ioredis');

var pl = new Playoff({
    type: 'client' or 'code',
    client_id: 'Your client id',
    client_secret: 'Your client Secret',
    version: 'v1',
    store: function(access_token, done) {
        redis.hmset("access_token", access_token)
        .then(function(access_token) {
            done(null, access_token);
        });
    }, 
    load: function(done) {
        redis.hmgetall("access_token")
        .then(function(access_token) {
            done(null, access_token);
        });
    }
});

Methods

All these methods return a bluebird Promise. All these methods return the request data only when full_response is false but return headers, status, body of the response when full_response is true.

api (method, route, query, body, full_response = false)
This will allow you to make any HTTP method request to the Playoff API

get (route, query, full_response = false)
This will make a GET request to the Playoff API

post (route, query, body, full_response = false)
This will make a POST request to the Playoff API

patch (route, query, body, full_response = false)
This will make a PATCH request to the Playoff API

put (route, query, body, full_response = false)
This will make a PUT request to the Playoff API

delete (route, query, full_response = false)
This will make a DELETE request to the Playoff API

upload (url, query, formData, full_response)
This will upload any formData you want to send to the server like files, images etc. Files need to be sent as streams like this, upload("/runtime/player/image", req.query, {file: fs.createReadStream(path) }) This uses the request library so the pattern should be the same

getAuthorizationURI ()
This will return the url to which the user needs to be redirected to login. This doesn't need

exchangeCode (code)
This is used in the auth code flow so that the sdk can get the access token. Before any request to the playoff api is made this has to be called atleast once.This should be called in the the route/controller which you specified in your redirect_uri.

PlayoffException
This is thrown whenever an error occurs in each call. The Error contains the name, message, status, headers and data fields which can be used to determine the type of error that occurred.

License

Playoff NodeJS SDK
http://dev.playoffgamification.io/
Copyright(c) 2019, Officina S.r.l. [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.