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

buycraft

v1.0.4

Published

Simple node.js wrapper for the Buycraft API

Downloads

17

Readme

Buycraft for Node.js Build Status NPM Version

Simple node.js wrapper for Buycraft's HTTP API.

Downloads Dependencies License

Table of Contents

Installation

To use buycraft in your projects execute the following command from the command line:

$ npm install --save buycraft

Usage

To use the module simply require it at the top of any script you need it in.

var buycraft = require('buycraft');

You must provide a "secret key" in order to use the API, you can find out how to get one here. You don't require a server to do this, however using this would be pretty pointless if you don't have one. :wink:

You can set the secret key simply by calling the setKey method as follows:

buycraft.setKey('foo_bar');

Please bear in mind there's minimal verification for keys. If you're experiencing issues then consider double checking everything works outside of your application.

Configuring HTTPS

I'm personally fond of HTTPS, though if you want to switch to plain ol' HTTP then it's as simple as this:

buycraft.setSecure(false);

Fetching Categories

If you fancy printing a list of every category to the console then you could use the following snippet to achieve this.

buycraft.getCategories(function(categories) {
    categories.forEach(function(category) {
        console.log('Category: ' + category.name);
    });
});

Fetching Packages

Fetching packages is no problem either, you can do this using code that's mostly the same as fetching categories.

buycraft.getPackages(function(packages) {
    packages.forEach(function(package) {
        console.log('Package: ');
        console.log('\t' + package.name);
        console.log('\t' + package.category);
        console.log('\t' + package.description);
    }
});

Fetching Payments

Need to know how much money Notch has spent on your server? Easy.

var config = {
    ign: 'Notch'
};

var process = function(payments) {
    var spent = 0.00;
    payments.forEach(function(payment) {
        spent += parseFloat(payment.price).toFixed(2);
    });
    
    return spent;
};

buycraft.getPayments(config, function(payments) {   
    console.log('Notch has spent $' + process(payments) + ' on your server!');
});


/*
 * "What if I want to know much everyone has spent?"
 * Got you covered, though I'm unsure how far this snippet goes back as my buycraft account is less than 24 hours old.
 */
buycraft.getPayments(null, function(payments) {
    console.log('People have spent $' + process(payments) + ' on your server, wow!');
});

Documentation

"Proper" documentation (generated by JSDoc) is available here, it should be noted that this is currently a work in progress though.

If you wish to generate the documentation files locally then you may execute the following commands:

$ npm install -g jsdoc
$ jsdoc ./lib/

If you happen to use IntelliJ (or another IDE/Editor with JSDoc support) then you will find that the code completion tool will include each property an object has, eg: the name property of a package.

Autocompletion

Todo

  • Figure out if it's possible to capture a PHP session ID and CSRF token then re-use, would allow editing of packages from third party websites but requires a user to login first.