noop(); pop(); map();

    exoplay-node-sdk

    0.2.0 • Public • Published

    exoplay-node-sdk

    A library for interacting with the exoplay API over javscript. Works with both node and client-side javascript.

    Installation

    Usage

    The Exoplay API is highly RESTful, and therefore predictable.

    • GET gets data based on a query. Most data fields on a resource type are queryable (refer to exoplay.net API documentaion for exceptions)
    • POST posts new data to a resource type
    • PUT replaces data at a given ID
    • PATCH merges data changes at a given ID
    • DELETE deletes data matching a query or ID

    Basic example:

    var ExoplayAPI = require('exoplay-node-sdk');
    var gameId = 'myawesomegame';
     
    function handleError(error) {
      console.log(error.statusCode, error.message);
    }
     
    exoplayAPI = new ExoplayAPI('myawesomegame', {
      origin: 'https://api.exoplay.net', // optional, defaults to exoplay production url
      defaultErrorHandler: handleError // optional, catches API errors
    });
     
    // get the token from oauth, and use it below.
    var token = session.get('token'); 
     
    // Format: <api instance>.<api>.<method>([... destructuring paramaters], query);
    // Returns: promise, which evaluates to (meta, data)
    // Meta is information from the headers, shuch as an updated oauth token
    // Data is the raw data from the API
     
    // Get scope information for users who have an "owner" or "manager" role
    // attached to the "clan" resource of id "theAwesomeClan"
     
    exoplayAPI.withAuth(token).scopes.get('clan', 'theAwesomeClan', {
        role: ['owner', 'manager']
      })
      .then(function(meta, scopes) {
        console.log('There are ' + scopes.length + ' owners or managers.');
      })
     
    /* ---------------------------------------------------------------------------
    Note: you can clean up the code a bit, if your execution path is safe. But, if
    you're doing async work on a web server and you're not careful about where your
    token is coming from, you could accidentally serve requests with the wrong
    token, which is very bad. Watch your async flows!
     
    As a benefit, if `meta` contains an updated `token`, your token will be
    automatically applied to the next new request.
    */
     
    var myAPI = exoplayAPI.withAuth(token);
    myAPI.scopes.get(...);
    myAPI.scopes.patch(...);
    /* -------------------------------------------------------------------------- */
     
     
    // Add the "manager" role to the user "ajacksified" for the "clan" resource
    // of id "theAwesomeClan"
     
    exoplayAPI.withAuth(token).scopes.put('clan', 'theAwesomeClan', 'ajacksified', 'manager')
      .then(function(meta, scopes) {
        console.log('Updated self, and got a new token', meta.token);
        token = meta.token;
      })
      // supply a custom error handling function instead of using the default
      .catch(function(error) {
        if (error.statusCode === 403) {
          console.log('You do not have permissions for that!');
        }
      });
     
     
    // Add the "manager" and "owner" roles to the user "ajacksified" for the "clan"
    // resource of id "theAwesomeClan"
     
    exoplayAPI.withAuth(token).scopes.post('clan', 'theAwesomeClan', 'ajacksified' {
        scope: ['owner', 'manager']
      })
      .then(function(res) {})
     
     
    // Replace the roles of the user "ajacksified" for the "clan" resource of id
    // "theAwesomeClan" with ['owner, manager']
     
    exoplayAPI.withAuth(token).scopes.put('clan', 'theAwesomeClan', 'ajacksified' {
        scope: ['owner', 'manager']
      })
      .then(function(res) {})
     
     
    // Delete a role from the user "ajacksified" for the "clan" resource of id
    // "theAwesomeClan"
     
    exoplayAPI.withAuth(token).scopes.del('clan', 'theAwesomeClan', 'ajacksified', 'owner')
      .then(function(res) {})
     
     
    // Delete all roles from the user "ajacksified" for the "clan" resource of id
    // "theAwesomeClan"
     
    exoplayAPI.withAuth(token).scopes.del('clan', 'theAwesomeClan', 'ajacksified')
      .then(function(res) {})
     
    // Delete all roles from the user "ajacksified" and "doriangray" for the "clan"
    // resource of id "theAwesomeClan"
     
    exoplayAPI.withAuth(token).scopes.del('clan', 'theAwesomeClan', {
        userId: [ 'ajacksified', 'doriangray' ]
      })
      .then(function(res) {})

    Per-endpoint documentation is available in ./docs.

    Development

    • Read the contribution guide and browse existing issues and PRs for similar changes or issues. If in doubt, create an issue before writing code. The contribution guide contains guidelines for code standards and git flow.
    • Fork this repository
    • Install node (v0.10+)
    • Make changes, and add or modify tests where necessary. Run tests using npm test, which runs mocha.
    • Create a pull request

    License

    Copyright 2016 Exoplay, LLC. GPLv3 Licensed. Free for personal or commercial use. See LICENSE for details.

    Install

    npm i exoplay-node-sdk

    DownloadsWeekly Downloads

    3

    Version

    0.2.0

    License

    GPL-3.0

    Last publish

    Collaborators

    • ajacksified