Giter VIP home page Giter VIP logo

node-cocoonjs-cloud-api's Introduction

CocoonJS Cloud API Node Module

Node.js REST Client for the CocoonJS Cloud API

Overview

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!

Usage

Authenticate with Username and Password

var client = require('cocoonjs-cloud-api');

client.auth({ username: '[email protected]', password: 'lalala' }, function(e, api) {
    // time to make requests
});

GET /v1/project

api.get('/project', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /v1/project/:id

api.get('/project/W6m62sfubmtOxBa7IpTnPQ', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /v1/project/:id/:platform

api.get('/project/W6m62sfubmtOxBa7IpTnPQ/android').pipe(fs.createWriteStream('app.apk'));

POST /v1/project

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 /v1/project/:id

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);
});

POST /v1/project/:id/compile

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);
});

POST /v1/project/:id/compile/:platform

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);
});

DELETE /v1/project/:id

api.del('/project/W6m62sfubmtOxBa7IpTnPQ', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

API

client.auth(options, callback)

CocoonJS Cloud Authentication.

Authentications with CocoonJS Cloud and returns an instance of API. The authentication credentials must be a username and password.

Options:

  • 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 the API instance to interact with cocoonjs cloud.

Example:

var client = require('cocoonjs-cloud-api');

client.auth({ username: '[email protected]', password: 'lalala' }, function(e, api) {
    if (e) {
        console.log('error:', e);
        return;
    }

    // make some api requests
});

api(path, [options], [callback])

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.

Options:

  • path {String} is a relative resource path (e.g. "/project").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example: GET Request

api('/project', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

Example: POST Request

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);
});

api.get(path, [options], [callback])

GET API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'GET' }.

Options:

  • path {String} is a relative resource path (e.g. "/project").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

api.get('/me', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

api.post(path, [options], [callback])

POST API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'POST' }.

Options:

  • path {String} is a relative resource path (e.g. "/project").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

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);
});

api.put(path, [options], [callback])

PUT API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'PUT' }.

Options:

  • path {String} is a relative resource path (e.g. "/project").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

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);
});

api.del(path, [options], [callback])

DELETE API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'DELETE' }.

Options:

  • path {String} is a relative resource path (e.g. "/project").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

api.del('/project/W6m62sfubmtOxBa7IpTnPQ', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

api.defaults(options)

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.

node-cocoonjs-cloud-api's People

Contributors

abdul-martinez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.