amigocloud/amigocloud-js

语言: JavaScript

git: https://github.com/amigocloud/amigocloud-js

FriendCloud Javascript库
AmigoCloud Javascript Library
README.md (中文)

JS-amigocloud

AmigoCloud的简单JavaScript API。

安装

安装为凉亭包:

..

bower install amigocloud-js

依赖

  • | socket.io | _:用于通过websockets侦听服务器事件。

快速开始

认证 ~~~~~~

安装完库后,您需要做的就是 开始使用ACCESS TOKEN对服务器进行身份验证:

.. code :: javascript

L.amigo.auth.setToken(ACCESS_TOKEN);

在进行身份验证后,Amigo.user将设置在Amigo对象中。它包含与经过身份验证的用户相关的所有信息(从/ me端点返回)。

要求 ~~~~

接下来,您将要实际使用我们服务器中的数据。使用L.amigo.utils中的端点,您可以开始制作自己的请求并操纵数据。

.. code :: javascript

var data = {
    'param1': 'value1',
    'param2': 'value2'
}
L.amigo.utils.get(someUrl); //will do a simple get request
L.amigo.utils.get(someOtherUrl, data). // the second parameter is optional
    then(function (responseData) {
        // you can manipulate the data that comes back from hitting someOtherUrl with the GET method.
    });

对于POST请求,请使用以下函数(这将创建一个新项目):

.. code :: javascript

// make sure your access token allows you to do this operation
L.amigo.utils.post('/me/projects', { name: 'new dataset' }).  //will do a POST request
    then(function (responseData) {
        // you can still manipulate the return data. In this case, it's the new project's information
    });

.then()方法绑定一个回调,以便在响应从服务器返回时运行。唯一的论点是响应数据。

的WebSockets ~~

在继续阅读之前,请务必阅读有关我们的websocket活动的帮助页面<http://help.amigocloud.com/hc/en-us/articles/204246154> __。

要开始侦听websocket事件,请使用以下函数:

.. code :: javascript

// We recomend excecuting this code only once
L.amigo.auth.setToken(ACCESS_TOKEN); // set the access token in auth
L.amigo.events.startListening(); // start listening events

在开始监听事件之后,您可能希望实际将某些回调绑定到特定事件:

.. code :: javascript

L.amigo.events.on('dataset:creation_succeeded', function (data) {
    // do something when a dataset is created.
});

.. | socket.io | replace :: socket.io .. _socket.io:http://socket.io

FriendCloud 2015

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

amigocloud-js

A simple JavaScript API for AmigoCloud.

Installation

Install as a bower package:

..

bower install amigocloud-js

Dependencies

  • |socket.io|_: Used to listen to server events through websockets.

Quick Start

Authentication
~~~~~~

Once you have installed the library, all you need to do to
get going is authenticate with the server using an ACCESS TOKEN:

.. code:: javascript

L.amigo.auth.setToken(ACCESS_TOKEN);

After authenticating, Amigo.user will be set in the Amigo object. This contains all of the information relevant to the authenticated user (returned from the /me endpoint).

Requests
~~~~

Next you'll want to actually use data from our server. Using the endpoints found in L.amigo.utils you can start making your own requests and manipulating data.

.. code:: javascript

var data = {
    'param1': 'value1',
    'param2': 'value2'
}
L.amigo.utils.get(someUrl); //will do a simple get request
L.amigo.utils.get(someOtherUrl, data). // the second parameter is optional
    then(function (responseData) {
        // you can manipulate the data that comes back from hitting someOtherUrl with the GET method.
    });

For POST requests, use the following function (this will create a new project):

.. code:: javascript

// make sure your access token allows you to do this operation
L.amigo.utils.post('/me/projects', { name: 'new dataset' }).  //will do a POST request
    then(function (responseData) {
        // you can still manipulate the return data. In this case, it's the new project's information
    });

The .then() method binds a callback to be run when the response comes back from the server. Its only argument is the response data.

Websockets
~~

Make sure to read our help page about our websocket events <http://help.amigocloud.com/hc/en-us/articles/204246154>__ before continue reading.

To start listening to websocket events, use the following functions:

.. code:: javascript

// We recomend excecuting this code only once
L.amigo.auth.setToken(ACCESS_TOKEN); // set the access token in auth
L.amigo.events.startListening(); // start listening events

After starting to listen events, you might want to actually bind some callbacks to specific events:

.. code:: javascript

L.amigo.events.on('dataset:creation_succeeded', function (data) {
    // do something when a dataset is created.
});

.. |socket.io| replace:: socket.io
.. _socket.io: http://socket.io

AmigoCloud 2015