github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/clients/js/client.js (about)

     1  var Camli = {
     2  
     3  BlobStore: function() {
     4  }
     5  
     6  };
     7  
     8  Camli.BlobStore.prototype.blobURL = function(ref) {
     9    return '/camli/' + ref;
    10  };
    11  
    12  Camli.BlobStore.prototype.xhr = function(url, cb) {
    13    var xhr = new XMLHttpRequest();
    14    xhr.onreadystatechange = function() {
    15      if (xhr.readyState == 4) {
    16        if (xhr.status == 200) {
    17          cb(xhr.responseText);
    18        }
    19      }
    20      // XXX handle error
    21    };
    22    xhr.open('GET', url, true);
    23    xhr.send(null);
    24  };
    25  
    26  Camli.BlobStore.prototype.xhrJSON = function(url, cb) {
    27    this.xhr('/camli/enumerate-blobs', function(data) {
    28      cb(JSON.parse(data));
    29    });
    30  };
    31  
    32  Camli.BlobStore.prototype.enumerate = function(cb) {
    33    this.xhrJSON('/camli/enumerate-blobs', cb);
    34  };
    35  
    36  Camli.BlobStore.prototype.getBlob = function(ref, cb) {
    37    this.xhr(this.blobURL(ref), cb);
    38  };