Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ciscospark

Package Overview
Dependencies
Maintainers
6
Versions
252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ciscospark

SDK for Cisco Spark

  • 0.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
decreased by-63.14%
Maintainers
6
Weekly downloads
 
Created
Source

CiscoSpark

SDK for Cisco Spark

Installation

npm install --save ciscospark

A Note on Browsers

Ciscospark is fully browser compatible but we don't distribute a browserified bundle at this time; you'll need to build the bundle yourself. We use browserify internally and webpack should work as well.

Getting Started

The examples below have both ES5 and ES6 variations. The ES6 examples will require you to build your project using babel. The ES5 examples should be directly runnable.

The quickest way to get started is to set your access token as an environment variable:

import assert from 'assert';
import spark from 'ciscospark';

assert(process.env.CISCOSPARK_ACCESS_TOKEN);
(async function() {
 try {
   let room = await spark.rooms.create({title: 'My First Room'});
   let message = await spark.messages.create({
     text: 'Howdy!',
     roomId: room.id
   });
 }
 catch(error) {
   console.error(error.stack);
   process.exit(1);
 }
}());


var ciscospark = require('ciscospark');

assert(process.env.CISCOSPARK_ACCESS_TOKEN);
return ciscspark.rooms.create({title: 'My First Room'})
  .then(function(room) {
    return ciscospark.messages.create({
      text: 'Howdy!',
      roomId: room.id
    });
  })
  .catch(function(reason) {
    console.error(reason);
    process.exit(1);
  });


Refresh Tokens

For long-running use cases, you'll need to provide a refresh token, client id, and client secret:

import assert from 'assert';
import spark from 'ciscospark';

assert(process.env.CISCOSPARK_ACCESS_TOKEN);
assert(process.env.CISCOSPARK_REFRESH_TOKEN);
assert(process.env.CISCOSPARK_CLIENT_ID);
assert(process.env.CISCOSPARK_CLIENT_SECRET);
(async function run() {
  try {
    let room = await spark.rooms.create({title: 'My First Room'});
    let message = await spark.messages.create({
      text: 'Howdy!',
      roomId: room.id
    });
  }
  catch(error) {
    console.error(error.stack);
    process.exit(1);
  }
}());


Runtime Configuration

While environment variables are handy for development, they don't really help you write an app for lots of users. You can pass credentials to the spark using init.

import spark from 'ciscospark';
import {getAcessTokenFromSomewhereElse} from '../../../lib/my-auth-module';


(async function run() {
  try {
    const spark2 = spark.init({
      credentials: {
        access_token: getAcessTokenFromSomewhereElse()
      }
    });
    const room = await spark2.rooms.create({title: `My First Room`});
    await spark.messages.create({
      text: `Howdy!`,
      roomId: room.id
    });
  }
  catch(error) {
    console.error(error.stack);
    process.exit(1);
  }
}());


OAuth

OAuth is baked right into spark so you don't need to figure it out.

To kick off an OAuth login, simply call spark.authenticate() which will direct the current app to our login page.

import spark from 'ciscospark';

spark.authenticate();


To refresh an access token, call spark.authorize(). (Note: this should generally happen for you automatically).

import spark from 'ciscospark';

spark.authorize();


Messages

Messages are how people communicate in rooms. Each message timestamped and represented in Spark as a distinct block of content. Messages can contain plain text and a single file attachment. See the Message Attachments Guide for a list of supported media types.

create

Post a new message and/or media content into a room.

Parameters

  • message Types~Message

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  let room = await ciscospark.rooms.create({title: `Messages Example`});
  let message = await ciscospark.messages.create({
    text: `Howdy!`,
    roomId: room.id
  });
  assert(message.id);
  assert(message.personId);
  assert(message.personEmail);
  assert(message.roomId);
  assert(message.created);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

return ciscospark.rooms.create({title: `Messages Example`})
  .then(function(room) {
    return ciscospark.messages.create({
      text: 'Howdy!',
      roomId: room.id
    });
  })
  .then(function(message) {
    assert(message.id);
    assert(message.personId);
    assert(message.personEmail);
    assert(message.roomId);
    assert(message.created);
  });


Returns Promise<Types~Message>

get

Returns a single message.

Parameters

  • message Types~Room or string

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Messages Example`});
  const message = await ciscospark.messages.create({
    text: `Howdy!`,
    roomId: room.id
  });
  const message2 = await ciscospark.messages.get(message.id);
  assert.deepEqual(message2, message);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var message;
return ciscospark.rooms.create({title: `Messages Example`})
  .then(function(room) {
    return ciscospark.messages.create({
      text: `Howdy!`,
      roomId: room.id
    });
  })
  .then(function(m) {
    message = m;
    return ciscospark.messages.get(message.id);
  })
  .then(function(message2) {
    assert.deepEqual(message2, message);
  });


Returns Promise<Types~Message>

list

Returns a list of messages. In most cases the results will only contain messages posted in rooms that the authentiated user is a member of.

Parameters

  • options Object
    • options.roomId string
    • options.max number

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Messages Example`});
  const message1 = await ciscospark.messages.create({
    text: `Howdy!`,
    roomId: room.id
  });
  const message2 = await ciscospark.messages.create({
    text: `How are you?`,
    roomId: room.id
  });

  const messages = Array.from(await ciscospark.messages.list({roomId: room.id}));
  assert.equal(messages.length, 2);
  assert.equal(messages[0].id, message2.id);
  assert.equal(messages[1].id, message1.id);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var message1, message2, room;
return ciscospark.rooms.create({title: `Messages Example`})
  .then(function(r) {
    room = r;
    return ciscospark.messages.create({
      text: `Howdy!`,
      roomId: room.id
    });
  })
  .then(function(m) {
    message1 = m;
    return ciscospark.messages.create({
      text: `How are you?`,
      roomId: room.id
    });
  })
  .then(function(m) {
    message2 = m;
    return ciscospark.messages.list({roomId: room.id});
  })
  .then(function(messages) {
    assert.equal(messages.length, 2);
    assert.equal(messages.items[0].id, message2.id);
    assert.equal(messages.items[1].id, message1.id);
  });


Returns Promise<Page<Types~Message>>

remove

Deletes a single message. Deleting a message will notify all members of the room that the authenticated user deleted the message. Generally, users can only delete their own messages except for the case of Moderated Rooms and Org Administrators.

Parameters

  • message Types~Message or uuid

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Messages Example`});
  const message = await ciscospark.messages.create({
    text: `Howdy!`,
    roomId: room.id
  });
  await ciscospark.messages.create({
    text: `How are you?`,
    roomId: room.id
  });
  await ciscospark.messages.remove(message);
  const messages = await ciscospark.messages.list({roomId: room.id});
  assert.equal(messages.length, 1);
  assert(messages.items[0].id !== message.id);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var message1, message2, room;
return ciscospark.rooms.create({title: `Messages Example`})
  .then(function(r) {
    room = r;
    return ciscospark.messages.create({
      text: `Howdy!`,
      roomId: room.id
    });
  })
  .then(function(m) {
    message1 = m;
    return ciscospark.messages.create({
      text: `How are you?`,
      roomId: room.id
    });
  })
  .then(function(m) {
    message2 = m;
    return ciscospark.messages.remove(message1);
  })
  .then(function() {
    return ciscospark.messages.list({roomId: room.id});
  })
  .then(function(messages) {
    assert.equal(messages.items.length, 1);
    assert(messages.items[0].id !== message1.id);
  });


Returns Promise }

Webhooks

A webhook notifies an application when an event for which the application is registered has occurred.

create

Posts a webhook.

Parameters

  • webhook Types~Webhook

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Webhook Example`});
  const webhook = await ciscospark.webhooks.create({
    resource: `messages`,
    event: `created`,
    filter: `roomId=${room.id}`,
    targetUrl: `https://example.com/webhook`,
    name: `Test Webhook`
  });
  assert(webhook.id);
  assert(webhook.resource);
  assert(webhook.event);
  assert(webhook.filter);
  assert(webhook.targetUrl);
  assert(webhook.name);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

return ciscospark.rooms.create({title: 'Webhook Example'})
  .then(function(room) {
    return ciscospark.webhooks.create({
      resource: 'messages',
      event: 'created',
      filter: 'roomId=' + room.id,
      targetUrl: 'https://example.com/webhook',
      name: 'Test Webhook'
    });
  })
  .then(function(webhook) {
    assert(webhook.id);
    assert(webhook.resource);
    assert(webhook.event);
    assert(webhook.filter);
    assert(webhook.targetUrl);
    assert(webhook.name);
  });


Returns Promise<Webhook>

get

Shows details for a webhook.

Parameters

  • webhook Webhook or string

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Webhook Example`});
  const webhook = await ciscospark.webhooks.create({
    resource: `messages`,
    event: `created`,
    filter: `roomId=${room.id}`,
    targetUrl: `https://example.com/webhook`,
    name: `Test Webhook`
  });
  const webhook2 = await ciscospark.webhooks.get(webhook.id);
  assert.deepEqual(webhook2, webhook);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var webhook;
return ciscospark.rooms.create({title: 'Webhook Example'})
  .then(function(room) {
    return ciscospark.webhooks.create({
      resource: 'messages',
      event: 'created',
      filter: 'roomId=' + room.id,
      targetUrl: 'https://example.com/webhook',
      name: 'Test Webhook'
    });
  })
  .then(function(w) {
    webhook = w;
    return ciscospark.webhooks.get(webhook.id);
  })
  .then(function(webhook2) {
    assert.deepEqual(webhook2, webhook);
  });


Returns Promise<Array<Webhook>>

list

Lists all webhooks.

Parameters

  • options Object
    • options.max integer Limit the maximum number of webhooks in the response.

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Webhook Example`});
  const webhook = await ciscospark.webhooks.create({
    resource: `messages`,
    event: `created`,
    filter: `roomId=${room.id}`,
    targetUrl: `https://example.com/webhook`,
    name: `Test Webhook`
  });
  const webhooks = Array.from(await ciscospark.webhooks.list());
  assert.equal(webhooks.filter((w) => {
    return w.id === webhook.id;
  }).length, 1);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room, webhook;
return ciscospark.rooms.create({title: 'Webhook Example'})
  .then(function(r) {
    room = r;
    return ciscospark.webhooks.create({
      resource: 'messages',
      event: 'created',
      filter: 'roomId=' + room.id,
      targetUrl: 'https://example.com/webhook',
      name: 'Test Webhook'
    });
  })
  .then(function(w) {
    webhook = w;
    return ciscospark.webhooks.list();
  })
  .then(function(webhooks) {
    assert.equal(webhooks.items.filter(function(w) {
      return w.id === webhook.id;
    }).length, 1);
  });


Returns Promise<Webhook>

remove

Delete a webhook.

Parameters

  • webhook Webhook or string

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Webhook Example`});
  const webhook = await ciscospark.webhooks.create({
    resource: `messages`,
    event: `created`,
    filter: `roomId=${room.id}`,
    targetUrl: `https://example.com/webhook`,
    name: `Test Webhook`
  });
  await ciscospark.webhooks.remove(webhook);
  const webhooks = Array.from(await ciscospark.webhooks.list());
  assert.equal(webhooks.filter((w) => w.id === webhook.id).length, 0);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room, webhook;
return ciscospark.rooms.create({title: 'Webhook Example'})
  .then(function(r) {
    room = r;
    return ciscospark.webhooks.create({
      resource: 'messages',
      event: 'created',
      filter: 'roomId=' + room.id,
      targetUrl: 'https://example.com/webhook',
      name: 'Test Webhook'
    });
  })
  .then(function(w) {
    webhook = w;
    return ciscospark.webhooks.remove(webhook);
  })
  .then(function() {
    return ciscospark.webhooks.list();
  })
  .then(function(webhooks) {
    assert.equal(webhooks.items.filter(function(w) {
      return w.id === webhook.id;
    }).length, 0);
  });


Returns Promise

update

Update a webhook.

Parameters

  • webhook Webhook

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Webhook Example`});
  let webhook = await ciscospark.webhooks.create({
    resource: `messages`,
    event: `created`,
    filter: `roomId=${room.id}`,
    targetUrl: `https://example.com/webhook`,
    name: `Test Webhook`
  });
  webhook.targetUrl = `https://example.com/webhook/newtarget`;
  await ciscospark.webhooks.update(webhook);
  webhook = await ciscospark.webhooks.get(webhook);
  assert.equal(webhook.targetUrl, `https://example.com/webhook/newtarget`);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var webhook;
return ciscospark.rooms.create({title: 'Webhook Example'})
  .then(function(room) {
    return ciscospark.webhooks.create({
      resource: 'messages',
      event: 'created',
      filter: 'roomId=' + room.id,
      targetUrl: 'https://example.com/webhook',
      name: 'Test Webhook'
    });
  })
  .then(function(w) {
    webhook = w;
    webhook.targetUrl = 'https://example.com/webhook/newtarget';
    return ciscospark.webhooks.update(webhook);
  })
  .then(function() {
    return ciscospark.webhooks.get(webhook);
  })
  .then(function(webhook) {
    assert.equal(webhook.targetUrl, 'https://example.com/webhook/newtarget');
  });


Returns Promise<Webhook>

Rooms

Rooms are virtual meeting places for getting stuff done. This resource represents the room itself. Check out the Memberships API to learn how to add and remove people from rooms and the Messages API for posting and managing content.

create

Creates a new room. The authenticated user is automatically added as a member of the room. See the @{link Memberships} to learn how to add more people to the room. Membership

Parameters

  • room Types~Room

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Rooms Example`});
  assert(room.id);
  assert(room.title);
  assert(room.created);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

return ciscospark.rooms.create({title: 'Rooms Example'})
  .then(function(room) {
    assert(room.id);
    assert(room.title);
    assert(room.created);
  });


Returns Promise<Types~Room>

get

Returns a single room.

Parameters

  • room Types~Room or string
  • options Object
    • options.includeSipAddress Object To show the SIP address for the room in the response, set this value to true. A session initiation protocol (SIP) address is a URI that addresses a specific telephone extension on a voice over IP (VOIP) system.

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  let room = await ciscospark.rooms.create({title: `Rooms Example`});
  let room2 = await ciscospark.rooms.get(room.id);
  assert.equal(room2.id, room.id);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room;
return ciscospark.rooms.create({title: `Rooms Example`})
  .then(function(r) {
    room = r;
    return ciscospark.rooms.get(room.id);
  })
  .then(function(room2) {
    assert.equal(room2.id, room.id);
  });


Returns Promise<Types~Room>

list

Returns a list of rooms. In most cases the results will only contain rooms that the authentiated user is a member of.

Parameters

  • options Object
    • options.max Object Limit the maximum number of rooms in the response.
    • options.includeSipAddress Object To show the SIP address for the room in the response, set this value to true. A session initiation protocol (SIP) address is a URI that addresses a specific telephone extension on a voice over IP (VOIP) system.

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const createdRooms = await Promise.all([
    await ciscospark.rooms.create({title: `Rooms Example 1`}),
    await ciscospark.rooms.create({title: `Rooms Example 2`}),
    await ciscospark.rooms.create({title: `Rooms Example 3`})
  ]);

  const rooms = await ciscospark.rooms.list({max: 3});
  assert(rooms.length === 3);
  for (const room of rooms) {
    assert(createdRooms.find((r) => r.id === room.id));
  }
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var createdRooms;
return Promise.all([
  ciscospark.rooms.create({title: 'Rooms Example 1'}),
  ciscospark.rooms.create({title: 'Rooms Example 2'}),
  ciscospark.rooms.create({title: 'Rooms Example 3'})
])
  .then(function(r) {
    createdRooms = r;
    return ciscospark.rooms.list({max: 3});
  })
  .then(function(rooms) {
    assert(rooms.length === 3);
    for (var i = 0; i < rooms.items.length; i++) {
      assert(createdRooms.filter(function(room) {
        return room.id === rooms.items[i].id;
      }).length === 1);
    }
  });


Returns Promise<Page<Types~Room>>

remove

Deletes a single room.

Parameters

  • room Types~Room or string

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  let room = await ciscospark.rooms.create({title: `Rooms Example`});
  await ciscospark.rooms.remove(room.id);
  try {
    room = await ciscospark.rooms.get(room.id);
    assert(false, `the previous line should have failed`);
  }
  catch(reason) {
    assert.equal(reason.statusCode, 404);
  }
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room;
return ciscospark.rooms.create({title: 'Rooms Example'})
  .then(function(r) {
    room = r;
    return ciscospark.rooms.remove(room.id);
  })
  .then(function() {
    return ciscospark.rooms.get(room.id);
  })
  .then(function() {
    assert(false, 'the previous get should have failed');
  })
  .catch(function(reason) {
    assert.equal(reason.statusCode, 404);
  });


Returns Promise

update

Used to update a single room's properties.

Parameters

  • room Types~Room

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  let room = await ciscospark.rooms.create({title: `Rooms Example`});
  room.title = `Rooms Example (Updated Title)`;
  await ciscospark.rooms.update(room);
  room = await ciscospark.rooms.get(room.id);
  assert.equal(room.title, `Rooms Example (Updated Title)`);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room;
return ciscospark.rooms.create({title: 'Rooms Example'})
  .then(function(r) {
    room = r;
    room.title = 'Rooms Example (Updated Title)';
    return ciscospark.rooms.update(room);
  })
  .then(function() {
    return ciscospark.rooms.get(room.id);
  })
  .then(function(room) {
    assert.equal(room.title, 'Rooms Example (Updated Title)');
  });


Returns Promise<Types~Room>

Memberships

create

Adds a person to a room. The person can be added by ID (personId) or by Email Address (personEmail). The person can be optionally added to the room as a moderator.

Parameters

  • membership Types~Membership

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Memberships Example`});
  const membership = await ciscospark.memberships.create({
   personEmail: `alice@example.com`,
   roomId: room.id
  });
  assert(membership.id);
  assert(membership.roomId);
  assert(membership.personId);
  assert(membership.personEmail);
  assert(`isModerator` in membership);
  assert(`isMonitor` in membership);
  assert(membership.created);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

return ciscospark.rooms.create({title: `Rooms Example`})
  .then(function(room) {
    return ciscospark.memberships.create({
     personEmail: `alice@example.com`,
     roomId: room.id
   });
  })
  .then(function(membership) {
    assert(membership.id);
    assert(membership.roomId);
    assert(membership.personId);
    assert(membership.personEmail);
    assert(`isModerator` in membership);
    assert(`isMonitor` in membership);
    assert(membership.created);
  });


Returns Promise<Types~Membership>

get

Returns a single membership.

Parameters

  • membership Types~Membership or uuid

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
 const room = await ciscospark.rooms.create({title: `Memberships Example`});
 const membership = await ciscospark.memberships.create({
   personEmail: `alice@example.com`,
   roomId: room.id
 });
 const membership2 = await ciscospark.memberships.get(membership.id);
 assert.deepEqual(membership2, membership);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var membership;
return ciscospark.rooms.create({title: 'Memberships Example'})
  .then(function(room) {
    return ciscospark.memberships.create({
      personEmail: 'alice@example.com',
      roomId: room.id
    });
  })
  .then(function(m) {
    membership = m;
    return ciscospark.memberships.get(m.id);
  })
  .then(function(m) {
    assert.deepEqual(m, membership);
  });


Returns Promise<Types~Membership>

list

Returns a list of memberships. In most cases the results will only contain rooms that the authentiated user is a member of. You can filter the results by room to list people in a room or by person to find rooms that a specific person is a member of.

Parameters

  • options Object
    • options.personId string
    • options.personEmail string
    • options.roomId string
    • options.max number

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Memberships Example`});
  await ciscospark.memberships.create({
   personEmail: `alice@example.com`,
   roomId: room.id
  });
  const memberships = await ciscospark.memberships.list({roomId: room.id});
  assert.equal(memberships.length, 2);
  for (const membership of memberships) {
    assert.equal(membership.roomId, room.id);
  }
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room;
return ciscospark.rooms.create({title: `Memberships Example`})
  .then(function(r) {
    room = r;
    return ciscospark.memberships.create({
     personEmail: `alice@example.com`,
     roomId: room.id
    });
  })
  .then(function() {
    return ciscospark.memberships.list({roomId: room.id})
  })
  .then(function(memberships) {
    assert.equal(memberships.length, 2);
    for (var i = 0; i < memberships.length; i++) {
      assert.equal(memberships.items[i].roomId, room.id);
    }
  });


Returns Promise<Page<Types~Membership>>

remove

Deletes a single membership.

Parameters

  • membership Types~Membership or uuid

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Memberships Example`});
  const membership = await ciscospark.memberships.create({
    personEmail: `alice@example.com`,
    roomId: room.id
  });
  let memberships = await ciscospark.memberships.list({roomId: room.id});
  assert.equal(memberships.length, 2);
  await ciscospark.memberships.remove(membership);
  memberships = await ciscospark.memberships.list({roomId: room.id});
  assert.equal(memberships.length, 1);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var membership, room;
return ciscospark.rooms.create({title: `Memberships Example`})
  .then(function(r) {
    room = r;
    return ciscospark.memberships.create({
     personEmail: `alice@example.com`,
     roomId: room.id
    });
  })
  .then(function(m) {
    membership = m;
    return ciscospark.memberships.list({roomId: room.id});
  })
  .then(function(memberships) {
    assert.equal(memberships.length, 2);
    return ciscospark.memberships.remove(membership);
  })
  .then(function() {
    return ciscospark.memberships.list({roomId: room.id})
  })
  .then(function(memberships) {
    assert.equal(memberships.length, 1);
  });



Returns Promise

update

Used to update a single membership's properties

Parameters

  • membership Types~Membership or uuid

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `Memberships Example`});
  const memberships = await ciscospark.memberships.list({roomId: room.id});
  let membership = memberships.items[0];
  assert.equal(membership.isModerator, false);
  membership.isModerator = true;
  await ciscospark.memberships.update(membership);
  membership = await ciscospark.memberships.get(membership.id);
  assert.equal(membership.isModerator, true);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var membership, room;
return ciscospark.rooms.create({title: `Memberships Example`})
  .then(function(r) {
    room = r;
    return ciscospark.memberships.list({roomId: room.id});
  })
  .then(function(memberships) {
    membership = memberships.items[0];
    assert.equal(membership.isModerator, false);
    membership.isModerator = true;
    return ciscospark.memberships.update(membership)
  })
  .then(function() {
    return ciscospark.memberships.get(membership.id);
  })
  .then(function(membership) {
    assert.equal(membership.isModerator, true);
  });



Returns Promise<Types~Membership>

People

get

Returns a single person by ID

Parameters

  • person Types~Person or uuid

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `People Example`});
  const membership = await ciscospark.memberships.create({
    personEmail: `alice@example.com`,
    roomId: room.id
  });
  const alice = await ciscospark.people.get(membership.personId);
  assert(alice.id);
  assert(Array.isArray(alice.emails));
  assert(alice.emails.includes(`alice@example.com`));
  assert(alice.displayName);
  assert(alice.created);
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

return ciscospark.rooms.create({title: 'People Example'})
  .then(function(room) {
    return ciscospark.memberships.create({
      personEmail: 'alice@example.com',
      roomId: room.id
    });
  })
  .then(function(membership) {
    return ciscospark.people.get(membership.personId);
  })
  .then(function(alice) {
    assert(alice.id);
    assert(Array.isArray(alice.emails));
    assert.equal(alice.emails.filter(function(email) {
      return email === 'alice@example.com';
    }).length, 1);
    assert(alice.displayName);
    assert(alice.created);
  });


Returns Promise<Types~Person>

list

Returns a list of people

Parameters

  • options Object
    • options.email email Returns people with an email that contains this string
    • options.name string Returns people with a name that contains this string

Examples

import assert from 'assert';
import ciscospark from 'ciscospark';

return (async function() {
  const room = await ciscospark.rooms.create({title: `People Example`});
  const aliceMembership = await ciscospark.memberships.create({
    personEmail: `alice@example.com`,
    roomId: room.id
  });
  const bobMembership = await ciscospark.memberships.create({
    personEmail: `bob@example.com`,
    roomId: room.id
  });

  let people = await ciscospark.people.list({email: `alice@example.com`});
  assert.equal(people.length, 1);
  for (const person of people) {
    if (person.emails.includes(`alice@example.com`)) {
      assert(person.id);
      assert(Array.isArray(person.emails));
      assert(person.displayName);
      assert(person.created);
    }
  }
}());


'use strict';

var assert = require('assert');
var ciscospark = require('ciscospark').default;

var room;
return ciscospark.rooms.create({title: 'People Example'})
  .then(function(r) {
    room = r;
    return ciscospark.memberships.create({
      personEmail: 'alice@example.com',
      roomId: room.id
    });
  })
  .then(function() {
    return ciscospark.memberships.create({
      personEmail: 'bob@example.com',
      roomId: room.id
    });
  })
  .then(function() {
    return ciscospark.people.list({email: 'alice@example.com'});
  })
  .then(function(people) {
    assert.equal(people.length, 1);
    var person = people.items[0];
    assert(person.id);
    assert(Array.isArray(person.emails));
    assert(person.displayName);
    assert(person.created);
  });


Returns Promise<Page<Types~Person>>

Types~Membership

Properties

  • id uuid Unique identifier for the membership
  • roomId string The room ID
  • personId uuid The person ID
  • personEmail email The email address of the person / room member
  • isModerator boolean Indicates whether the specified person should be a room moderator.
  • isMonitor boolean Indicates whether the specified member is a room monitor.
  • created isoDate The date and time that this membership was created.

Types~Message

Properties

  • id uuid (server generated) Unique identifier for the message
  • personId uuid The ID for the author of the messasge
  • personEmail email The email for the author of the messasge
  • roomId string The message posted to the room in plain text
  • created isoDate (server generated)The source URLs for the message attachment. See the {@link Content & Attachments{ Guide for a list of supported media types.

Types~Person

Properties

  • id uuid Unique identifier for the person
  • emails Array<email> Email addresses of the person
  • displayName string Display name of the person
  • created isoDate The date and time that the person was created

Types~Room

Properties

  • id string (server generated) Unique identifier for the room
  • title string The display name for the room. All room members will see the title so make it something good
  • created isoDate (server generated) The date and time that the room was created

Types~Webhook

Properties

  • id string The unique ID for the webhook.
  • resource string The resource type for the webhook.
  • event string The event type for the webhook.
  • filter string The filter that defines the webhook scope.
  • targetUrl string The URL that receives POST requests for each event.
  • name string A user-friendly name for this webhook.

FAQs

Package last updated on 25 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc