Node.js REST Client for the CocoonJS Cloud API
This library simplifies requests to the CocoonJS Cloud REST API for node.js clients.
If something is inaccurate or missing, please send a pull request!
var client = require('cocoonjs-cloud-api');
client.auth({ username: 'user@email.com', password: 'lalala' }, function(e, api) {
// time to make requests
});
api.get('/project', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/project/W6m62sfubmtOxBa7IpTnPQ', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/project/W6m62sfubmtOxBa7IpTnPQ/android').pipe(fs.createWriteStream('app.apk'));
var options = {
form: {
"title": "My App created using the API",
"package": "com.domain.bundleid",
"version": "0.1"
}
};
api.post('/project', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
"title": "My App created using the API Updated",
"package": "com.domain.bundleid",
"version": "0.2"
}
};
api.put('/project/W6m62sfubmtOxBa7IpTnPQ', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
"view": "webview+",
"version": "3.5",
"ios": "true",
"android": "true",
"file": "/my/folder/file.zip"
}
};
api.post('/project/W6m62sfubmtOxBa7IpTnPQ/compile', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
Compile specific platforms:
var options = {
form: {
"view": "webview+",
"version": "3.5",
"file": "/my/folder/file.zip"
}
};
api.post('/project/W6m62sfubmtOxBa7IpTnPQ/compile/android', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.del('/project/W6m62sfubmtOxBa7IpTnPQ', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
CocoonJS Cloud Authentication.
Authentications with CocoonJS Cloud and returns an instance of API
.
The authentication credentials must be a username and password.
options
{Object}
is the authentication settings.options.username
{String}
is the cocoonjs cloud username.options.password
{String}
is the cocoonjs cloud password.- [
options.proxy
]{String}
specifies an optional proxy server. e.g. 'http://myproxy.com:8181'. callback
{Function}
is trigger after the authentication.e
{Error}
is null unless there is an error.api
{Object}
is theAPI
instance to interact with cocoonjs cloud.
var client = require('cocoonjs-cloud-api');
client.auth({ username: 'user@email.com', password: 'lalala' }, function(e, api) {
if (e) {
console.log('error:', e);
return;
}
// make some api requests
});
API Request.
Create a RESTful request to the CocoonJS Cloud API. The api
function is a
wrapper to request's interface.
The path
parameter is a relative path to a CocoonJS Cloud API response.
For example, to the resource https://api.ludei.com/v1/project
is specified
as the path /project
.
The options
parameter maps directly to request's options.
The default request method is GET
. You can specify a specific but you can be changed
in the options
parameters (e.g. { method: 'POST' }
).
To send form data, you can use the options.form
parameter. If the key 'file' is found the submission Content-Type is 'multipart/form-data' else 'application/json' are assumed.
path
{String}
is a relative resource path (e.g."/project"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
api('/project', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
title: 'My App',
create_method: 'file'
file: '/path/to/app.zip'
},
method: 'POST'
};
api('/project', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
GET API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'GET' }
.
path
{String}
is a relative resource path (e.g."/project"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
api.get('/me', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
POST API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'POST' }
.
path
{String}
is a relative resource path (e.g."/project"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
var options = {
form: {
"title": "My App created using the API",
"package": "com.domain.bundleid",
"version": "0.1"
}
};
api.post('/project', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
PUT API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'PUT' }
.
path
{String}
is a relative resource path (e.g."/project"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
var options = {
form: {
"title": "My App created using the API Updated",
"package": "com.domain.bundleid",
"version": "0.2"
}
};
api.put('/project/W6m62sfubmtOxBa7IpTnPQ', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
DELETE API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'DELETE' }
.
path
{String}
is a relative resource path (e.g."/project"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
api.del('/project/W6m62sfubmtOxBa7IpTnPQ', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
This maps directly to request's default
method.
This method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.