-
Notifications
You must be signed in to change notification settings - Fork 549
/
soundcloud.js
85 lines (69 loc) · 1.59 KB
/
soundcloud.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
82
83
84
85
// See: https://developers.soundcloud.com/docs/api/reference
(function(hello) {
hello.init({
soundcloud: {
name: 'SoundCloud',
oauth: {
version: 2,
auth: 'https://soundcloud.com/connect',
grant: 'https://soundcloud.com/oauth2/token'
},
// Request path translated
base: 'https://api.soundcloud.com/',
get: {
me: 'me.json',
// Http://developers.soundcloud.com/docs/api/reference#me
'me/friends': 'me/followings.json',
'me/followers': 'me/followers.json',
'me/following': 'me/followings.json',
// See: http://developers.soundcloud.com/docs/api/reference#activities
'default': function(p, callback) {
// Include '.json at the end of each request'
callback(p.path + '.json');
}
},
// Response handlers
wrap: {
me: function(o) {
formatUser(o);
return o;
},
'default': function(o) {
if (Array.isArray(o)) {
o = {
data: o.map(formatUser)
};
}
paging(o);
return o;
}
},
xhr: formatRequest,
jsonp: formatRequest
}
});
function formatRequest(p, qs) {
// Alter the querystring
var token = qs.access_token;
delete qs.access_token;
qs.oauth_token = token;
qs['_status_code_map[302]'] = 200;
return true;
}
function formatUser(o) {
if (o.id) {
o.picture = o.avatar_url;
o.thumbnail = o.avatar_url;
o.name = o.username || o.full_name;
}
return o;
}
// See: http://developers.soundcloud.com/docs/api/reference#activities
function paging(res) {
if ('next_href' in res) {
res.paging = {
next: res.next_href
};
}
}
})(hello);