Home

Awesome

Karmacracy API Javascript

Package Quality Build Status Dependency Status devDependency Status

A Javascript wrapper for Karmacracy API. You can check the official documentation

If you want to try the tool, here you are an invitation

Installation

You can use it in client-side and also in server-side

Client-side

You can add it as bower dependency:

bower install --save karmacracy-javascript-api

Server-side

You can install it using npm:

npm install --save karmacracy-javascript-api

Initialize

Before start to develop an app or web using Karmacracy you need an API_key.

Runing Karmacracy API in the Client

var kcy = new Karmacracy(API_key, 'es');

Runing Karmacracy API in the Server (NodeJS)

You need to add the dependence in the pacjage.json. Check the NPM module page

"dependences": {
	"karmacracy-javascript-api": "*"
}

And you can use it as module:

var karmacracy = require('karmacracy-javascript-api');
var kcy = new karmacracy(API_key, 'es');

Setup the user (client and server)

The first thing the user of your app will need to give you the userName and userKey (The user can find it in Preferences > Conexions at karmacracy).

kcy.setUserName('userName');
kcy.setUserKey('userKey');

If you want to do this in one simple line

kcy.setUser('userName', 'userKey');

Methods

setLang

You can change the lang of the response using this function. The response of following request will be in the new language

kcy.setLang('es');

setUserName

You can change the userName for the request. Remember that you have to change the userKey too.

kcy.setUserName('jorgecasar');

setUserKey

You can change the userKey for the request. Remember that you have to change the userName too.

kcy.setUserKey('ia7odp8fvdof');

setUser

This is a shortcut to change UserName and UserKey at once. You need give the parameters userName and userKey.

kcy.setUser('jorgecasar', 'ia7odp8fvdof');

getKey

You can recover the key asking for the user's name and password.

kcy.getKey({
	u: 'jorgecasar',
	p: 'jorgecasarPassword'
}, callback);

The callback follow the nodeJS convention reserving the first parameter of the callback for an optional error object. If all went well you receive an object like this as second parameter:

{error: 0, key: 'userKey'}

getNewKey

You can regenerate the userKey of the user asking for the user's name and password.

kcy.getNewKey({
	u: 'jorgecasar',
	p: 'jorgecasarPassword'
}, callback);

The callback follow the nodeJS convention reserving the first parameter of the callback for an optional error object. If all went well you receive an object like this as second parameter:

{error: 0, key: 'userNewKey'}

checkKey

Allows to know whether the user and the key (third key) entered by the user are valids.

kcy.checkKey({
	k: 'userKey'
}, callback);

The callback follow the nodeJS convention reserving the first parameter of the callback for an optional error object. If all went well you receive an object like this as second parameter: {ok: 1} In the other case, if it's not correct: {ok: 0}

getUserInfo

Return user details and a list of his kcys.

kcy.getUserInfo(callback);	
kcy.getUserInfo({u: 'jorgecasar'}, callback);

If the user does't exist you get an error 404. In the other case you get an object with the user info as second parameter:

{
	"username": "jorgecasar",
	"kcyrank": "40",
	"img": "http://gravatar.com/avatar/b374f3bd05b1db4a974585ba57661815/?s=85",
	"level": "3",
	"date_signed": "2012-10-28 17:20:32",
	"stats": [],
	"kcys": []
}

getNuts

Return an array with all user's nuts

kcy.getNuts(callback);	
kcy.getNuts({u: 'jorgecasar'}, callback);

If all was right you get an array like this as second parameter:

[{
	"id": "140",
	"name": "Creator 10",
	"imageSmall": "http://karmacracy.com/img-nuts/0b4beab1b0b6b273ae0ca0818b1b0d1a833edf38.png",
	"imageBig": "http://karmacracy.com/img-nuts/3d1c89f69382216508cdeb2a685a85336cd9d651.png",
	"level": "1",
	"dateReceivedOrLast": "2013-06-24",
	"number": "1"
},{
	…
}]

getNut

Return detailed information and URLs of the nut (achievement) of the user.

kcy.getNut({
	n: '140'
}, callback);

kcy.getNut({
	u: 'jorgecasar',
	n: '140'
}, callback);

If all was right you get an object like this as second parameter:

{
	"id": "140",
	"name": "Creator 10",
	"dateSince": "2012-09-03",
	"history": "This nut was proposed by <a href=\"/kcy\">kcy</a>. It was created on 03 sep 2012.",
	"imageSmall": "http://karmacracy.com/img-nuts/0b4beab1b0b6b273ae0ca0818b1b0d1a833edf38.png",
	"imageBig": "http://karmacracy.com/img-nuts/3d1c89f69382216508cdeb2a685a85336cd9d651.png",
	"description": "Life is a game and so is Karmacracy. We want you to keep having fun with us so we give you this Nut because you have shared 10 new kcys (new links in Karmacracy). Use this Cinexin to rekindle the moment.",
	"flg_type": "H",
	"level": "1",
	"nrKcys": "0",
	"nrMyKcys": "0",
	"nrHumans": "2707",
	"humans": [{…}]
}

getNetworks

This method return an array with all user's networks

kcy.getNetworks(callback);
kcy.getNetworks({ u: 'jorgecasar' }, callback);

If all was right you get an array like this as second parameter:

[{
	"connectid": "connectID",
	"hidden": "0",
	"name": "Jorge del Casar",
	"type": "FB"
},{
	…
}}

getFacebookPages

Return an array with all Facebook Pages that the user is admin.

kcy.getFacebookPages(callback);

If all was right you get an array like this as second parameter:

[{
	"access_token": "ACCESS_TOKEN",
	"id": "FACEBOOK_PAGE_ID",
	"name": "Jorge del Casar - Desarrollo Frontend"
},{
	…
}]

getDomains

Returns the list of user's domains ranking ordered by the user within the domain.

kcy.getDomains(callback);
kcy.getDomains({u:'jorgecasar'}, callback);

If all was right you get an array like this as second parameter:

[{
	"clicks": "246",
	"domain": "developer.blackberry.com",
	"numPersonas": "5",
	"rank": "1"
},{
	…
}]

getKcys

Allows you to view, search and explore all kcys in Karmacracy.com.

kcy.getKcys(callback);
kcy.getKcys({u:'jorgecasar'}, callback);

If all was right you get an array like this as second parameter:

[{
	"id": "qt36",
	"url": "http://www.eldiario.es/turing/Socializando-enlaces-contenidos-Karmacracy_0_169383125.html",
	"title": "Socializando enlaces y contenidos con Karmacracy",
	"description": "&nbsp;Entrevistamos a Álex Dolara, fundador de Karmacracy, una startup española, dedicada a compartir contenidos y acortar enlaces con una capa social.",
	"imgUser": "http://karmacracy.com/img/kcylocke.png",
	"image": "http://images.eldiario.es/turing/Alex-Dolara_EDIIMA20130828_0074_6.jpg",
	"time": "2013-08-29 07:32:21",
	"user": "agileando",
	"clicks": "205",
	"weight": "205",
	"people": […]
},{
	…
}]

getKcy

Get a kcy detailed information, statistics and human trafficking that have shared.

kcy.getKcys({kcy:'qt36'}, callback);

If all was right you get an object like this as second parameter:

{
	"shorturl": "qt36",
	"url": "http://www.eldiario.es/turing/Socializando-enlaces-contenidos-Karmacracy_0_169383125.html",
	"date": "2013-08-29 07:32:21",
	"kcyedhumans": {…},
	"kclicks": null,
	"mykclicks": "17",
	"mykcytype": "2",
	"traffic": {…}
}

getRank

View and explore the global and instantaneous kcyrank.

kcy.getRank(callback);
// Get the instantaneous rank from position 40th.
kcy.getRank({
	now:1,
	from:40
}, callback);

If all was right you get an array like this as second parameter:

[{
	"username": "elandroidelibre",
	"kcyrank": "1",
	"img": "http://karmacracy.com/img-users/114.jpg",
	"totalawards": "9384"
},{
	…
}]

getStatsEvolution

Returns the statistics of the evolution of a user in the last 30 days.

kcy.getStatsEvolution(callback);

If all was right you get an object like this as second parameter:

{

	"links_evolution": {…},
	"koi_evolution": {…},
	"rank_evolution": {…},
	"clicks_evolution": {…},
	"virgin_vs_burned": {
		"virgin": "128",
		"total": "154",
		"burned": 26
	},
	"kclicks": "4357.64",
	"kcys": "118"
}

getStatsRelevance

Returns the statistics of the relevance of a user in the last 30 days (default), 7 days or 24 hours.

kcy.getStatsRelevance(callback);

If all was right you get an object like this as second parameter:

{
	"hours": {…},
	"kclicks": "4357.64",
	"kcys": "118",
	"koi": 36.929152542373,
	"social": {…},
	"week": {…}
}

shortLink

You can short a link using kcy.me, the Karmacracy.com shortener.

kcy.shortLink({url: 'http://karmacracy.com'}, callback);

If all was right you get an object like this as second parameter:

{
	"long_url": "http://karmacracy.com",
	"url": "http://kcy.me/nlr8",
	"hash": null,
	"global_hash": null,
	"new_hash": 0
}

shareKcy

Share a kcy through user networks. Before use it you have to short it and get the user's networks.

kcy.shareKcy({
	txt: 'Text to send to the social network of choice.',
	kcy: 'nlr8',
	// Network identifier, composed as follows:
	// RR_IDCONNECT, being 'RR' property 'type' network, and being IDCONNECT property 'connectid'.
	where: 'RR_IDCONNECT'
}, callback);

If all was right you get an object like this as second parameter:

{"result": "0"} 

getFirewords

Gets the list of the firewords on the Karmacracy portal:

kcy.getFirewords({ 
	num: '30' //number of firewords to get
},
 callback);

If all was right you get an object like this as second parameter:

"word": [
    [
        "celebro",
        "10",
        "1",
        "10.0000"
    ],
]