# cloudshare

> CloudShare Inc. API v3 SDK

Latest version **1.0.1** (published 2017-03-16) · Apache License 2.0 license · 0 weekly downloads

## Install

```sh
npm install cloudshare
pnpm add cloudshare
yarn add cloudshare
bun add cloudshare
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-03-16 |
| First published | 2017-03-16 |
| Weekly downloads | 0 |
| License | Apache License 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | CloudShare Inc. |
| Maintainers | cloudshare |

## Links

- npm: https://www.npmjs.com/package/cloudshare
- npm.io page: https://npm.io/package/cloudshare

## Dependencies (4)

- [xhr2](https://npm.io/package/xhr2.md) ^0.1.4
- [jssha](https://npm.io/package/jssha.md) ^1.5.0
- [bottlejs](https://npm.io/package/bottlejs.md) ^0.6.0
- [es6-promise](https://npm.io/package/es6-promise.md) ^2.0.0

## Recent versions

- 1.0.1 (latest) — 2017-03-16
- 1.0.0 — 2017-03-16

## README

CloudShare API v3 SDK
=====================
Quickstart
----------
### Install with NPM
```
npm install cloudshare
```

### Build it yourself
1. Install node version >= 4
3. run `npm install`
4. 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)
    1. `npm run bundle` to build the unminified `dist/cssdk.js` (with built-in source-map).
    2. `set dev=true && npm run bundle` to build the minified `dist/cssdk.min.js`.
    3. `npm test` to run the unit tests.
5. On Linux/OSX:
    1. `npm run test_unix` or `npm 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
```

Interface
---------
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:

1. `npm install`
2. `node run server`
3. Make sure you set your API ID and API key in the global vars: `API_ID` and `API_KEY` in `driver/index.html`.
3. Navigate to `localhost:8080/driver/index.html` and 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);
});
```

---
_Source: https://npm.io/package/cloudshare · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
