Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
190 lines (126 sloc) 4.21 KB

Dribbble Api 0.0.3

What's this?

This is a node module, serving as Dribbble API wrapper. See the Dribbble API docs for more details.

Installation

The easiest way to install is via npm

npm install dribbble-api

Otherwise, you can install this is by taking the code and sticking it in your node_modules folder.

Usage

Dribbble doesn't (yet) require any sort of auth key or access token. Still, this module is a constructor. This way, if things change and keys are required, the constructor would be utilized and legacy code would be less effected.

Making a request looks something like this:

var dribbbleApi = require('dribbble-api')

var dribbble = new dribbbleApi()

dribbble.list('debuts', function(err, res, json, paging) { })

Every callback gets four arguments; An error (if there is one), the HTTP response, a JSON object (probably what you will want) and a paging object (more on this in the paging section).

Player

All of the player-related functions require a player id (or username).

Player Profile

dribbble.player('44656', function(err, res, json, paging) {
	console.log(json)
})

A Player's Shots

dribbble.playerShots('44656', function(err, res, json, paging) {
	console.log(json)	// json.shots
})

Shots by Users Player is Following

dribbble.playerFollowingShots('44656', function(err, res, json, paging) {
	console.log(json)	// json.shots
})

Shots Liked by Player

dribbble.playerLikes('44656', function(err, res, json, paging) {
	console.log(json)	// json.shots
})

Users that Follow the Player

dribbble.playerFollowers('44656', function(err, res, json, paging) {
	console.log(json)	// json.players
})

Users that the Player Follows

dribbble.playerFollows('44656', function(err, res, json, paging) {
	console.log(json)	// json.players
})

Users Drafted by the Player

dribbble.playerDraftees('44656', function(err, res, json, paging) {
	console.log(json)	// json.players
})

Shots

All of the shot-related functions, except for list, require a shot id.

An Individual Shot's Profile

dribbble.shot('300230', function(err, res, json, paging) {
	console.log(json)
})

Rebounds of a Shot

dribbble.shotRebounds('43424', function(err, res, json, paging) {
	console.log(json) 	// json.shots
})

Comments on a Shot

dribbble.shotComments('43424', function(err, res, json, paging) {
	console.log(json) 	// json.comments
})

Lists of Shots

This one is a bit different. It doesn't take a shot id. Instead it takes the name of a list.

Possible names are popular, debuts and everyone.

If you don't pass a list name it will default to popular.

dribbble.list('popular', function(err, res, json, paging) {
	console.log(json) 	// json.shots
})

// has the same effect as

dribbble.list(function(err, res, json, paging) {
	console.log(json) 	// json.shots
})

Options

Dribbble allows for options to be set. You can set these by passing your options, as an {} object, just before the callback.

dribbble.lists('debuts', { per_page: 30, page: 5 }, function(err, res, json, paging) { })

Paging

The paging object returned to the callbacks may contain a next or previous function. These functions allow you to make another request, using the same arguments passed before, but with a new callback.

Here's an example where we request as many pages as we can, from the 'popular list', and add all resulting shots to the popularShots array. Once this is done we'll call onRequestsFinished.

var popularShots = []

var onRequestsFinished = function() {
	// do something
}

var requestCallback = function(err, res, json, paging) {
	if (Array.isArray(json.shots)) {
		popularShots = popularShots.concat(json.shots)
	}

	if (paging.next) {
		paging.next(requestCallback)
	}
	else {
		onRequestsFinished()
	}
}

dribbble.list('popular', requestCallback)

Future Plans