Skip to content

Instantly share code, notes, and snippets.

@benmills
Created May 25, 2012 01:11
Show Gist options
  • Save benmills/2785218 to your computer and use it in GitHub Desktop.
Save benmills/2785218 to your computer and use it in GitHub Desktop.
// 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
});
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