Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 212 lines (157 sloc) 5.272 kb
5c19708 Magnus Holm First version
authored
1 GitHub.js
2 =========
3
4 GitHub.js is a simple library for interacting with GitHub's v2 API.
5
6 Quickstart
7 ----------
8
9 /*
10 * LOADERS
11 */
12
13 var user = new GitHub.User('judofyr');
14
15 // Let's load some data:
16 user.load('basic')
17
18 // That command is async, so let's add a callback too:
19 // (since basic already has been loaded,
20 // this would not make any calls to GitHub)
21 user.load('basic', function(obj) {
22 user == obj; // The object itself is passed to the callback,
23 // so you can easily pass in a normal function.
24
25 user.name; // Now our object has many properties (see API below)
26 });
27
28 // You can give it multiple loaders too:
29 user.load('basic', 'followers');
30 user.load('basic', 'following', callback);
31
32 // The loader defaults to 'basic':
33 user.load() // equals to user.load('basic')
34 user.load(callback) // equals to user.load('basic', callback)
35
36 // More stuff
37 user.isLoaded('basic') == true
38 user.reload('basic') // Load basic again
39
40 /*
41 * FETCHERS
42 */
43
44 var repo = user.repo('something');
45
46 // Let's load the issues:
47 repo.issues('open', function(issues) {
48 repo != issues; // Now issues is a completely different object.
49 });
50
51 // If we fetch them again, it will cause a new call to GitHub:
52 repo.issues('open', callback);
53
54 Use
55 ---
56
57 Run `rake build` and you'll get two versions:
58
59 * github.only.js, which depends on JS.Class being loaded already
60 * github.js, which already includes JS.Class
61
62 Read the quickstart at the top, the API at the bottom and take a look at examples/
63
64 Use the fork, Luke
65 ------------------
66
67 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.
68
69 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!
70
71 Magnus Holm <judofyr@gmail.com>
72
73 ---
74
75 API
76 ---
77
78 ### GitHub.User
79
80 var user = new GitHub.User(login);
81
82 user.load(function() {
83 user.company;
84 user.name;
85 user.following_count;
86 user.blog;
87 user.public_repo_count;
88 user.public_gist_count;
89 user.id;
90 user.login;
91 user.followers_count;
92 user.created_at;
93 user.email;
94 user.location;
95 });
96
97 user.load('followers', 'following', function() {
98 user.followers;
99 user.following;
100 });
101
102 user.load('repos', function() {
103 user.repos; // => [GitHub.Repo]
104 });
105
106 user.repo(project) // => GitHub.Repo
107 // Preloaded if you've already loaded repos
108
109 ### GitHub.Repo
110
111 var repo = new GitHub.Repo(owner, name);
112
113 repo.load(function() {
114 repo.name;
115 repo.watchers;
116 repo.private;
117 repo.url;
118 repo.fork;
119 repo.forks;
120 repo.description;
121 repo.homepage;
122 repo.owner;
123 });
124
125 repo.load('tags', 'branches', function() {
126 repo.tags; // { name: sha }
127 repo.branches // { name: sha }
128 });
129
130 repo.tree(sha) // GitHub.Tree
131
132 repo.issues('open' OR 'closed', function(issues) {
133 issues; // [GitHub.Issue]
134 });
135
136 repo.issue(number) // GitHub.Issue
137
138 repo.commits(branch, function(commits) {
139 commits; // [GitHub.Commit]
140 });
141
142 repo.commits(branch, filename, function(commits) {
143 commits; // [GitHub.Commit]
144 });
145
146 repo.commit(number) // GitHub.Commit
147
148 ### GitHub.Issue
149
150 var issue = new GitHub.Issue(repo, number); // Please use repo.issue(number)
151
152 issue.load(function() {
153 issue.user;
154 issue.updated_at;
155 issue.votes;
156 issue.number;
157 issue.title;
158 issue.body;
159 issue.position;
160 issue.state;
161 issue.created_at;
162 });
163
164 ### GitHub.Commit
165
166 var commit = new GitHub.Commit(repo, sha); // Please use repo.commit(sha)
167
168 commit.load(function() {
169 commit.message;
170 commit.parents;
171 commit.author;
172 commit.url;
173 commit.id;
174 commit.committed_date;
175 commit.authored_date;
176 commit.tree;
177 commit.committer;
178 });
179
180 commit.load('detailed', function() {
181 commit.added;
182 commit.removed;
183 commit.modified;
184 });
185
186 ### GitHub.Tree
187
188 var tree = new GitHub.Tree(repo, sha); // Please use repo.tree(sha)
189
190 tree.load(function() {
191 tree.children; // [GitHub.Tree OR GitHub.Blob]
192
193 var child = tree.children[0];
194
195 child.name;
196 child.sha;
197 child.mode;
198 child.type;
199 });
200
201 ### GitHub.Blob
202
203 var blob = new GitHub.Blob(tree, filename);
204
205 blob.load(function() {
206 blob.name;
207 blob.sha;
208 blob.size;
209 blob.mode;
210 blob.mime_type;
211 blob.data;
212 })
Something went wrong with that request. Please try again.