Skip to content

Instantly share code, notes, and snippets.

@fehmicansaglam
Created May 2, 2012 19:45
Show Gist options
  • Save fehmicansaglam/2579695 to your computer and use it in GitHub Desktop.
Save fehmicansaglam/2579695 to your computer and use it in GitHub Desktop.
Twitter takipçi grafı
var createNode = function(data){
return $.ajax({
type: 'POST',
url: 'http://localhost:7474/db/data/index/node/people?unique',
data: data,
contentType: 'application/json',
dataType: 'json'
});
}
var createRelationship = function(from, to, type){
console.log('creating relationship: ' + from + ' ' + type + ' ' + to);
return $.ajax({
type: 'POST',
url: from + '/relationships',
data: {
to: to,
type: type
},
dataType: 'json',
async: false
});
}
var getFollowersIds = function(userId){
return $.ajax({
type: 'GET',
url: 'http://api.twitter.com/1/followers/ids.json?user_id=' + userId,
dataType: 'jsonp'
});
}
var retreiveAndSave = function(userId){
createNode('{"key": "id", "value": "' + userId + '", "properties": {"id": "' + userId + '"} }')
.done(function(data, message, jqxhr){
var nodeTo = data.self;
getFollowersIds(userId).done(function(data){
$.each(data.ids, function(index, follower){
createNode('{"key": "id", "value": "' + follower + '", "properties": {"id": "' + follower + '"} }')
.done(function(data, message, jqxhr){
var nodeFrom = data.self;
createRelationship(nodeFrom, nodeTo, 'FOLLOWS');
if(jqxhr.status === 201){
console.log(follower + ' is created');
retreiveAndSave(follower);
} else if(jqxhr.status === 200){
console.log(follower + ' exists');
}
});
});
});
});
}
retreiveAndSave(36611939);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment