balena-cli/lib/resin/models/_canvas.coffee
2014-12-03 12:03:54 -04:00

21 lines
623 B
CoffeeScript

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