From e18bc832858c4a1aae196e38f229113c1de7b914 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti <juanchiviotti@gmail.com> Date: Tue, 18 Nov 2014 10:11:07 -0400 Subject: [PATCH] Integrat resin-platform-api --- lib/config.coffee | 1 + lib/models/_canvas.coffee | 23 +++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lib/models/_canvas.coffee diff --git a/lib/config.coffee b/lib/config.coffee index b8d8e7c7..faf16bb5 100644 --- a/lib/config.coffee +++ b/lib/config.coffee @@ -4,4 +4,5 @@ module.exports = # TODO: Should be configurable remoteUrl: 'https://staging.resin.io' + apiPrefix: '/ewa/' dataPrefix: path.join(process.env.HOME, '.resin') diff --git a/lib/models/_canvas.coffee b/lib/models/_canvas.coffee new file mode 100644 index 00000000..b4d1add8 --- /dev/null +++ b/lib/models/_canvas.coffee @@ -0,0 +1,23 @@ +_ = require('lodash') +Canvas = require('resin-platform-api') +Promise = require('bluebird') +config = require('../config') +server = require('../server/server') +promisifiedServerRequest = Promise.promisify(server.request, server) + +# TODO: I've copy and pasted request.coffee that comes with +# resin-platform-api. In package.json, the main is set as +# simply canvas.js, so I have no way of access this file. +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 diff --git a/package.json b/package.json index fc858239..f5efde60 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "rimraf": "~2.2.8", "commander": "~2.5.0", "mkdirp": "~0.5.0", - "resin-platform-api": "git+ssh://git@bitbucket.org/rulemotion/resin-platform-api.git#master" + "resin-platform-api": "git+ssh://git@bitbucket.org/rulemotion/resin-platform-api.git#master", + "bluebird": "~2.3.11" } }