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 = ;var client = etsyjs; // direct API calls (GET / PUT / POST / DELETE)client; // or you can use some convenience methodsvar etsyUser = client;var etsySearch = client;var etsyShop = client; etsyUser;
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 = ; var client = etsyjs;
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 = session = cookieParser = url = etsyjs = # instantiate client with key and secret and set callback urlclient = etsyjsclient key: nconf secret: nconf callbackURL: 'http://localhost:3000/authorise' scope: 'email_r%20profile_r%20profile_w%20address_r%20address_w' app = appapp appget '/' req res -> client -> return consolelog err if err reqsessiontoken = responsetoken reqsessionsec = responsetokenSecret resredirect responseloginUrl appget '/authorise' req res -> # parse the query string for OAuth verifier query = urlquery; verifier = queryoauth_verifier # final part of OAuth dance request access token and secret with given verifier clientaccessToken reqsessiontoken reqsessionsec verifier err response -> # update our session with OAuth token and secret reqsessiontoken = responsetoken reqsessionsec = responsetokenSecret resredirect '/find' appget '/find' req res -> # we now have OAuth credentials for this session and can perform authenticated requests client -> consolelog err if err consoledirbody if body ressend bodyresults0 if body server = applisten 3000 -> consolelog 'Listening on port %d' serverport
API Callback Strucutre
All the callbacks fwill take first an error argument, then a data argument, like this:
etsyUser;
Pagination
Pagination is supported, simply pass through params as follows:
var params = keywords: "rainbow" offset: 1 limit: 25; client;
Etsy authenticated user api
More examples to come...
Get information about the user (GET /user)
etsyUser; //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