balena-cli/lib/models/_canvas.coffee

21 lines
608 B
CoffeeScript
Raw Normal View History

2014-11-18 14:11:07 +00:00
_ = require('lodash')
Canvas = require('resin-platform-api')
Promise = require('bluebird')
config = require('../config')
server = require('../server/server')
promisifiedServerRequest = Promise.promisify(server.request, server)
class CanvasRequestService extends Canvas(_, Promise)
_request: (params) ->
params.json = true
params.gzip ?= true
promisifiedServerRequest(params).spread (response, body) ->
if 200 <= response.statusCode < 300
return body
throw new Error(body)
module.exports = new CanvasRequestService
url: config.remoteUrl
apiPrefix: config.apiPrefix
withCredentials: true