Permalink
Browse files

First version

  • Loading branch information...
judofyr committed May 28, 2009
0 parents commit 5c19708aa3de308cd70fbf2933efaea2c9ac1f82
43 COPYING
@@ -0,0 +1,43 @@
+
+ Potion is free software, released under an MIT license -- the very
+ brief paragraphs below. There is satisfaction simply in having
+ created this. Please use this how you may, even in commercial or
+ academic software. I've had a good time and am want for nothing.
+
+ ~
+
+ Copyright (c) 2008 why the lucky stiff
+
+ HOWEVER:
+ Be it known, parts of the object model taken from obj.c
+ (c) 2007 Ian Piumarta
+ <http://www.piumarta.com/software/id-objmodel/> (MIT licensed)
+ And, also, the design of the VM bytecode is from Lua
+ (c) 1994-2006 Lua.org, PUC-Rio
+ <http://lua.org/license.html> (MIT licensed)
+ <http://luaforge.net/docman/view.php/83/98/ANoFrillsIntroToLua51VMInstructions.pdf>
+ Lastly, khash.h
+ (c) 2008, by Attractive Chaos
+ <http://attractivechaos.awardspace.com/khash.h.html> (MIT licensed)
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+ SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
@@ -0,0 +1,212 @@
+GitHub.js
+=========
+
+GitHub.js is a simple library for interacting with GitHub's v2 API.
+
+Quickstart
+----------
+
+ /*
+ * LOADERS
+ */
+
+ var user = new GitHub.User('judofyr');
+
+ // Let's load some data:
+ user.load('basic')
+
+ // That command is async, so let's add a callback too:
+ // (since basic already has been loaded,
+ // this would not make any calls to GitHub)
+ user.load('basic', function(obj) {
+ user == obj; // The object itself is passed to the callback,
+ // so you can easily pass in a normal function.
+
+ user.name; // Now our object has many properties (see API below)
+ });
+
+ // You can give it multiple loaders too:
+ user.load('basic', 'followers');
+ user.load('basic', 'following', callback);
+
+ // The loader defaults to 'basic':
+ user.load() // equals to user.load('basic')
+ user.load(callback) // equals to user.load('basic', callback)
+
+ // More stuff
+ user.isLoaded('basic') == true
+ user.reload('basic') // Load basic again
+
+ /*
+ * FETCHERS
+ */
+
+ var repo = user.repo('something');
+
+ // Let's load the issues:
+ repo.issues('open', function(issues) {
+ repo != issues; // Now issues is a completely different object.
+ });
+
+ // If we fetch them again, it will cause a new call to GitHub:
+ repo.issues('open', callback);
+
+Use
+---
+
+Run `rake build` and you'll get two versions:
+
+* github.only.js, which depends on JS.Class being loaded already
+* github.js, which already includes JS.Class
+
+Read the quickstart at the top, the API at the bottom and take a look at examples/
+
+Use the fork, Luke
+------------------
+
+I've used the excellent [JS.Class](http://jsclass.jcoglan.com/) which fakes Ruby's object model in JavaScript. It allowed me to quickly build this and get something working pretty well. The goal is however to *not* have any other dependencies and make it so idomatic JavaScript as possible.
+
+I would be very grateful if someone could take a look at the code and point out all my silly mistakes. This applies to everything, both the frontend API which you'll be using and the backend code which handles API calls. Fork away, don't be afraid of refactoring and deleting my code, and I'll merge your changes right away!
+
+Magnus Holm <judofyr@gmail.com>
+
+---
+
+API
+---
+
+### GitHub.User
+
+ var user = new GitHub.User(login);
+
+ user.load(function() {
+ user.company;
+ user.name;
+ user.following_count;
+ user.blog;
+ user.public_repo_count;
+ user.public_gist_count;
+ user.id;
+ user.login;
+ user.followers_count;
+ user.created_at;
+ user.email;
+ user.location;
+ });
+
+ user.load('followers', 'following', function() {
+ user.followers;
+ user.following;
+ });
+
+ user.load('repos', function() {
+ user.repos; // => [GitHub.Repo]
+ });
+
+ user.repo(project) // => GitHub.Repo
+ // Preloaded if you've already loaded repos
+
+### GitHub.Repo
+
+ var repo = new GitHub.Repo(owner, name);
+
+ repo.load(function() {
+ repo.name;
+ repo.watchers;
+ repo.private;
+ repo.url;
+ repo.fork;
+ repo.forks;
+ repo.description;
+ repo.homepage;
+ repo.owner;
+ });
+
+ repo.load('tags', 'branches', function() {
+ repo.tags; // { name: sha }
+ repo.branches // { name: sha }
+ });
+
+ repo.tree(sha) // GitHub.Tree
+
+ repo.issues('open' OR 'closed', function(issues) {
+ issues; // [GitHub.Issue]
+ });
+
+ repo.issue(number) // GitHub.Issue
+
+ repo.commits(branch, function(commits) {
+ commits; // [GitHub.Commit]
+ });
+
+ repo.commits(branch, filename, function(commits) {
+ commits; // [GitHub.Commit]
+ });
+
+ repo.commit(number) // GitHub.Commit
+
+### GitHub.Issue
+
+ var issue = new GitHub.Issue(repo, number); // Please use repo.issue(number)
+
+ issue.load(function() {
+ issue.user;
+ issue.updated_at;
+ issue.votes;
+ issue.number;
+ issue.title;
+ issue.body;
+ issue.position;
+ issue.state;
+ issue.created_at;
+ });
+
+### GitHub.Commit
+
+ var commit = new GitHub.Commit(repo, sha); // Please use repo.commit(sha)
+
+ commit.load(function() {
+ commit.message;
+ commit.parents;
+ commit.author;
+ commit.url;
+ commit.id;
+ commit.committed_date;
+ commit.authored_date;
+ commit.tree;
+ commit.committer;
+ });
+
+ commit.load('detailed', function() {
+ commit.added;
+ commit.removed;
+ commit.modified;
+ });
+
+### GitHub.Tree
+
+ var tree = new GitHub.Tree(repo, sha); // Please use repo.tree(sha)
+
+ tree.load(function() {
+ tree.children; // [GitHub.Tree OR GitHub.Blob]
+
+ var child = tree.children[0];
+
+ child.name;
+ child.sha;
+ child.mode;
+ child.type;
+ });
+
+### GitHub.Blob
+
+ var blob = new GitHub.Blob(tree, filename);
+
+ blob.load(function() {
+ blob.name;
+ blob.sha;
+ blob.size;
+ blob.mode;
+ blob.mime_type;
+ blob.data;
+ })
@@ -0,0 +1,5 @@
+task :build do
+ mkdir_p 'build'
+ sh "ruby vendor/jsmin.rb < src/github.js > build/github.only.js"
+ sh "cat vendor/jsclass/class.js src/github.js | ruby vendor/jsmin.rb > build/github.js"
+end
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>GitHub Browser</title>
+ <!-- Combo-handled YUI CSS files: -->
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.7.0/build/treeview/assets/skins/sam/treeview.css">
+ <!-- Combo-handled YUI JS files: -->
+ <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.7.0/build/yahoo-dom-event/yahoo-dom-event.js&2.7.0/build/treeview/treeview-min.js"></script>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+ <script type="text/javascript" src="../deps/jsclass.js"></script>
+ <script type="text/javascript" src="../src/github.js"></script>
+ <script type="text/javascript">
+ $(function(){
+ $('form').submit(function(){
+ $('#user').text('Loading...');
+ $('#file').text('');
+ $('#tree').text('');
+ var user = new GitHub.User($('#username').attr('value'));
+ user.load('basic', showUser);
+ return false;
+ });
+ });
+
+ function showUser(user) {
+ var box = $('#user');
+ box.text('Welcome ' + user.name + '. Here are your repos:');
+ $('#tree').text('Loading...');
+ user.load('repos', showRepos);
+ }
+
+ function showRepos(user) {
+ var tree = new YAHOO.widget.TreeView("tree");
+ tree.setDynamicLoad(loadLeaves);
+ tree.subscribe('clickEvent', clicked);
+ var root = tree.getRoot();
+
+ for (var i in user.repos) {
+ var repo = user.repos[i];
+ var node = new YAHOO.widget.TextNode(repo.name, root, false);
+ // Store the object in the node
+ $(node).data('object', repo);
+ }
+
+ tree.draw();
+ }
+
+ function clicked(thing) {
+ var object = $(thing.node).data('object');
+
+ // Load the file if it's a blob
+ if (object.isA(GitHub.Blob)) {
+ $('#file').text('Loading...');
+ object.load(function() {
+ $('#file').text(object.data);
+ });
+ }
+ }
+
+ function loadLeaves(node, completed) {
+ var object = $(node).data('object');
+
+ // If it's a repo, load the branches
+ if (object.isA(GitHub.Repo)) {
+ object.load('branches', function(){
+ for (var i in object.branches) {
+ var tree = object.tree(object.branches[i]);
+ var child = new YAHOO.widget.TextNode(i, node, false);
+ $(child).data('object', tree);
+ }
+ completed();
+ });
+ // If it's a tree, load the children
+ } else if (object.isA(GitHub.Tree)) {
+ object.load(function() {
+ for (var i in object.children) {
+ var tree = object.children[i];
+ var child = new YAHOO.widget.TextNode(tree.name, node, false);
+ $(child).data('object', tree);
+ if (tree.type == 'blob') {
+ child.isLeaf = true;
+ }
+ }
+ completed();
+ });
+ }
+ }
+ </script>
+</head>
+<body>
+ <form>
+ Username: <input type="text" id="username">
+ <input type="submit" value="Fetch info">
+ </form>
+ <div id="user"></div>
+ <div id="tree"></div>
+ <pre id="file"></pre>
+</body>
+</html>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 5c19708

Please sign in to comment.