Skip to content

Latest commit

 

History

History
95 lines (70 loc) · 3.29 KB

File metadata and controls

95 lines (70 loc) · 3.29 KB

smartapp-contextstore-dynamodb

This library adds support for a context store using DynamoDB. This will help keep track of tokens, configuration and other application related data stored in a DefaultInstalledAppContext instance.

Prerequisites

Adding the library to your build

Include the smartapp-core Maven dependency:

<dependency>
    <groupId>com.smartthings.sdk</groupId>
    <artifactId>smartapp-contextstore-dynamodb</artifactId>
    <version>0.0.4-PREVIEW</version>
</dependency>

If you're using Gradle:

dependencies {
    compile 'com.smartthings.sdk:smartapp-contextstore-dynamodb:0.0.4-PREVIEW'
}

If you do not use Maven or Gradle, jars can be downloaded from the central Maven repository.

Getting Started

To use this library, you'll need to create an instance of DynamoDBInstalledAppContextStore and wire it into your SmartApp instance. DynamoDBInstalledAppContextStore is a RequestPreprocessor that handles the appropriate lifecycle events to keep the backing store up-to-date with application installs, updates and uninstalls.

AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient();
DynamoDB dynamoDB = new DynamoDB(client);
TokenRefreshService tokenRefreshService = new TokenRefreshServiceImpl(clientId, clientSecret);
DynamoDBInstalledAppContextStore contextStore =
    new DynamoDBInstalledAppContextStore(dynamoDB, tokenRefreshService);

...

SmartApp smartApp = SmartApp.of(spec ->
    spec
        .install(request -> Response.ok())
        .update(request -> Response.ok(UpdateResponseData.newInstance()))
        .configuration(request -> Response.ok(ConfigurationResponseData.newInstance()))
        .event(request -> Response.ok(EventResponseData.newInstance()))
        .uninstall(request -> Response.ok(UninstallResponseData.newInstance()))
        .addRequestPreprocessor(contextStore)
);

DynamoDBInstalledAppContextStore also implements DefaultInstalledAppContextStore so you can use it directly to retrieve the context for a given installed app id.

// later you can refer to the context store to get the context for a given
// installedAppId
DefaultInstalledAppContext context = contextStore.get(installedAppId);

For a complete example, see Java Spring Boot example SmartApp.

More about SmartThings

If you are not familiar with SmartThings, we have extensive on-line documentation.

To create and manage your services and devices on SmartThings, create an account in the developer workspace.

The SmartThings Community is a good place share and ask questions.

There is also a SmartThings reddit community where you can read and share information.

License and Copyright

Licensed under the Apache License, Version 2.0

Copyright 2019 SmartThings, Inc.