balena-cli/lib/resin/models/_canvas.coffee

31 lines
933 B
CoffeeScript
Raw Normal View History

2014-11-18 10:11:07 -04:00
_ = require('lodash')
Promise = require('bluebird')
2014-12-05 15:33:24 -04:00
Canvas = require('resin-platform-api')(_, Promise)
settings = require('../settings')
2014-11-26 12:15:40 -04:00
server = require('../server/server')
promisifiedServerRequest = Promise.promisify(server.request, server)
2014-11-18 10:11:07 -04:00
2014-12-05 15:33:24 -04:00
class CanvasRequestService extends Canvas
# Trigger a request to the resin.io API
#
# Makes use of [pinejs-client](https://bitbucket.org/rulemotion/pinejs-client-js)
#
# @private
#
# @param {Object} params request params (same as node-request params)
#
# @note You shouldn't make use of this method directly, but through models
2014-11-18 10:11:07 -04:00
_request: (params) ->
params.json = params.data
2014-11-18 10:11:07 -04:00
params.gzip ?= true
promisifiedServerRequest(params).spread (response, body) ->
if 200 <= response.statusCode < 300
return body
throw new Error(body)
module.exports = new CanvasRequestService
2014-12-05 10:53:59 -04:00
url: settings.get('remoteUrl')
apiPrefix: settings.get('apiPrefix')
2014-11-18 10:11:07 -04:00
withCredentials: true