Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2cc88fd

Browse filesBrowse files
committed
working on auth to get rate limit up
1 parent 9640aea commit 2cc88fd
Copy full SHA for 2cc88fd

File tree

Expand file treeCollapse file tree

3 files changed

+63
-104
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+63
-104
lines changed

‎githubconsole.html

Copy file name to clipboardExpand all lines: githubconsole.html
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ <h2>Try out the Console</h2>
4747
<div>Type <code>help</code> or hit <code>TAB</code> for a list of commands.</div>
4848
<div id="shell-view"></div>
4949
</div>
50+
<div>Github rate limit: <span id="ratelimit"></span></div>
5051
</section>
5152
</div>
5253
<!--[if !IE]>

‎javascripts/githubconsole.js

Copy file name to clipboardExpand all lines: javascripts/githubconsole.js
+62-34Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
};
2222
var _shell = Josh.Shell({console: _console});
2323
var _pathhandler = new Josh.PathHandler(_shell, {console: _console});
24+
var _rateLimitTemplate = _.template("<%=remaining%>/<%=limit%><% if(noAuthToken) {%> <a href='http://josh.claassen.net/github'>Authenticate with Github to increase your Rate Limit.</a><%}%>");
2425
var _self = {
25-
api: "https://api.github.com/",
26+
api: "https://api.github.com/"
2627
};
2728
_shell.templates.repos = _.template("<ul class='widelist'><% _.each(repos, function(repo) { %><li><%- repo.name %></li><% }); %></ul>");
2829
_shell.templates.prompt = _.template("<em>[<%= self.user.login %>/<%= self.repo.name %>]</em></br>(<%=self.branch%>) <strong><%= node.path %> $</strong>");
@@ -58,24 +59,50 @@
5859
});
5960

6061
function getRepos(callback) {
61-
var uri = _self.api + "users/" + _self.user.login + "/repos?callback=?";
62-
_console.log("fetching: " + uri);
63-
return $.getJSON(uri, function(response) {
64-
checkRateLimit(response.meta);
65-
_self.repos = response.data;
62+
return get("users/" + _self.user.login + "/repos", null, function(data) {
63+
_self.repos = data;
6664
callback();
6765
});
6866
}
6967

68+
function get(resource, args, callback) {
69+
var url = _self.api + resource;
70+
if(_self.access_token) {
71+
args = args || {};
72+
args.access_token = _self.access_token;
73+
}
74+
if(args) {
75+
url += "?" + _.map(args,function(v, k) {
76+
return k + "=" + v;
77+
}).join("&");
78+
}
79+
_console.log("fetching: " + url);
80+
var request = {
81+
url: url,
82+
dataType: 'jsonp'
83+
};
84+
$.ajax(request).done(function(response) {
85+
_console.log(response.meta);
86+
$('#ratelimit').html(_rateLimitTemplate({
87+
remaining: response.meta["X-RateLimit-Remaining"],
88+
limit: response.meta["X-RateLimit-Limit"],
89+
noAuthToken: !_self.access_token
90+
}));
91+
if(response.meta["X-RateLimit-Remaining"] == 0) {
92+
alert("Whoops, you've hit the github rate limit. You'll need to authenticate to continue");
93+
_shell.deactivate();
94+
return;
95+
}
96+
callback(response.data);
97+
})
98+
}
99+
70100
function setUser(user, repo, callback) {
71101
if(_self.user && _self.user.login === user) {
72102
return callback();
73103
}
74-
var uri = _self.api + "users/" + user + "?callback=?";
75-
_console.log("fetching: " + uri);
76-
return $.getJSON(uri, function(response) {
77-
checkRateLimit(response.meta);
78-
_self.user = response.data;
104+
return get("users/" + user, null, function(data) {
105+
_self.user = data;
79106
getRepos(function() {
80107
setRepo(repo, function() {
81108
callback();
@@ -84,24 +111,13 @@
84111
});
85112
}
86113

87-
function checkRateLimit(meta) {
88-
_console.log(response.meta);
89-
if(response.meta["X-RateLimit-Remaining"] == 0) {
90-
alert("Whoops, you've hit the github rate limit. You'll need to authenticate to continue");
91-
}
92-
_shell.deactivate();
93-
}
94-
95114
function getDir(path, callback) {
96-
if(path && path.length > 1 && path[path.length-1] === '/') {
97-
path = path.substr(0,path.length-1);
115+
if(path && path.length > 1 && path[path.length - 1] === '/') {
116+
path = path.substr(0, path.length - 1);
98117
}
99-
var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?callback=?";
100118
//var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?ref=" + _self.branch + "&callback=?";
101-
_console.log("fetching: " + uri);
102-
$.getJSON(uri, function(response) {
103-
checkRateLimit(response.meta);
104-
if(Object.prototype.toString.call(response.data) !== '[object Array]') {
119+
get("repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path, null, function(data) {
120+
if(Object.prototype.toString.call(data) !== '[object Array]') {
105121
_console.log("path '" + path + "' was a file");
106122
return callback();
107123
}
@@ -110,7 +126,7 @@
110126
return x;
111127
})) || "",
112128
path: path,
113-
children: response.data
129+
children: data
114130
};
115131
_console.log("got node at: " + node.path);
116132
return callback(node);
@@ -200,13 +216,25 @@
200216

201217

202218
$(document).ready(function() {
203-
var $consolePanel = $('#shell-panel');
204-
$consolePanel.resizable({ handles: "s"});
205-
_console.log("initializing 'sdether'");
206-
setUser("sdether", "josh.js", function() {
207-
_console.log("activating");
208-
_shell.activate();
209-
});
219+
$.ajax({
220+
url: 'http://josh.claassen.net/github-token',
221+
type: "get",
222+
dataType: "json",
223+
xhrFields: {
224+
withCredentials: true
225+
}
226+
})
227+
.done(function(data) {
228+
_console.log(data);
229+
_self.access_token = data.access_token;
230+
var $consolePanel = $('#shell-panel');
231+
$consolePanel.resizable({ handles: "s"});
232+
_console.log("initializing 'sdether'");
233+
setUser("sdether", "josh.js", function() {
234+
_console.log("activating");
235+
_shell.activate();
236+
});
237+
});
210238
});
211239
})(root, $, _);
212240
})(this, $, _);

‎stylesheets/styles.css

Copy file name to clipboardExpand all lines: stylesheets/styles.css
-70Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,3 @@
1-
@font-face {
2-
font-family: 'OpenSansLight';
3-
src: url("../fonts/OpenSans-Light-webfont.eot");
4-
src: url("../fonts/OpenSans-Light-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Light-webfont.woff") format("woff"), url("../fonts/OpenSans-Light-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Light-webfont.svg#OpenSansLight") format("svg");
5-
font-weight: normal;
6-
font-style: normal;
7-
}
8-
9-
@font-face {
10-
font-family: 'OpenSansLightItalic';
11-
src: url("../fonts/OpenSans-LightItalic-webfont.eot");
12-
src: url("../fonts/OpenSans-LightItalic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-LightItalic-webfont.woff") format("woff"), url("../fonts/OpenSans-LightItalic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-LightItalic-webfont.svg#OpenSansLightItalic") format("svg");
13-
font-weight: normal;
14-
font-style: normal;
15-
}
16-
17-
@font-face {
18-
font-family: 'OpenSansRegular';
19-
src: url("../fonts/OpenSans-Regular-webfont.eot");
20-
src: url("../fonts/OpenSans-Regular-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Regular-webfont.woff") format("woff"), url("../fonts/OpenSans-Regular-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Regular-webfont.svg#OpenSansRegular") format("svg");
21-
font-weight: normal;
22-
font-style: normal;
23-
-webkit-font-smoothing: antialiased;
24-
}
25-
26-
@font-face {
27-
font-family: 'OpenSansItalic';
28-
src: url("../fonts/OpenSans-Italic-webfont.eot");
29-
src: url("../fonts/OpenSans-Italic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Italic-webfont.woff") format("woff"), url("../fonts/OpenSans-Italic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Italic-webfont.svg#OpenSansItalic") format("svg");
30-
font-weight: normal;
31-
font-style: normal;
32-
-webkit-font-smoothing: antialiased;
33-
}
34-
35-
@font-face {
36-
font-family: 'OpenSansSemibold';
37-
src: url("../fonts/OpenSans-Semibold-webfont.eot");
38-
src: url("../fonts/OpenSans-Semibold-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Semibold-webfont.woff") format("woff"), url("../fonts/OpenSans-Semibold-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Semibold-webfont.svg#OpenSansSemibold") format("svg");
39-
font-weight: normal;
40-
font-style: normal;
41-
-webkit-font-smoothing: antialiased;
42-
}
43-
44-
@font-face {
45-
font-family: 'OpenSansSemiboldItalic';
46-
src: url("../fonts/OpenSans-SemiboldItalic-webfont.eot");
47-
src: url("../fonts/OpenSans-SemiboldItalic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-SemiboldItalic-webfont.woff") format("woff"), url("../fonts/OpenSans-SemiboldItalic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-SemiboldItalic-webfont.svg#OpenSansSemiboldItalic") format("svg");
48-
font-weight: normal;
49-
font-style: normal;
50-
-webkit-font-smoothing: antialiased;
51-
}
52-
53-
@font-face {
54-
font-family: 'OpenSansBold';
55-
src: url("../fonts/OpenSans-Bold-webfont.eot");
56-
src: url("../fonts/OpenSans-Bold-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Bold-webfont.woff") format("woff"), url("../fonts/OpenSans-Bold-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Bold-webfont.svg#OpenSansBold") format("svg");
57-
font-weight: normal;
58-
font-style: normal;
59-
-webkit-font-smoothing: antialiased;
60-
}
61-
62-
@font-face {
63-
font-family: 'OpenSansBoldItalic';
64-
src: url("../fonts/OpenSans-BoldItalic-webfont.eot");
65-
src: url("../fonts/OpenSans-BoldItalic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-BoldItalic-webfont.woff") format("woff"), url("../fonts/OpenSans-BoldItalic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-BoldItalic-webfont.svg#OpenSansBoldItalic") format("svg");
66-
font-weight: normal;
67-
font-style: normal;
68-
-webkit-font-smoothing: antialiased;
69-
}
70-
711
/* normalize.css 2012-02-07T12:37 UTC - http://github.com/necolas/normalize.css */
722
/* =============================================================================
733
HTML5 display definitions

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.