diff --git a/src/api.coffee b/src/api.coffee index cf10f81e..1425d1cc 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -1,8 +1,10 @@ Promise = require 'bluebird' fs = Promise.promisifyAll require 'fs' +url = require 'url' +knex = require './db' utils = require './utils' express = require 'express' -dockerode = require 'dockerode' +request = Promise.promisify require 'request' api = express() @@ -22,7 +24,22 @@ api.post('/v1/blink', (req, res) -> ) api.post('/v1/update', (req, res) -> - console.log('TODO: Update the application') + res.send(204) + Promise.all([ + knex('config').select('value').where(key: 'apiKey') + knex('config').select('value').where(key: 'uuid') + ]).then(([[apiKey], [uuid]]) -> + apiKey = apiKey.value + uuid = uuid.value + request( + method: 'GET' + url: url.resolve(process.env.API_ENDPOINT, "/ewa/application?$filter=device/uuid eq '#{uuid}'&apikey=#{apiKey}") + json: true + ).spread((request, body) -> + for app in body.d + console.log("Got application", app) + ) + ) ) module.exports = api