GithubHelp home page GithubHelp logo

javascript-forks / appcelerator.acs-node-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sanyaade-mobiledev/cocoafish-node-sdk

0.0 2.0 0.0 741 KB

SDK to use ACS from Node.js applications

License: Other

JavaScript 99.96% CSS 0.04%

appcelerator.acs-node-sdk's Introduction

ACS Node SDK Build Status

The SDK of ACS for NodeJS

Getting started

git clone [email protected]:realpaul/acs-node-sdk.git
cd acs-node-sdk
npm install
export ACS_APPKEY=ONE_OF_YOUR_ACS_TEST_APPKEY
npm test

Basic Example

You can get an overview of ACS Node SDK example from examples/basic.js

cd acs-node-sdk/examples
export ACS_APPKEY=YOUR_ACS_TEST_APPKEY
node basic.js

ACS Node SDK Example on Node.ACS

There is another example for ACS Node SDK to show how to run on Node.ACS as a service. Make sure you have installed Node.ACS command line tool first:

sudo npm -g install acs

Then you can try:

cd acs-node-sdk/examples/over_nodeacs
# Update config.json to fill in your ACS app key
vi config.json
acs run

Open another session and try:

curl -b cookie.txt -c cookie.txt -X POST -F "login=YOUR_USERNAME" -F "password=YOUR_PASSWORD" http://localhost:8080/login
curl -b cookie.txt -c cookie.txt -X GET http://localhost:8080/showMe

ACS Node SDK Basic Usage

Use ACS Node SDK directly

var acsApp = require('acs-node')('Your_ACS_APPKEY');
// Cookie string can be passed into too
// var acsApp = require('acs-node')('Your_ACS_APPKEY', {
//     apiEntryPoint: 'https://api.cloud.appcelerator.com',
//     cookieString: req.session.cookieString
// });
acsApp.usersLogin({
    login: ACS_USERNAME,
    password: ACS_PASSWORD
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log('Logged in user: %j', result.body);
    acsApp.setSessionByCookieString(result.cookieString);
    acsApp.usersShowMe(function(err, result) {
        if (err) {
            console.error(err);
            return;
        }
        console.log('Show user: %j', result.body);
    });
});

Use ACS Node SDK inner express or http/https NodeJS module

// HTTP call 1 with cookie:
var acsApp = require('acs-node')('Your_ACS_APPKEY');
acsApp.usersLogin(ACS_APPKEY, {
    login: req.body.login,
    password: req.body.password,
    req: req,
    res: res
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    res.end(result.body);
});

// HTTP call 2 with cookie, after HTTP call 1:
var acsApp = require('acs-node')('Your_ACS_APPKEY');
acsApp.usersShowMe(ACS_APPKEY, {
    req: req,
    res: res
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    res.end(result.body);
});

General RestAPI call

var acsApp = require('acs-node')('Your_ACS_APPKEY');
acsApp.post(ACS_APPKEY, '/v1/users/login.json', {
    login: ACS_USERNAME,
    password: ACS_PASSWORD
}, function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log('ACS returned body: %j', result.body);
    console.log('Cookie string returned: %s', result.cookieString);
    acsApp.setSessionByCookieString(result.cookieString);
    acsApp.get(ACS_APPKEY, '/v1/users/show/me.json', function(err, result) {
        if (err) {
            console.error(err);
            return;
        }
        console.log('ACS returned user: %j', result.body);
    });
});

appcelerator.acs-node-sdk's People

Contributors

billwang avatar ins429 avatar jhaynie avatar peri18 avatar realpaul avatar

Watchers

 avatar  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.