mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-19 03:06:29 +00:00
Upgrade old resin-platform-api to pinejs-client-js
This commit is contained in:
parent
be2282d70f
commit
f5a0c7d6e5
@ -1,21 +1,22 @@
|
||||
_ = require('lodash')
|
||||
Promise = require('bluebird')
|
||||
Canvas = require('resin-platform-api')(_, Promise)
|
||||
PinejsClientCore = require('pinejs-client-js')(_, Promise)
|
||||
settings = require('../settings')
|
||||
server = require('../server/server')
|
||||
promisifiedServerRequest = Promise.promisify(server.request, server)
|
||||
|
||||
class CanvasRequestService extends Canvas
|
||||
class PinejsClientRequest extends PinejsClientCore
|
||||
|
||||
# Trigger a request to the resin.io API
|
||||
#
|
||||
# Makes use of [pinejs-client](https://bitbucket.org/rulemotion/pinejs-client-js)
|
||||
# Makes use of [pinejs-client-js](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
|
||||
#
|
||||
_request: (params) ->
|
||||
params.json = params.data
|
||||
params.gzip ?= true
|
||||
@ -24,7 +25,5 @@ class CanvasRequestService extends Canvas
|
||||
return body
|
||||
throw new Error(body)
|
||||
|
||||
module.exports = new CanvasRequestService
|
||||
url: settings.get('remoteUrl')
|
||||
module.exports = new PinejsClientRequest
|
||||
apiPrefix: settings.get('apiPrefix')
|
||||
withCredentials: true
|
@ -8,10 +8,10 @@ chai.use(chaiAsPromised)
|
||||
|
||||
data = require('../data/data')
|
||||
mock = require('../../../tests/utils/mock')
|
||||
canvas = require('./_canvas')
|
||||
pine = require('./_pine')
|
||||
settings = require('../settings')
|
||||
|
||||
describe 'Canvas:', ->
|
||||
describe 'Pine:', ->
|
||||
|
||||
URI =
|
||||
application: url.resolve(settings.get('apiPrefix'), 'application')
|
||||
@ -42,7 +42,7 @@ describe 'Canvas:', ->
|
||||
mock.connection.restore()
|
||||
|
||||
it 'should construct the correct url', ->
|
||||
promise = canvas.get
|
||||
promise = pine.get
|
||||
resource: 'application'
|
||||
|
||||
expect(promise).to.become(RESPONSE.applications.d)
|
@ -1,5 +1,5 @@
|
||||
_ = require('lodash-contrib')
|
||||
canvas = require('./_canvas')
|
||||
pine = require('./_pine')
|
||||
errors = require('../errors/errors')
|
||||
server = require('../server/server')
|
||||
settings = require('../settings')
|
||||
@ -16,7 +16,7 @@ settings = require('../settings')
|
||||
# console.log(applications)
|
||||
#
|
||||
exports.getAll = (callback) ->
|
||||
return canvas.get
|
||||
return pine.get
|
||||
resource: 'application'
|
||||
options:
|
||||
orderby: 'app_name asc'
|
||||
@ -43,7 +43,7 @@ exports.getAll = (callback) ->
|
||||
# console.log(application)
|
||||
#
|
||||
exports.get = (id, callback) ->
|
||||
return canvas.get
|
||||
return pine.get
|
||||
resource: 'application'
|
||||
id: id
|
||||
|
||||
@ -70,7 +70,7 @@ exports.get = (id, callback) ->
|
||||
# console.log(id)
|
||||
#
|
||||
exports.create = (name, deviceType, callback) ->
|
||||
return canvas.post
|
||||
return pine.post
|
||||
resource: 'application'
|
||||
data:
|
||||
app_name: name
|
||||
@ -97,7 +97,7 @@ exports.create = (name, deviceType, callback) ->
|
||||
# throw error if error?
|
||||
#
|
||||
exports.remove = (id, callback) ->
|
||||
return canvas.delete
|
||||
return pine.delete
|
||||
resource: 'application'
|
||||
id: id
|
||||
.then ->
|
||||
|
@ -1,4 +1,4 @@
|
||||
canvas = require('./_canvas')
|
||||
pine = require('./_pine')
|
||||
_ = require('lodash-contrib')
|
||||
errors = require('../errors/errors')
|
||||
server = require('../server/server')
|
||||
@ -16,7 +16,7 @@ settings = require('../settings')
|
||||
# console.log(devices)
|
||||
#
|
||||
exports.getAll = (callback) ->
|
||||
return canvas.get
|
||||
return pine.get
|
||||
resource: 'device'
|
||||
options:
|
||||
expand: 'application'
|
||||
@ -43,7 +43,7 @@ exports.getAll = (callback) ->
|
||||
# console.log(devices)
|
||||
#
|
||||
exports.getAllByApplication = (applicationId, callback) ->
|
||||
return canvas.get
|
||||
return pine.get
|
||||
resource: 'device'
|
||||
options:
|
||||
filter:
|
||||
@ -72,7 +72,7 @@ exports.getAllByApplication = (applicationId, callback) ->
|
||||
# console.log(device)
|
||||
#
|
||||
exports.get = (deviceId, callback) ->
|
||||
return canvas.get
|
||||
return pine.get
|
||||
resource: 'device'
|
||||
id: deviceId
|
||||
options:
|
||||
@ -97,7 +97,7 @@ exports.get = (deviceId, callback) ->
|
||||
# throw error if error?
|
||||
#
|
||||
exports.remove = (id, callback) ->
|
||||
return canvas.delete
|
||||
return pine.delete
|
||||
resource: 'device'
|
||||
id: id
|
||||
.then ->
|
||||
|
@ -1,4 +1,4 @@
|
||||
canvas = require('./_canvas')
|
||||
pine = require('./_pine')
|
||||
errors = require('../errors/errors')
|
||||
|
||||
# Get all environment variables by application
|
||||
@ -14,7 +14,7 @@ errors = require('../errors/errors')
|
||||
# console.log(environmentVariables)
|
||||
#
|
||||
exports.getAllByApplication = (applicationId, callback) ->
|
||||
return canvas.get
|
||||
return pine.get
|
||||
resource: 'environment_variable'
|
||||
options:
|
||||
filter:
|
||||
@ -40,7 +40,7 @@ exports.getAllByApplication = (applicationId, callback) ->
|
||||
# throw error if error?
|
||||
#
|
||||
exports.remove = (id, callback) ->
|
||||
return canvas.delete
|
||||
return pine.delete
|
||||
resource: 'environment_variable'
|
||||
id: id
|
||||
.then ->
|
||||
|
@ -44,7 +44,7 @@
|
||||
"rimraf": "~2.2.8",
|
||||
"commander": "~2.5.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"resin-platform-api": "git+ssh://git@bitbucket.org/rulemotion/pinejs-client-js.git#6dbc6de",
|
||||
"pinejs-client-js": "git+ssh://git@bitbucket.org/rulemotion/pinejs-client-js.git",
|
||||
"bluebird": "~2.3.11",
|
||||
"open": "0.0.5",
|
||||
"inquirer": "~0.8.0",
|
||||
|
Loading…
Reference in New Issue
Block a user