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

box-sdk

v0.0.8

Published

Node.js client for Box Content API

Downloads

85

Readme

Node Box SDK Build Status

Npm Downloads

Node.js client for the Box.com Content API.

Supported Features

  • All File Ops
  • All Folder Ops
  • Events - Long Polling
  • Search

The SDK aims to abstract away the intricacies of authentication, refreshing tokens, etc. as far as possible. Hence, you will not find explicit methods to perform low-level operations.

All legitimate public methods map to the high level functionality described in the Content API docs.

Getting Started

Install the module with: npm install box-sdk

Running Standalone

var box_sdk = require('box-sdk');

var logLevel = 'debug'; //default log level on construction is info

//Default host: localhost
var box = box_sdk.Box({
  client_id: 'client id',
  client_secret: 'client secret',
  port: 9999,
  host: 'somehost' //default localhost
}, logLevel);
var connection = box.getConnection('[email protected]');

//Navigate user to the auth URL
console.log(connection.getAuthURL());

connection.ready(function () {
  connection.getFolderItems(0, {limit: 1}, function (err, result) {
    if (err) {
      console.error(JSON.stringify(err.context_info));
    }
    console.dir(result);
  });
});

Running with Passport authentication under Express

Note: There is a complete express example in this gist.

var express = require('express'),
  passport = require('passport'),
  BoxStrategy = require('passport-box').Strategy,
  box_sdk = require('../../..');

...

var box = box_sdk.Box();

...

passport.use(new BoxStrategy({
  clientID: BOX_CLIENT_ID,
  clientSecret: BOX_CLIENT_SECRET,
  callbackURL: "http://127.0.0.1:" + PORT + "/auth/box/callback"
}, box.authenticate()));

...

var app = express();

...

app.get('/auth/box', passport.authenticate('box'), function (req, res) {});

app.get('/auth/box/callback',
  passport.authenticate('box', {
    failureRedirect: '/login'
  }),
  function (req, res) {
    res.redirect('/');
  });

app.get('/', function (req, res) {
  var opts = {
    user: req.user
  };
  if (req.user) {
    var connection = box.getConnection(req.user.login);
    connection.ready(function () {
      connection.getFolderItems(0, null, function (err, result) {
        if (err) {
          opts.body = err;
        } else {
          opts.body = result;
        }
        res.render('index', opts);
      });
    });
  } else {
    res.render('index', opts);
  }
});

Long Polling

var connection = box.getConnection('[email protected]');

//Navigate user to the auth URL
console.log(connection.getAuthURL());

connection.ready(function () {
  connection.startLongPolling();

  //Monologue subscription filter to catch all polling events
  connection.on('polling.event.#', function (data) {
    console.log('Received event: %s', data.event_type);

    //Handle event
    ...
  });
  connection.on('polling.end', function() {
    //Continue with post-polling ops
    ...
  });
  connection.on('polling.error', function (err) {
    console.error(err);
  });

  //Conquer the universe, etc
  ...

  //In some block later...
  //connection.stopLongPolling();
};

Testing

Before running your tests locally, copy test/env.json.example to test/env.json and fill in correct values for the environment variables to be imported during testing.

The casperjs and phantomjs executables must be available in the enviroment path. Usually it is enough to run:

$ (sudo) npm install -g phantomjs
$ (sudo) npm install -g casperjs

Run all tests with:

$ grunt mochaTest

The files under test/integration are completely self-contained, and hence can be run independently. For example:

$ grunt mochaTest --target=./test/integration/api/content/folders-test.js

Documentation

API documentation is generated by running:

$ grunt jsdoc

The generated documentation is available in the dist/docs folder. An up-to-date online version is hosted at http://adityamukho.github.io/node-box-sdk/ .

Examples

Complete tutorials will soon be added to the documentation. In the meantime, have a look at the included test cases to get an idea of how the SDK is used.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2014-2015 Aditya Mukhopadhyay

Licensed under the MIT license.