2014-11-18 14:11:07 +00:00
|
|
|
_ = require('lodash')
|
|
|
|
Canvas = require('resin-platform-api')
|
|
|
|
Promise = require('bluebird')
|
|
|
|
config = require('../config')
|
2014-11-26 16:07:10 +00:00
|
|
|
resin = require('../resin')
|
|
|
|
promisifiedServerRequest = Promise.promisify(resin.server.request)
|
2014-11-18 14:11:07 +00:00
|
|
|
|
|
|
|
class CanvasRequestService extends Canvas(_, Promise)
|
|
|
|
_request: (params) ->
|
2014-11-24 14:40:12 +00:00
|
|
|
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 CanvasRequestService
|
|
|
|
url: config.remoteUrl
|
|
|
|
apiPrefix: config.apiPrefix
|
|
|
|
withCredentials: true
|