Created
May 25, 2012 01:11
-
-
Save benmills/2785218 to your computer and use it in GitHub Desktop.
This file contains 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
// Example | |
var GitGoggles = { | |
getRepositories: function (callback) { | |
this._get('repositories', callback); | |
}, | |
getRepository: function (repoName, callback) { | |
this._get('repository/'+repoName, callback); | |
}, | |
_rootUrl: 'http://localhost:9292/', | |
_get: function (path, callback) { | |
$.getJSON(this._rootUrl+path+'?callback=?', callback); | |
} | |
}; | |
// Usage example | |
$(function () { | |
GitGoggles.getRepositories(function (response) { | |
for (i in response.repositories) { | |
console.log('Repo '+i+': '+response.repositories[i]); | |
} | |
}); | |
//=> Repo 0: foo | |
GitGoggles.getRepository('foo', function (repo) { | |
for (key in repo) { | |
console.log(key+": "+repo[key]); | |
} | |
}); | |
//=> name: foo | |
//=> branches: master | |
}); |
This file contains 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 GitGoggles = function (rootHost, rootPort) { | |
this._get = function (path, callback) { | |
$.getJSON('http://'+rootHost+':'+rootPort+'/'+path+'?callback=?', callback); | |
}; | |
this.getRepositories = function (callback) { | |
this._get('repositories', callback); | |
}; | |
this.getRepository = function (repoName, callback) { | |
this._get('repository/'+repoName, callback); | |
}; | |
}; | |
// Usage example | |
$(function () { | |
var gitGoggles = new GitGoggles('localhost', '9292'); | |
gitGoggles.getRepositories(function (response) { | |
for (i in response.repositories) { | |
console.log('Repo '+i+': '+response.repositories[i]); | |
} | |
}); | |
//=> Repo 0: foo | |
gitGoggles.getRepository('foo', function (repo) { | |
for (key in repo) { | |
console.log(key+": "+repo[key]); | |
} | |
}); | |
//=> name: foo | |
//=> branches: master | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment