-
Notifications
You must be signed in to change notification settings - Fork 552
/
Copy pathgithub.js
81 lines (71 loc) · 1.58 KB
/
github.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// GitHub
//
(function(hello){
function formatError(o,headers){
var code = headers ? headers.statusCode : ( o && "meta" in o && "status" in o.meta && o.meta.status );
if( (code===401||code===403) ){
o.error = {
code : "access_denied",
message : o.message || (o.data?o.data.message:"Could not get response")
};
delete o.message;
}
}
function formatUser(o){
if(o.id){
o.thumbnail = o.picture = o.avatar_url;
o.name = o.login;
}
}
function paging(res,headers,req){
if(res.data&&res.data.length&&headers&&headers.Link){
var next = headers.Link.match(/<(.*?)>;\s*rel=\"next\"/);
if(next){
res.paging = {
next : next[1]
};
}
}
}
hello.init({
github : {
name : 'GitHub',
oauth : {
version : 2,
auth : 'https://github.com/login/oauth/authorize',
grant : 'https://github.com/login/oauth/access_token',
response_type : 'code'
},
scope : {
basic : '',
email : 'user:email'
},
base : 'https://api.github.com/',
get : {
'me' : 'user',
'me/friends' : 'user/following?per_page=@{limit|100}',
'me/following' : 'user/following?per_page=@{limit|100}',
'me/followers' : 'user/followers?per_page=@{limit|100}'
},
wrap : {
me : function(o,headers){
formatError(o,headers);
formatUser(o);
return o;
},
"default" : function(o,headers,req){
formatError(o,headers);
if(Object.prototype.toString.call(o) === '[object Array]'){
o = {data:o};
paging(o,headers,req);
for(var i=0;i<o.data.length;i++){
formatUser(o.data[i]);
}
}
return o;
}
}
}
});
})(hello);