cocoon-cloud-sdk
v3.0.0
Published
Cocoon.io is a cloud service that allows any web developer to build performant mobile native apps/games based on their HTML5 content.
Downloads
27
Maintainers
Readme
Cocoon Cloud SDK
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 [email protected] 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_10.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 [email protected] to request it.
Install NodeJS and NPM in your system.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs
Install the module from NPM.
npm install cocoon-cloud-sdk --save
You must use a module bundler like Webpack to use it in a browser. Make sure the node definitions are included if you use typescript
{
"compilerOptions": {
"typeRoots" : ["node_modules/@types"],
"types" : ["node"]
}
}
And import it in your NodeJS or Web project.
import * as cocoonSDK from "cocoon-cloud-sdk";
Documentation
You can read the documentation at CocoonIO.github.io/cocoon-cloud-sdk.
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("[email protected]", "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
- Imanol Fernandez - Version 1.0.0 - MortimerGoro
- Jorge Domínguez - Since version 2.0.0 - BlueSialia
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