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

hackerschool-api

v0.1.1

Published

Node wrapper for Hacker School API, including OAuth flow

Downloads

1

Readme

hackerschool-api

This library is meant to be a node wrapper for the Hacker School API. It encapsulates the OAuth flow as well as all the API endpoints.

Installation

npm install hackerschool-api

Usage

OAuth flow

var hackerschool = require('hackerschool-api'),
    app = require('express')();

var client = hackerschool.client();

var auth = hackerschool.auth({
  client_id: process.env.CLIENT_ID,
  client_secret: process.env.CLIENT_SECRET,
  redirect_uri: process.env.REDIRECT_URI
});

app.get('/login', function(req, res) {
  var authUrl = auth.createAuthUrl();

  // redirect the user to the auth page
  res.redirect(authUrl);
});

app.get('/oauthCallback', function(req, res) {
  var code = req.query.code;

  auth.getToken(code)
  .then(function(token) {
    // tells the client instance to use this token for all requests
    client.setToken(token);
  }, function(err) {
    res.send('There was an error getting the token');
  });
});

app.listen(3000);

Getting resources

These assume that the access token has already been set.

var hackerschool = require('hackerschool-api');

var client = hackerschool.client();

// Get information about the currently authorized hackerschooler
client.people.me()
.then(function(me) {
  console.log(me);
});

// Get information about a specific hackerschooler
client.people.person(901)
.then(function(person) {
  console.log(person);
});

// Get a list of all batches
client.batches.list()
.then(function(batches) {
  console.log(batches);
});

// Get information about a specific batch
client.batches.batch(12)
.then(function(batch) {
  console.log(batch);
});

// Get a list of the hackerschoolers in a specific batch
client.batches.people(12)
.then(function(people) {
  console.log(peoeple);
});

API reference

Auth

Auth contains the OAuth flow.

new hackerschool.Auth(config)

Config should be an object containing the following objects:

  • client_id: API client ID
  • client_secret: API client secret
  • redirect_uri: API redirect URI

Returns a new Auth object.

Auth.createAuthUrl()

Returns an authorization URL that the user should be redirected to in order to authorize access to their data.

Auth.getToken(code, [callback])

Makes a call to the access token endpoint with the given authorization code.

Returns a promise that resolves with the token. Also takes an optional callback if that's more your thing.

People

people.me()

Gets information about the currently authorized user.

Returns a promise that resolves with the person object.

people.person(id)

Gets information about about a specific hackerschooler by ID.

Returns a promise that resolves with the person object.

Batches

batches.list()

Gets a list of all current and previous batches.

Returns a promise that resolves with an array of batches.

batches.batch(id)

Gets information about a specific batch.

Returns a promise that resolves with the batch object.

batches.people(id)

Gets a list of hackerschools in a particular batch.

Returns a promise that resolves with an array of people.