-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdk.js
More file actions
32 lines (27 loc) · 802 Bytes
/
hdk.js
File metadata and controls
32 lines (27 loc) · 802 Bytes
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
function addMethod(object, name, fn){
var old = object[ name ];
object[ name ] = function(){
if ( fn.length == arguments.length )
return fn.apply( this, arguments );
else if ( typeof old == 'function' )
return old.apply( this, arguments );
};
}
function HDK(rootUrl) {
this.rootUrl = rootUrl;
}
addMethod(HDK.prototype, "fetch", function(callback) {
this.fetch(this.rootUrl, callback);
});
addMethod(HDK.prototype, "fetch", function(url, callback) {
$.getJSON(url,function(data) {
callback($.extend(data,HDK.prototype));
});
});
addMethod(HDK.prototype, "follow", function(linkName, args, callback) {
var link = this._links[linkName];
var href = link.href;
if(link.templated)
href = href.assign(args);
this.fetch(href,callback);
});