npm install cloudshare
- Install node version >= 4
- run
npm install
- On Windows: use the make-like command
npm run
to run the package's tasks: (this assumes you're running a windows machine, see step 5 if not)npm run bundle
to build the unminifieddist/cssdk.js
(with built-in source-map).set dev=true && npm run bundle
to build the minifieddist/cssdk.min.js
.npm test
to run the unit tests.
- On Linux/OSX:
npm run test_unix
ornpm 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=2012
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.
You can take a look at driver/index.html
for a kind of "hello world" example. To run it do the following:
npm install
npm run server
- Make sure you set your API ID and API key in the global vars:
API_ID
andAPI_KEY
indriver/index.html
. - Navigate to
localhost:8080/driver/index.html
and open the browser's javascript console.
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);
});
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);
});
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);
});
cssdk.req({
hostname: 'use.cloudshare.com',
method: 'POST',
path: 'invitations/actions/inviteanonymousendusertoblueprint',
content: {
policyId: 'POIdMkap90pdv1gA_39i79Ffa',
blueprintId: 'BPlaD_p14Vlzx5KqWpMm0_aB',
owningProjectMemberId: 'VPqDoa5_pKjhNxZ2QlApYtdsl',
opportunity: 'My Opportunity',
validForDays: 15
},
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);
});