Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including cocoon-cloud-sdk with all npm packages installed. Try it out:

var cocoonCloudSdk = require("cocoon-cloud-sdk")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

cocoon-cloud-sdk v2.0.1

Cocoon.io is a cloud service that allows any web developer to build performant mobile native apps/games based on their HTML5 content.

Cocoon Cloud SDK Travis Build Status NPM Version

bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies bitHound Code


The Cocoon Cloud SDK is the easiest way to integrate the Cocoon.io cloud compiler in any service or app. With this simple API, anyone can authenticate with their Cocoon.io account and create, update and compile HTML5 projects in the cloud programmatically.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

First things first. In order to access the Cocoon.io API you will need a ClientID credential (a ClientSecret too if your code runs in a server). You can contact us at support@cocoon.io to request it.

Other than that, you only need to have NodeJS and NPM installed in your system.

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt install -y nodejs

Installing

Clone the repository.

git clone https://github.com/CocoonIO/cocoon-cloud-sdk.git

And install its dependencies

npm install

The transpiled code should be in the out folder.

Running the tests

The tests are found in spec/tests.

npm test

Coding style tests

To inspect the code style of the source code:

npm run inspect-src

To inspect the code style of the tests:

npm run inspect-spec

Deployment

To use this repo as a NPM module in your project follow these instructions.

As mentioned previously: to access the Cocoon.io API you will need a ClientID credential (a ClientSecret too if your code runs in a server). You can contact us at support@cocoon.io to request it.

Install NodeJS and NPM in your system.

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt install -y nodejs

Install the module from NPM.

npm install cocoon-cloud-sdk

And import it in your NodeJS or Web project.

import * as cocoonSDK from "cocoon-cloud-sdk";
<script src="cocoon-cloud-sdk/index.js"></script>

Example

You can see an example of the usage in sample.

Usage

Log In into Cocoon.

const oAuth = new cocoonSDK.OAuth(grantType.Password, CLIENT_ID, CLIENT_SECRET);
oAuth.tokenExchangePassword("john.smith@example.com", "12345678")
.then((response) => {
    cocoonSDK.CocoonAPI.setupAPIAccess(response.access_token, response.refresh_token, response.expires_in);
});

Some API Examples. The SDK mimics the Cocoon.io REST API.

The Project API:

//List all projects
cocoonSDK.ProjectAPI.list()
.then((projects) => {
    doSomething();
})
.catch((error) => {
    fixSomething();
});

//Create a new project by uploading a zip file
cocoonSDK.ProjectAPI.createFromZipUpload(file)
.then((project) => {
    doSomething();
})
.catch((error) => {
    fixSomething();
});

//Create a new project from a url
cocoonSDK.ProjectAPI.createFromURL("MY_URL")
.then((project) => {
    doSomething();
})
.catch((error) => {
    fixSomething();
});

//Create a new project from a repository
cocoonSDK.ProjectAPI.createFromRepository({url:"MY_GITHUB_URL", branch:"MY_BRANCH"})
.then((project) => {
    doSomething();
})
.catch((error) => {
    fixSomething();
});

For Signing Keys:

//List all signing keys
cocoonSDK.SigningKeyAPI.list()
.then((signingKeys) => {
    doSomething();
})
.catch((error) => {
    fixSomething();
});

//Create a new Android signing key
cocoonSDK.SigningKeyAPI.createAndroid(name, alias, keystore, keystorePassword, certificatePassword)
.then((signingKey) => {
    doSomething();
})
.catch((error) => {
    fixSomething();
});

The objects returned by the API have their own methods to ease commonly performed tasks.

//Working with a Project object
cocoonSDK.ProjectAPI.get("PROJECT_ID")
.then((project) => {
    //project.isCompiling();
    //project.updateZip(zipFile);
    //project.delete();
    //project.assignSigningKey(signingKey);
    //...
})
.catch((error) => {
    fixSomething();
});

//Working with a Signing Key object
cocoonSDK.SigningKeyAPI.get("SIGNING_KEY_ID")
.then((signingKey) => {
    //signingKey.delete();
})
.catch((error) => {
    fixSomething();
});

Built With

  • Typescript - Language
  • NPM - Dependency Management
  • Jasmine - Testing Framework
  • Popsicle - Simple HTTP requests library for node and the browser
  • XMLSugar Helper functions to work with the config.xml

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free