-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrdio.js
39 lines (34 loc) · 886 Bytes
/
rdio.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
// Depends on cache.js
(function() {
Rdio = {
// Load cached response or call Rdio api to get new data
// Caches according to method and content
get: function(method, content, k) {
var that = this;
if (!method) {
return;
}
content = content || {};
var contentStr = '';
_.each(_.keys(content).sort(), function(key) {
contentStr += key + content[key];
});
var cacheKey = method + '::' + contentStr;
var cachedResponse = Cache.get(cacheKey);
if (cachedResponse) {
k(cachedResponse);
} else {
R.ready(function() {
R.request({
method: method,
content: content,
success: function(response) {
Cache.put(cacheKey, response);
k(response);
}
});
});
}
}
};
})();