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

30 lines
901 B
CoffeeScript
Raw Normal View History

2014-11-18 14:11:07 +00:00
_ = require('lodash')
Promise = require('bluebird')
PinejsClientCore = require('pinejs-client-js')(_, Promise)
settings = require('../settings')
2014-12-22 19:42:39 +00:00
server = require('../_server/server')
2014-11-26 16:15:40 +00:00
promisifiedServerRequest = Promise.promisify(server.request, server)
2014-11-18 14:11:07 +00:00
class PinejsClientRequest extends PinejsClientCore
2014-12-05 19:33:24 +00:00
# Trigger a request to the resin.io API
#
# Makes use of [pinejs-client-js](https://bitbucket.org/rulemotion/pinejs-client-js)
2014-12-05 19:33:24 +00:00
#
# @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 14:11:07 +00:00
_request: (params) ->
params.json = params.data
2014-11-18 14:11:07 +00:00
params.gzip ?= true
promisifiedServerRequest(params).spread (response, body) ->
if 200 <= response.statusCode < 300
return body
throw new Error(body)
module.exports = new PinejsClientRequest
2014-12-05 14:53:59 +00:00
apiPrefix: settings.get('apiPrefix')