tran2 / spark-js-sdk

Home Page:https://ciscospark.github.io/spark-js-sdk/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spark-js-sdk

npm license Build status

The Cisco Spark JavaScript SDK

This is a monorepo containing all officially maintained Cisco Spark JavaScript SDK modules in the same repo.

ciscospark is a collection of node modules targeting our external APIs.

Table of Contents

Install

We test against the current LTS version of Node.js (6.10) but the SDK should work with any supported version of Node.js.

To install the latest stable version from NPM:

npm install --save ciscospark

Usage

To use the SDK, you will need Cisco Spark credentials. If you do not already have a Cisco Spark account, visit Spark for Developers to create your account and retrieve your access token.

See the detailed docs for more usage examples.

Node.js

You will need to set the following environment variable:

  • CISCOSPARK_ACCESS_TOKEN
const assert = require(`assert`);
assert(process.env.CISCOSPARK_ACCESS_TOKEN, 'This example assumes you have set your access token as an environment variable');
const ciscospark = require(`ciscospark`);
ciscospark.rooms.create({title: `My First Room`})
  .then((room) => {
    return Promise.all([
      ciscospark.memberships.create({
        roomId: room.id,
        personEmail: `alice@example.com`
      }),
      ciscospark.memberships.create({
        roomId: room.id,
        personEmail: `bob@example.com`
      }),
    ])
      .then(() => ciscospark.messages.create({
        markdown: `**Hi Everyone**`,
        roomId: room.id
      }));
  });

Browsers

We do not provide a pre-built version of ciscospark.

If you've already got a commonjs or es6 build process in place, you can simply use const ciscospark = require('ciscospark').

If you need to load ciscospark via a script tag, you will need to build it first:

npm install ciscospark
npm install -g browserify
echo "window.ciscospark = require('ciscospark')" > ./index.js
browserify index.js > bundle.js

In-browser usage is pretty much the same as Node.js usage, with the addition of handling the user authentication flow for you. See the guide on the docs site for more information.

Samples

Sample code can be found in packages/node_modules/*. You can run them yourself with the following commands:

Note: this installs all of the sdk's tooling dependencies, so you'll need libgcrypt and (possibly) graphicsmagick. On a mac, you can install these with brew install graphicsmagick libgrcrypt.

git clone git@github.com:ciscospark/spark-js-sdk.git
cd spark-js-sdk
npm install
npm run serve:samples

You'll be able to load the samples by visiting https://localhost:8000/packages/node_modules/<PACKAGE NAME>.

Available Samples

  • Single Party Calling: local app | code

Contribute

Pull requests welcome. Please see CONTRIBUTING.md for more details about building the packages and submitting pull requests for suggested changes.

License

© 2016-2017 Cisco Systems, Inc. and/or its affiliates. All Rights Reserved.

See LICENSE for details.

About

https://ciscospark.github.io/spark-js-sdk/

License:MIT License


Languages

Language:JavaScript 83.4%Language:Shell 16.6%