UNPKG

hellojs-xiaotian

Version:

A clientside Javascript library for standardizing requests to OAuth2 web services (and OAuth1 - with a shim)

86 lines (69 loc) 1.63 kB
// 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);