cloudshare v1.0.1
CloudShare API v3 SDK
Quickstart
Install with NPM
npm install cloudshareBuild it yourself
- Install node version >= 4
- run
npm install - On Windows: use the make-like command
npm runto run the package's tasks: (this assumes you're running a windows machine, see step 5 if not)npm run bundleto build the unminifieddist/cssdk.js(with built-in source-map).set dev=true && npm run bundleto build the minifieddist/cssdk.min.js.npm testto run the unit tests.
- On Linux/OSX:
npm run test_unixornpm run bundle_unix
On windows machines with more than one visual studio installed, node-gyp complains sometimes. Choosing another visual studio version to use seem to help:
npm install --msvs_version=2012Interface
Whether included as an HTML script tag or through a CommonJS require(), the interface is a single object (a global object named cssdk in case it is included in a script tag), that has a single method req() that accepts an options object:
{
hostname: String,
method: String,
path: String,
queryParams: Object,
content: Object,
apiId: String,
apiKey: String,
}hostname, method, apiId and apiKey are required. And in order to request something useful the path property needs to be filled (e.g. path="envs", see examples below). queryParams if not null, is parsed into a query string that's added to the URL before the request is sent, and content is parsed into a JSON string before the request is sent.
If one of the required options is null/undefined, an exception is thrown. Otherwise the return value is an object:
{
content: Object | Array,
status: Number
}status is the HTTP response status, if not in the 200's range an error occured, if the status is 204 content is null. Otherwise content holds the actual response in form of an Object or an Array.
Example Usage
An example html
You can take a look at driver/index.html for a kind of "hello world" example. To run it do the following:
npm installnode run server- Make sure you set your API ID and API key in the global vars:
API_IDandAPI_KEYindriver/index.html. - Navigate to
localhost:8080/driver/index.htmland open the browser's javascript console.
List your environments
cssdk.req({
hostname: 'use.cloudshare.com',
method: 'GET',
path: 'envs',
apiId: 'Your API ID',
apiKey: 'Your API key'
})
.then(function(response) {
console.log('hi! these are my environments:');
console.log(response.content);
})
.catch(function(response) {
if (response instanceof Error)
console.log(response);
else
console.log('got status:', response.status,
'with content:', response.content);
});Get one environment
cssdk.req({
hostname: 'use.cloudshare.com',
method: 'GET',
path: 'envs/' + envId,
apiId: 'Your API ID',
apiKey: 'Your API key'
})
.then(function(response) {
console.log('Look at my environment details:');
console.log(response.content);
})
.catch(function(response) {
if (response instanceof Error)
console.log(response);
else
console.log('got status:', response.status,
'with content:', response.content);
});Suspend an environment
cssdk.req({
hostname: 'use.cloudshare.com',
method: 'PUT',
path: 'envs/actions/suspend',
queryParams: {
envId: envId
},
apiId: 'Your API ID',
apiKey: 'Your API key'
})
.then(function(response) {
console.log(response);
})
.catch(function(response) {
if (response instanceof Error)
console.log(response);
else
console.log('got status:', response.status,
'with content:', response.content);
});