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

etsyjs

v0.0.6

Published

An asynchronous nodejs wrapper for the etsy v2 api.

Downloads

3

Readme

etsy-js

Thanks to GeorgiCodes for the orginal code.

etsy-js is an asynchronous nodeJS wrapper for the etsy v2 api.

Installation

Install the latest stable version

$ npm install etsy-js

Bleeding edge version

$ git clone https://github.com/GeorgiCodes/etsy-js.git
$ cd etsy-js
$ npm install

Usage

Public Mode

The Etsy API has two modes: public, and authenticated. Public mode only requires an API key (available from http://developer.etsy.com ).

var etsyjs = require('etsy-js');
var client = etsyjs.client('your_api_key');

// direct API calls (GET / PUT / POST / DELETE)
client.get('/users/sparkleprincess', {}, function (err, status, body, headers) {
  console.log(body); //json object
});

// or you can use some convenience methods
var etsyUser = client.user('sparkleprincess');
var etsySearch = client.search();
var etsyShop = client.shop('shopALot');

etsyUser.find(function(err, body, headers) {
  console.log(body); //json object
});

You can make any non-authenticated calls to the API that you need.

Authenticated Mode

The Etsy API has support for both retrieval of extended information and write support for authenticated users. Authentication can be performed from within a web application.

In authenticated mode, you need to set a client, secret and callbackURL.

var etsyjs = require('etsy-js');

var client = etsyjs.client({
  key: 'key',
  secret: 'secret',
  callbackURL: 'http://localhost:3000/authorise',
  scope: 'email_r%20profile_r%20profile_w%20address_r%20address_w'
});

In this mode, you'll need to store the request token and secret before redirecting to the verification URL. This also sets the scope for the client to access your etsy shop. A simple example in coffeescript using Express and Express Sessions:

express = require('express')
session = require('express-session')
cookieParser = require('cookie-parser')
url = require('url')
etsyjs = require('etsy-js')

# instantiate client with key and secret and set callback url
client = etsyjs.client
  key: nconf.get('key')
  secret: nconf.get('secret')
  callbackURL: 'http://localhost:3000/authorise'
  scope: 'email_r%20profile_r%20profile_w%20address_r%20address_w'

app = express()
app.use(cookieParser('secEtsy'))
app.use(session())

app.get '/', (req, res) ->
  client.requestToken (err, response) ->
    return console.log err if err
    req.session.token = response.token
    req.session.sec = response.tokenSecret
    res.redirect response.loginUrl

app.get '/authorise', (req, res) ->
  # parse the query string for OAuth verifier
  query = url.parse(req.url, true).query;
  verifier = query.oauth_verifier

  # final part of OAuth dance, request access token and secret with given verifier
  client.accessToken req.session.token, req.session.sec, verifier, (err, response) ->
    # update our session with OAuth token and secret
    req.session.token = response.token
    req.session.sec = response.tokenSecret
    res.redirect '/find'

app.get '/find', (req, res) ->
  # we now have OAuth credentials for this session and can perform authenticated requests
  client.auth(req.session.token, req.session.sec).user("etsyjs").find (err, body, headers) ->
    console.log err if err
    console.dir(body) if body
    res.send body.results[0] if body

server = app.listen 3000, ->
  console.log 'Listening on port %d', server.address().port

API Callback Strucutre

All the callbacks fwill take first an error argument, then a data argument, like this:

etsyUser.find(function(err, body, headers) {
  console.log("error: " + err);
  console.log("data: " + body);
  console.log("headers:" + headers);
});

Pagination

Pagination is supported, simply pass through params as follows:

var params = {
  keywords: "rainbow"
  offset: 1,
  limit: 25
};

client.search().findAllUsers(params, function(err, body, headers) {
  console.log("data: " + body);
});

Etsy authenticated user api

More examples to come...

Get information about the user (GET /user)
etsyUser.find(callback); //json

Development

Running the tests

$ grunt test

Contributions & Bugs

Please submit and bugs to this project and I will fix them. Pull requests also welcome.

Acknowledgements

Thanks to the ruby etsy api wrapper as I used their fixture tests data for the etsy-js tests and README outline. Thanks to octonode for the inspiration to make this API in coffeescript.

Next Steps

  • integrate with travis properly
  • Rate limiting helper method
  • More helper methods!!
  • Flesh out me.coffee (should just call user with SELF) with tests
  • use logging not console