Cisco Spark

SDK for Java

Integrate Cisco Spark into your Java applications quickly

Features

Integrate the Java SDK into server-side applications and use Spark features directly in your Java applications.

Getting Started Guide

This guide will get you up-and-running with the Spark Java SDK.

Overview

  • Create Spark rooms
  • Post messages

Requirements

  • Java 1.6 or greater
  • This SDK requires the spark:all scope

Step 1: Register for a Cisco Spark Account

Before using the SDK, you will need a Spark account and a developer access token. If you haven't already, head on over to Cisco Spark to create an account.

Once you have an account, log into this site to get your developer access token. You will need this token to authenticate API requests from the SDK.

Step 2: Install the Java SDK

The Java SDK is available on GitHub. Clone the repository and include the source files in your Maven project.

Step 3: Use the Java SDK

Create an Example Class

For this example, we'll create a very simple Example class and set the developer access token. You'll need this token to initialize the client.

import com.ciscospark.*;
import java.net.URI;

class Example {
  public static void main(String[] args) {
    // To obtain a developer access token, visit http://developer.ciscospark.com
    String accessToken = "$YOUR_DEVELOPER_TOKEN";

Initialize the Spark Client

Initialize the client and set the endpoint to the current Spark API.

// Initialize the client
Spark spark = Spark.builder()
  .baseUrl(URI.create("https://api.ciscospark.com/v1"))
  .accessToken(accessToken)
  .build();

Create a New Space

Let's create a space. For now this space will only have you in it. You can always add more people later.

// Create a new room
Room room = new Room();
room.setTitle("Hello World");
room = spark.rooms().post(room);

Post a Message

Now that we have a new space, let's post a message to it.

// Post a text message to the room
Message message = new Message();
message.setRoomId(room.getId());
message.setText("Hello World!");
spark.messages().post(message);

Full Code

Compile and run the new class to see the SDK in action. Log into Spark through one of the clients to see your new room and new message!

Here's the full code for the example class:

import com.ciscospark.*;
import java.net.URI;

class Example {
  public static void main(String[] args) {
    // To obtain a developer access token, visit http://developer.ciscospark.com
    String accessToken = "$YOUR_DEVELOPER_TOKEN";

    // Initialize the client
    Spark spark = Spark.builder()
      .baseUrl(URI.create("https://api.ciscospark.com/v1"))
      .accessToken(accessToken)
      .build();

    // Create a new room
    Room room = new Room();
    room.setTitle("Hello World");
    room = spark.rooms().post(room);

    // Post a text message to the room
    Message message = new Message();
    message.setRoomId(room.getId());
    message.setText("Hello World!");
    spark.messages().post(message);
  }
}