0.9.1 • Published 5 years ago

capi.js v0.9.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Capi

The unofficial Codepen.io API

How it works

  • Uses node-fetch to request data relative to the users.
  • Parse the response with cheerio.
  • Make use of promises to fetch pages synchronously.

Demo

codepen (with front-end, as in gif):

https://codepen.io/lucagez/full/GPNJdE

glitch (api only):

Installation

npm install --save capi.js

Usage

const Capi = require('capi.js');

(async () => {
    const username = 'lucagez';

    // options:
    const maxPagesToFetch = 5 // if not set, Capi will continue to fetch pens until the very last one
    const order = 'latest' // defaults to 'popular'
    // const user = new Capi(username, maxPagesToFetch, order);
    
    const user = new Capi(username);
    const userData = await user.get();

    console.log(userData);
    // => object
    // [{
    //  title: "pen1", 
    //  views: 2000, 
    //  hearts: 200, 
    //  comments: 20}, 
    //  { other object }, 
    //  ...]
})();

Api

Capi accepts the following arguments:

argumenttypedescriptionrequired
userstringUsernameyes
maxnumberMax pages to fetch before stopping execution. If not set, Capi will simply continue to fetch pens until the very last one.no
orderstringCan be equal to popular or latest. Indicates the order with which the pens are retrieved.no

License

Licensed under the MIT license.