Skip to content

Commit 7d9710a

Browse files
committed
Demo github user:email, MrSwitch#366
1 parent c691e3e commit 7d9710a

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

demos/github.html

+44-14
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,54 @@
1111
<title>hello( github )</title>
1212
<h1>hello( github )</h1>
1313

14-
<button id='github' onclick="login('github');">github</button>
15-
<pre id="result">Signin to get a list of repos</pre>
14+
<button id='github' onclick="profile('github');">Get Profile</button>
1615
<script class="pre">
17-
function login(network){
18-
16+
function profile(network) {
1917
var github = hello(network);
20-
2118
github.login().then(function() {
22-
2319
// get user profile data
24-
github.api('me').then(function(p) {
25-
document.getElementById(network).innerHTML = "<img src='"+ p.thumbnail + "' width=24/>Connected to "+ network +" as " + p.name;
26-
});
20+
return github.api('me');
21+
})
22+
.then(function(p) {
23+
document.getElementById(network).innerHTML = "<img src='"+ p.thumbnail + "' width=24/>Connected to "+ network +" as " + p.name;
24+
});
25+
}
26+
</script>
27+
28+
<h2>Get user email</h2>
29+
30+
<button onclick="userEmail('github', 'email');">Get email</button>
31+
32+
<pre id="email"></pre>
33+
<script class="pre">
34+
function userEmail(network, target) {
35+
var github = hello(network)
36+
github.login({
37+
scope:'email'
38+
})
39+
.then(function() {
40+
// Get a bespoke endpoint from github
41+
return github.api('/user/emails');
42+
}).then(function(r) {
43+
document.getElementById(target).innerHTML = JSON.stringify(r, null, 2);
44+
});
45+
}
46+
</script>
2747

48+
<h2>List user repos</h2>
49+
50+
<button onclick="userRepos('github', 'repo_list');">Get a list of repos</button>
51+
52+
<pre id="repo_list"></pre>
53+
<script class="pre">
54+
function userRepos(network, target) {
55+
var github = hello(network)
56+
github.login()
57+
.then(function() {
2858
// Get a bespoke endpoint from github
29-
github.api('/user/repos').then(function(r) {
30-
document.getElementById('result').innerHTML = JSON.stringify(r,null,2);
31-
});
59+
return github.api('/user/repos');
60+
}).then(function(r) {
61+
document.getElementById(target).innerHTML = JSON.stringify(r, null, 2);
3262
});
3363
}
3464
</script>
@@ -38,6 +68,6 @@ <h1>hello( github )</h1>
3868
github : GITHUB_CLIENT_ID
3969
},{
4070
redirect_uri : '../redirect.html',
41-
oauth_proxy : OAUTH_PROXY_URL
71+
// oauth_proxy : OAUTH_PROXY_URL
4272
});
43-
</script>
73+
</script>

0 commit comments

Comments
 (0)