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

zds-api-client

v1.0.1

Published

Zeste de Savoir API Client

Downloads

5

Readme

zds-api-client

NPM Package

Coverage Status Build Status

Client Javacript pour l'API de Zeste de Savoir. Fonctionne avec Node.js, et dans le navigateur via browserify/webpack.

Utilisation

npm install zds-api-client

Les méthodes de ce client suivent à peu près celle de l'API, sous la forme api.{nom de l'api}().{methode}({parametres}, {callback}), avec la méthode en camelCase.

Exemple 1: lister les membres

var api = require("zds-api-client");

api.membres().list(function(err, results) {
    if(err) throw err;

    console.log(results);
    /*
       { count: 1337,
         results: [{
             pk: 1,
             username: 'John Doe'
         }, ...]
       }
    */
});

Exemple 2: Bannir un membre

Pour certaines "sous-resources", il faut chainer avec la méthode patch(pk)

var api = require("zds-api-client");

api.membres().patch(136).ban.set(function(err, results) {
    // ...
});

Jetez un oeil dans api/ pour voir toutes les méthodes de l'API.

Exemple 3: Modifier un membre

Les données de formulaires POST/PUT doivent passer par le paramètre resource. Le callback est d'ailleurs optionnel

var api = require("zds-api-client");

api.membres().update({ pk: 136, resource: {
    sign: "npm <3"
});

OAuth2

var api = require("zds-api-client");
var OAuth2 = api.auth.OAuth2;

var authClient = new OAuth2(CLIENT_ID, CLIENT_SECRET);
authClient.getToken({
    username: "John Doe",
    password: "123456"
}, function(err, tokens) {
    if(err) throw err;

    authClient.credentials = tokens;

    console.log(tokens);
    /*
        {
            access_token: ...,
            refresh_token: ...
        }
    */

    // On fait une requete avec l'authentification
    api.membres().monProfil({ auth: authClient }, function(err, results) {
        // ...
    })
});

Vous pouvez sauvegarder le refresh_token dans votre base de données pour l'utiliser pour regénérer un access_token plus tard:

var api = require("zds-api-client");
var OAuth2 = api.auth.OAuth2;

var authClient = new OAuth2(CLIENT_ID, CLIENT_SECRET);
authClient.getToken({
    refresh_token: ...
}, function(err, tokens) {
    // ...
});

L'access token est automatiquement rafraichit s'il arrive à expiration lors d'une requête.

Changer l'URL de base

Par défaut, les requètes se font sur https://zestedesavoir.com. Si vous voulez changer cette URL, utilisez la méthode api.setBaseURL.

var api = require("zds-api-client");

api.setBaseURL("http://localhost:8000");
api.membres().list(function() { ... });