Esempio n. 1
0
 test('get something that doesnt exist', t => {
   let earlier = timestamp.now()-5
   client.get(queryStr('coffee', earlier, timestamp.now()), {}, (err, res, body) => {
     let status = res.statusCode
     t.deepEquals(body, [], "got an empty array")
     t.end()
   })
 })
Esempio n. 2
0
  function addAndGet (t, cb) {

    function query (obs, t0, t1, cb) {
      client.get(queryStr(obs, t0, t1), {}, (err, res, body) => {
        let status = res.statusCode
        console.log(body)
        t.deepEqual(body[0].type, obs,
                    'we got the correct observation back')
        t.equal(status, 200,
                'got a 200 back from server on GET query/ observation')
        cb()
      })
    }

    let observation = randomstr()
    let now = timestamp.now()
    client.get(`add/${observation}`, {}, (err, res, body) => {
      let status = res.statusCode
      console.log(body)
      t.equal(status, 200,
              'got a 200 back from server on GET add/ observation')
      query(observation, now, timestamp.now(), () => {
        query(observation, now, timestamp.now(), () => {
          cb()
        })
      })
    })
  }
Esempio n. 3
0
 return new Promise(function(fulfill, reject) {
   var currentTime = Timestamp.now();
   if (self._accessTokenExpiration - currentTime <= 10) {
     fulfill(self._refreshAccessToken());
   } else {
     fulfill(self._accessToken);
   }
 });
Esempio n. 4
0
var RefreshClient = function(refreshString) {
  if (typeof refreshString !== 'string') {
    throw new Error('Refresh token must be supplied');
  }
  this._refreshToken = refreshString;
  this._accessToken = '';
  this._accessTokenExpiration = Timestamp.now(-1);
};
Esempio n. 5
0
 // adds an observation to table
 // returns a stream
 function add (observation) {
   let obs = {
     timestamp: r.epochTime(timestamp.now()),
     type: observation,
   }
   return streamFrom(
     r.table(tableName).insert(obs)
   )
 }
Esempio n. 6
0
 client.get(`add/${observation}`, {}, (err, res, body) => {
   let status = res.statusCode
   console.log(body)
   t.equal(status, 200,
           'got a 200 back from server on GET add/ observation')
   query(observation, now, timestamp.now(), () => {
     query(observation, now, timestamp.now(), () => {
       cb()
     })
   })
 })
Esempio n. 7
0
/**
 * adds an item to a playlist
 * @param  {string}  playlistURI The playlist URI
 * @param  {string}  mediaURI    The mediaURI to add
 * @param  {boolean} container   Is playlist a container
 * @param  {number}  time        The start time
 */
function addToPlaylist (playlistURI, mediaURI, container, time) {
  var params = []
  var mtime
  if (container) {
    mtime = Math.floor(timestamp.now())
  }
  params.push({ 'uri': mediaURI, 'mtime': mtime, 'base': playlistURI, 'startTime' : time })

  var patch = ''
  debug('params', params)
  patch += createInsertPatch(params)

  console.log('patch', patch)
  shell.patch(playlistURI, patch, function (err, ret) {
    if (err) {
      console.error(err)
    } else {
      console.log(ret)
    }
  })
}
Esempio n. 8
0
  shell.cat(playlistURI, function (err, content, uri) {
    if (err) {
      console.error(err)
    } else {
      var files = []
      var sort = 'asc'
      var g = $rdf.graph()
      $rdf.parse(content, g, uri, 'text/turtle')

      var arr = g.statementsMatching(null, $rdf.sym('http://www.w3.org/ns/ldp#contains'), null, $rdf.sym(uri))
      console.log(arr)
      for (var i = 0; i < arr.length; i++) {
        var file = arr[i]
        if (file.object && file.object.uri && /.ttl$/.test(file.object.uri)) {
          continue
        }
        var mtime = anyObj(g, file.object, 'http://www.w3.org/ns/posix/stat#mtime')
        var title = anyObj(g, file.object, 'http://purl.org/dc/terms/title')

        files.push({ 'uri': file.object.uri, 'mtime': mtime, 'title': title })
      }
      files = files.sort(function (a, b) {
        if (sort === 'desc') {
          return parseFloat(b.mtime) - parseFloat(a.mtime)
        } else {
          return parseFloat(a.mtime) - parseFloat(b.mtime)
        }
      })

      var patch = ''
      var params = []
      mtime = Math.floor(timestamp.now())
      params.push({ 'uri': mediaURI, 'mtime': mtime, 'base': playlistURI })
      debug('params', params)
      patch += createInsertPatch(params)

      var num
      if (files.length) {
        if (keep) {
          if ((files.length + 1 - keep) >= 0) {
            num = files.length + 1 - keep
          } else {
            num = 0
          }
        } else {
          num = 1
        }
        params = []
        for (i = 0; i < num; i++) {
          file = files[i]
          params.push({ 'uri': file.uri, 'mtime': file.mtime, 'base': playlistURI })
        }
        debug('params', params)
        var deletePatch = createDeletePatch(params, g)
        if (deletePatch) {
          patch += deletePatch
        }
      }

      console.log('patch', patch)
      shell.patch(uri, patch, function (err, ret) {
        if (err) {
          console.error(err)
        } else {
          console.log(ret)
        }
      })
    }
  })
Esempio n. 9
0
 query(observation, now, timestamp.now(), () => {
   query(observation, now, timestamp.now(), () => {
     cb()
   })
 })