Skip to content

Repository files navigation

license

Introduction

This Java SDK is a Java library for consuming Cisco Webex's RESTful APIs. Please visit us at https://developer.webex.com/ for more information about Cisco Webex for Developers.

Why spark-java-sdk? : A rebranding took place in 2018, some time after this SDK was created, that renamed Cisco Spark to Cisco Webex.

Prerequisites

Clone the repository

git clone git@github.com:webex/spark-java-sdk.git

Run maven through CLI or your favourite IDE

mvn install

Usage

To start, call the Spark builder with your developer token (can be retrieved from https://developer.webex.com).

StringaccessToken = "<<secret>>";
Sparkspark = Spark.builder()
.baseUrl(URI.create("https://api.ciscospark.com/v1"))
.accessToken(accessToken)
.build();

Work with Webex Teams rooms

// List my roomsspark.rooms()
.iterate()
.forEachRemaining(room -> {
System.out.println(room.getTitle() + ", created " + room.getCreated() + ": " + room.getId());
});
// Create a new roomRoomroom = newRoom();
room.setTitle("Hello World");
room = spark.rooms().post(room);
// Add a coworker to the roomMembershipmembership = newMembership();
membership.setRoomId(room.getId());
membership.setPersonEmail("wile_e_coyote@acme.com");
spark.memberships().post(membership);
// List the members of the roomspark.memberships()
.queryParam("roomId", room.getId())
.iterate()
.forEachRemaining(member -> {
System.out.println(member.getPersonEmail());
});
// Post a text message to the roomMessagemessage = newMessage();
message.setRoomId(room.getId());
message.setText("Hello World!");
spark.messages().post(message);
// Share a file with the roommessage = newMessage();
message.setRoomId(room.getId());
message.setFiles(URI.create("http://example.com/hello_world.jpg"));
spark.messages().post(message);
// Share an adaptive card with the roommessage = newMessage();
message.setRoomId(room.getId());
message.setText("Mandatory fallback text");
JsonArrayattachmentsArry = Json.createArrayBuilder() // Create an array to contain all the adaptive card JSONs
.add(Json.createObjectBuilder() // Add the required key "contentType" which points to the fact that this attachment is of type adatpive card
.add("contentType", "application/vnd.microsoft.card.adaptive") // The content key will contain the actual card JSON generated from the adaptive cards designer
.add("content", Json.createObjectBuilder()
.add("$schema", "http://adaptivecards.io/schemas/adaptive-card.json")
.add("type", "AdaptiveCard")
.add("version", "1.0")
.add("body", Json.createArrayBuilder() // Create the initital body object of the card
.add(Json.createObjectBuilder() // Create an object/element inside the body
.add("type", "TextBlock") // This is an example of TextBlock element
.add("text", "Here is a ninja cat")
.build() // Build the object
)
.add(Json.createObjectBuilder()
.add("type", "Image") // This is an example of Image element
.add("url", "http://adaptivecards.io/content/cats/1.png")
.build() // Build the image element
)
.build() // Build the body object
)
.build() // Build the card JSON
))
.build(); // Build the entire attachments arraymessage.setAttachments(attachmentsArry); // Set the attachments field on the message payload which has to be an array of JSONspark.messages().post(message);
// Get person detailsPersonperson=newPerson();
person=spark.people().path("/<<<**Insert PersonId**>>>").get();

Connect to Webex Teams via webhooks

// Create a new webhookWebhookwebhook = newWebhook();
webhook.setName("My Webhook");
webhook.setResource("messages");
webhook.setEvent("created");
webhook.setFilter("mentionedPeople=me");
webhook.setSecret("SOMESECRET");
webhook.setTargetUrl(URI.create("http://www.example.com/webhook"));
webhook=spark.webhooks().post(webhook);
// List webhooksspark.webhooks().iterate().forEachRemaining(hook -> {
System.out.println(hook.getId() + ": " + hook.getName() + " (" + hook.getTargetUrl() + ")" + " Secret - " + hook.getSecret());
});
// Delete a webhookwebhook=spark.webhooks().path("/<<<**Insert WebhookId**>>>").delete();

Find all your relevant information through our APIs

// List people in the organizationspark.people().iterate().forEachRemaining(ppl -> {
System.out.println(ppl.getId() + ": " + ppl.getDisplayName()+" : Creation: "+ppl.getCreated());
});
// Get organizationsspark.organizations().iterate().forEachRemaining(org -> {
System.out.println(org.getId() + ": " + org.getDisplayName()+" : Creation: "+org.getCreated());
});
// Get licensesspark.licenses().iterate().forEachRemaining(license -> {
System.out.println("GET Licenses " +license.getId() + ": DisplayName:- " + license.getDisplayName()+" : totalUnits: "+Integer.toString(license.getTotalUnits())+" : consumedUnits: "+Integer.toString(license.getConsumedUnits()));
});
// Get rolesspark.roles().iterate().forEachRemaining(role -> {
System.out.println("GET Roles " +role.getId() + ": Name:- " + role.getName());
});

Work directly with your teams

// Create a new teamTeamteam = newTeam();
team.setName("Brand New Team");
team = spark.teams().post(team);
// Add a coworker to the teamTeamMembershipteamMembership = newTeamMembership();
teamMembership.setTeamId(team.getId());
teamMembership.setPersonEmail("wile_e_coyote@acme.com");
spark.teamMemberships().post(teamMembership);
// List the members of the teamspark.teamMemberships()
.queryParam("teamId", team.getId())
.iterate()
.forEachRemaining(member -> {
System.out.println(member.getPersonEmail());
});

Contributing

Maintainers

  • Brian (bbender)
  • Santosh (santokum)

License

© 2018 Cisco Systems, Inc. and/or its affiliates. All Rights Reserved. See LICENSE for details.

About

Java library for consuming RESTful APIs for Cisco Spark

Resources

Contributing

Stars

70 stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages