Adobe Behance Portfolio development API’s: node-behance-api

24 / May / 2015 by Deepak Vishwakarma 0 comments

68747470733a2f2f6c68332e676f6f676c6575736572636f6e74656e742e636f6d2f2d4c68766e4c4a333939634d2f56456545566f456a6f58492f41414141414141414179382f456b484a5a57744b6b664d2f773533302d683230372d6e6f2f626568616e63652d6c6f676f2d677265792e706e67 (1)

Behance is an online portfolios website. Here a user can create and see his/her/others portfolios. node-behance-api is an utility wrapper built on node.js for Adobe Behance rest services. This utility is developed for node.js only. Currently it supports most of the API’s of Adobe Behance. You can upgrade or add other new API’s via simply  coding. This node-behance-api is more configurable than any third party module available on node.js.

Before starting development on Behance. You have to register a app on Behance.  For registering your app you just need to follow simple steps. Register your app and get the client id from there.

Working on  node-behance-api is very easy. You just need to require the node-behance-api. And here you go, you are ready to work on Behance 

Requiring the node-behance-api to your nodejs app

[js]

var Behance = require(‘node-behance-api’);

[/js]

Initializing node-behance-api module is very easy. Once you have done with Behance constructor(create a object) , You can initialize  Behance by calling initOptions method. Here below i have attached samples code snippet.

[js]

var Behance = require(‘node-behance-api’);

//Initialize Behance module with your client_id

var behance = new Behance({‘client_id’: ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxx’})
Behance.initOptions();

[/js]

Here Behance.initOptions() is where you initialize node-behance-api. You can further integrate/update this module with other added API’s. We will see example later on.
Calling a simple API let’s say users/{user}

Example:

[js]

var Behance = require("node-behance-api");
var behance = new Behance({"client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"})
Behance.initOptions();
behance.get({
api: Behance.APIS.GET_USER,
params: { //or simply behance.get(‘user’,
user:’deepakmshrma’

}
}, function (error, result) {
if (error)
console.log(error)
else
console.log(result)
});

[/js]

Here Behance.APIS.GET_USER, name of the API which you want to access. There are several API’s available. You can find API’s name in apiNameEnum.js or you can just simply pass string as API’s name here.

List of API’s available right now:

[js]

var ENUM = {
GET_USERS: ‘users’,
GET_USER: ‘user’,
GET_USER_PRODUCT: ‘user_products’,
GET_USER_WIPS: ‘user_wips’,
GET_USER_APR: ‘user_appreciations’,
GET_USER_COLLECTIONS: ‘user_collections’,
GET_USER_STATS: ‘user_stats’,
GET_USER_FOLLOWERS: ‘user_followers’,
GET_USER_FOLLOWEES: ‘user_following’,
GET_USER_FEEDBACK: ‘user_feedback’,
GET_USER_WORK_EXP: ‘user_work_experience’,
GET_PRODUCTS: ‘projects’,
GET_PRODUCT: ‘project’,
GET_PRODUCT_COMMENTS: ‘project_comments’,
GET_COLLECTIONS: ‘collections’,
GET_COLLECTION: ‘collection’,
GET_COLLECTION_PROJECTS: ‘collection_projects’,
GET_WIPS: ‘wips’,
GET_WIP_REVISION: ‘wip_revision’,
GET_WIP_REVISION_COMMENTS: ‘wip_revision_comments’,
GET_WIP: ‘wip’
}

[/js]

Integration of another API’s node-behance-api

Currently this node-behance-api module supports most of the Behance API’s. But in future if you needed you can easily upgrade node-behance-api with other list of API’s. Refer to below given snippet.

[js]

var Behance = require(‘node-behance-api’),
extend = require(‘extend’);
var behance = new Behance({‘client_id’: ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxx’})
Behance.initOptions({
postProcess: function (options) {
var newapis = {
‘newapis’: {
‘name’: ‘newapis’,
‘url’: ‘users’,
‘params’: {
‘client_id’: true,
‘q’: false,
‘sort’: false
}
}
}
options = extend(true, {}, newapis, options);
return options;
}
});
behance
.get({
api: ‘newapis’,
params: {
user: ‘deepakmshrma’
}
}, function (error, result) {
if (error)
console.log(error)
else
console.log(result)
});

[/js]

Here i have used extend  module to extend my previous option with new API details. You can use other third party tool for that.

You can use this initOptions method to add new to the existing API’s or you can simply override current available API by passing same name as it is defined. It will simply override the previous API.

Example:

[js]

Behance.initOptions({
postProcess: function (options) {
var newapis = {
‘users’: {
‘name’: ‘users’,
‘url’: ‘users’,
‘params’: {
‘client_id’: true,
‘q’: false,
‘sort’: false,
‘time’: false,
‘field’: false,
‘country’: false,
‘state’: false,
‘city’: false,
‘page’: false,
‘tags’: false,
‘color_hex’: false,
‘color_range’: false
}
}
}
options = extend(true, {}, newapis, options);
return options;
}
});

[/js]

Error handling with node-behance-api

Error handling with this module is very easy. You can specify the mandatory param with options. If the param value is true. It means it is mandatory for given API’s.

[js]

‘newapi’ : {
‘name’: ‘newapis’,
‘url’: ‘users’,
‘params’: {
‘client_id’: true,
‘q’: false,
‘sort’: false,
‘time’: true,
‘field’: false,
‘country’: false,
‘state’: false,
‘city’: false,
‘page’: false,
‘tags’: false,
‘color_hex’: false,
‘color_range’: false
}
}
//Here param ‘time’ is mandatory for newapi.

[/js]

Hence i tried my best to explain all of the feature of the node-behance-api. You can further visit my Github repository which is https://github.com/deepakshrma/node-behance-api. In case of any issue regarding to node-behance-api. Kindly raise your issue on Github.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *