1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Documentation: Remove personal info from sample

This commit is contained in:
Vishal Banthia 2016-01-04 21:53:52 +09:00
parent 981fb0d449
commit a875d85c46

View file

@ -63,7 +63,7 @@ clientWithPromise.then(function(api) {
api.user.getUser() api.user.getUser()
.then(function(res) { .then(function(res) {
console.log(res.obj.user.email) console.log(res.obj.user.email)
// vishal.banthia.vb@gmail.com // vishal@example.com
}) })
}) })
``` ```
@ -162,7 +162,7 @@ clientWithPromise.then(function(api) {
api.user.getUser() api.user.getUser()
.then(function(res) { .then(function(res) {
console.log(res.obj.user.email) console.log(res.obj.user.email)
// vishal.banthia.vb@gmail.com // vishal@example.com
}) })
}) })
``` ```
@ -330,17 +330,17 @@ var SWAGGER_URL = 'https://stf.example.org/api/v1/swagger.json';
var AUTH_TOKEN = 'xx-xxxx-xx'; var AUTH_TOKEN = 'xx-xxxx-xx';
// Using Promise // Using Promise
var clientWithPromise = new Swagger({ var client = new Swagger({
url: SWAGGER_URL url: SWAGGER_URL
, usePromise: true , usePromise: true
, authorizations: { , authorizations: {
accessTokenAuth: new Swagger.ApiKeyAuthorization('Authorization', 'bearer ' + AUTH_TOKEN, 'header') accessTokenAuth: new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + AUTH_TOKEN, 'header')
} }
}) })
var serial = process.argv.slice(2)[0] var serial = process.argv.slice(2)[0]
clientWithPromise.then(function(api) { client.then(function(api) {
return api.devices.getDeviceBySerial({ return api.devices.getDeviceBySerial({
serial: serial serial: serial
, fields: 'serial,present,ready,using,owner' , fields: 'serial,present,ready,using,owner'
@ -348,9 +348,11 @@ clientWithPromise.then(function(api) {
// check if device can be added or not // check if device can be added or not
var device = res.obj.device var device = res.obj.device
if (!device.present || !device.ready || device.using || device.owner) { if (!device.present || !device.ready || device.using || device.owner) {
throw new Error('Device is not available') console.log('Device is not available')
return
} }
// add device to user
return api.user.addUserDevice({ return api.user.addUserDevice({
device: { device: {
serial: device.serial serial: device.serial
@ -358,9 +360,11 @@ clientWithPromise.then(function(api) {
} }
}).then(function(res) { }).then(function(res) {
if (!res.obj.success) { if (!res.obj.success) {
throw new Error('Could not connect to device') console.log('Could not add device')
return
} }
// get remote connect url
return api.user.remoteConnectUserDeviceBySerial({ return api.user.remoteConnectUserDeviceBySerial({
serial: device.serial serial: device.serial
}).then(function(res) { }).then(function(res) {
@ -383,26 +387,25 @@ var Swagger = require('swagger-client');
var SWAGGER_URL = 'https://stf.example.org/api/v1/swagger.json'; var SWAGGER_URL = 'https://stf.example.org/api/v1/swagger.json';
var AUTH_TOKEN = 'xx-xxxx-xx'; var AUTH_TOKEN = 'xx-xxxx-xx';
// Using Promise var client = new Swagger({
var clientWithPromise = new Swagger({
url: SWAGGER_URL url: SWAGGER_URL
, usePromise: true , usePromise: true
, authorizations: { , authorizations: {
accessTokenAuth: new Swagger.ApiKeyAuthorization('Authorization', 'bearer ' + AUTH_TOKEN, 'header') accessTokenAuth: new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + AUTH_TOKEN, 'header')
} }
}) })
var serial = process.argv.slice(2)[0] var serial = process.argv.slice(2)[0]
clientWithPromise.then(function(api) { client.then(function(api) {
return api.user.getUserDevices({ return api.user.getUserDevices({
serial: serial serial: serial
, fields: 'serial,present,ready,using,owner' , fields: 'serial,present,ready,using,owner'
}).then(function(res) { }).then(function(res) {
// check if device can be added or not // check if user has that device or not
var devices = res.obj.devices var devices = res.obj.devices
var hasDevice = false var hasDevice = false
devices.forEach(function(device) { devices.forEach(function(device) {
if(device.serial === serial) { if(device.serial === serial) {
hasDevice = true; hasDevice = true;
@ -410,16 +413,17 @@ clientWithPromise.then(function(api) {
}) })
if (!hasDevice) { if (!hasDevice) {
throw new Error('You are not owner') console.log('You do not own that device')
return
} }
return api.user.deleteUserDeviceBySerial({ return api.user.deleteUserDeviceBySerial({
serial: serial serial: serial
}).then(function(res) { }).then(function(res) {
if (!res.obj.success) { if (!res.obj.success) {
throw new Error('Could not disconnect to device') console.log('Could not disconnect')
return
} }
console.log('Device disconnected successfully!') console.log('Device disconnected successfully!')
}) })
}) })