Created
May 2, 2012 19:45
-
-
Save fehmicansaglam/2579695 to your computer and use it in GitHub Desktop.
Twitter takipçi grafı
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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