Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Kotlin docs #648

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/cache/develop/sdks/kotlin/cheat-sheet.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
sidebar_position: 1
sidebar_label: Cheat Sheet
title: Cheat Sheet for Kotlin
description: Get started really quickly coding using Kotlin with Momento Cache
---

import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock";
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl";

# Cheat Sheet for Kotlin with Momento Cache

If you need to get going quickly with Kotlin and Momento Cache, this page contains the basic API calls you'll need. [Check the Kotlin SDK examples](https://github.com/momentohq/client-sdk-kotlin/tree/main/examples) for complete, working examples including build configuration files.

## Install the Momento client library

Install the client library in an existing Kotlin project:

### Gradle

```kotlin
implementation("software.momento.kotlin:sdk:0.1.3")
```

### Maven

```xml
<dependency>
<groupId>software.momento.kotlin</groupId>
<artifactId>sdk</artifactId>
<version>0.1.3</version>
</dependency>
```

## Set up your auth token

You'll need a Momento API key to authenticate with Momento. You can get one from the [Momento Web Console](https://console.gomomento.com/caches).
Once you have your token, store it in an environment variable so that the Momento client can consume it:

```
export MOMENTO_API_KEY=<your Momento API key here>
```

## Import libraries and connect to return a CacheClient object
This code sets up the main function, the necessary imports, and the CacheClient instantiation that each of the other functions will need to call.

<SdkExampleCodeBlock language={'kotlin'} file={'CheatSheet.kt'} />

## Create a new cache in Momento Cache
Use this function to create a new cache in your account.

<SdkExampleCodeBlock language={'kotlin'} snippetId={'API_CreateCache'} />


## List the names of existing caches in your account
A simple list of the names of caches for the account.

<SdkExampleCodeBlock language={'kotlin'} snippetId={'API_ListCaches'} />

## Write an item to a cache
A simple example of doing a set operation. In the client.set call, the TTL it optional. If you did pass it in, this would override the default TTL value set with the client connection object.

<SdkExampleCodeBlock language={'kotlin'} snippetId={'API_Set'} />

## Read an item from a cache
This is an example of a simple read operation to get an item from a cache.

<SdkExampleCodeBlock language={'kotlin'} snippetId={'API_Get'} />

## Running the code

You can find complete, working examples in the [Kotlin SDK github repo examples directory](https://github.com/momentohq/client-sdk-kotlin/tree/main/examples).

:::info
Beyond these basic API calls check out the [API reference page](/cache/develop/api-reference/index.mdx) for more information on the full assortment of Momento API calls.

:::
31 changes: 31 additions & 0 deletions docs/cache/develop/sdks/kotlin/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
sidebar_position: 6
title: Momento Kotlin SDK
pagination_prev: null
sidebar_label: Kotlin
description: Information about the Momento Kotlin SDK
---

# Momento Kotlin SDK

The Momento Kotlin SDK for Android and JVM is available via Maven Central: [`software.momento.kotlin:sdk`](https://central.sonatype.com/artifact/software.momento.kotlin/sdk).


The source code can be found on GitHub: [momentohq/client-sdk-kotlin](https://github.com/momentohq/client-sdk-kotlin).

## Requirements

- A Momento API Key is required; you can get one from the [Momento Web Console](https://console.gomomento.com/).
- At least the Java 11 run time installed, or Android 23+.
- mvn or gradle for downloading the sdk.

## Resources

- [Kotlin SDK Cheat Sheet](./cheat-sheet.mdx)
- [Kotlin SDK Examples](https://github.com/momentohq/client-sdk-kotlin/blob/main/examples/README.md): working example projects that illustrate how to use the Kotlin SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Kotlin SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Kotlin SDK

## Integrations

COMING SOON
1 change: 1 addition & 0 deletions docs/cache/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ We currently have the following SDK languages available:
- [Go](./develop/sdks/go)
- [PHP](./develop/sdks/php)
- [Java](./develop/sdks/java)
- [Kotlin](./develop/sdks/kotlin)
- [Rust](./develop/sdks/rust)
- [Ruby](./develop/sdks/ruby)
- [Elixir](./develop/sdks/elixir)
Expand Down
1 change: 1 addition & 0 deletions docs/cache/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ In the following pages, you can learn about caching in general and how to use Mo
- [Go](./cache/develop/sdks/go)
- [PHP](./cache/develop/sdks/php)
- [Java](./cache/develop/sdks/java)
- [Kotlin](./cache/develop/sdks/kotlin)
- [Rust](./cache/develop/sdks/rust)
- [Ruby](./cache/develop/sdks/ruby)
- [Elixir](./cache/develop/sdks/elixir)
Expand Down
29 changes: 29 additions & 0 deletions docs/topics/develop/sdks/kotlin/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
sidebar_position: 6
title: Momento Kotlin SDK
pagination_prev: null
sidebar_label: Kotlin
description: Information about the Momento Kotlin SDK
---

# Momento Kotlin SDK

The Momento Kotlin SDK is available via Maven Central: [`software.momento.kotlin:sdk`](https://central.sonatype.com/artifact/software.momento.kotlin/sdk).

The source code can be found on GitHub: [momentohq/client-sdk-kotlin](https://github.com/momentohq/client-sdk-kotlin).

## Requirements

- A Momento API key is required; you can get one from the [Momento Web Console](https://console.gomomento.com/).
- At least the Java 11 run time installed or Android 23+
- mvn or gradle for downloading the sdk

## Resources

- [Kotlin SDK Examples](https://github.com/momentohq/client-sdk-kotlin/blob/main/examples/README.md): working example projects that illustrate how to use the Kotlin SDK
- COMING SOON: Observability: Logging and Client-side Metrics with the Kotlin SDK
- COMING SOON: Taking your code to prod: Configuration and Error handling in the Kotlin SDK

## Integrations

COMING SOON
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ const config = {
],
},
prism: {
additionalLanguages: ["java", "rust", "csharp", "php", "elixir", "swift", "dart"],
additionalLanguages: ["java", "kotlin", "rust", "csharp", "php", "elixir", "swift", "dart"],
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ const SDKS: Array<SdkInfo> = [
authClientFile: 'momento-sdk/src/main/java/momento/sdk/AuthClient.java',
leaderboardClientFile: undefined,
},
{
sdk: Sdk.KOTLIN,
cacheClientFile:
'src/commonMain/kotlin/software/momento/kotlin/sdk/CacheClient.kt',
configObjectFile:
'src/commonMain/kotlin/software/momento/kotlin/sdk/config/Configuration.kt',
topicClientFile:
'src/commonMain/kotlin/software/momento/kotlin/sdk/TopicClient.kt',
authClientFile: undefined,
leaderboardClientFile: undefined,
},
{
sdk: Sdk.ELIXIR,
cacheClientFile: 'src/lib/momento/cache_client.ex',
Expand Down
3 changes: 3 additions & 0 deletions plugins/example-code-snippets/src/examples/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum ExampleLanguage {
PYTHON = 'python',
GO = 'go',
JAVA = 'java',
KOTLIN = 'kotlin',
PHP = 'php',
RUST = 'rust',
RUBY = 'ruby',
Expand Down Expand Up @@ -48,6 +49,8 @@ export function languageDisplayName(language: ExampleLanguage): string {
return 'Go';
case ExampleLanguage.JAVA:
return 'Java';
case ExampleLanguage.KOTLIN:
return 'Kotlin';
case ExampleLanguage.PHP:
return 'PHP';
case ExampleLanguage.RUST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {JavaSnippetSourceParser} from './source-parsers/languages/java-snippet-s
import {ElixirSnippetSourceParser} from './source-parsers/languages/elixir-snippet-source-parser';
import {SwiftSnippetSourceParser} from './source-parsers/languages/swift-snippet-source-parser';
import {DartSnippetSourceParser} from './source-parsers/languages/dart-snippet-source-parser';
import {KotlinSnippetSourceParser} from './source-parsers/languages/kotlin-snippet-source-parser';

export class SdkRepoSnippetResolver implements SnippetResolver {
private readonly sourceProvider: SdkSourceProvider =
Expand Down Expand Up @@ -87,6 +88,8 @@ export class SdkRepoSnippetResolver implements SnippetResolver {
return new GolangSnippetSourceParser(sourceDir);
case ExampleLanguage.JAVA:
return new JavaSnippetSourceParser(sourceDir);
case ExampleLanguage.KOTLIN:
return new KotlinSnippetSourceParser(sourceDir);
case ExampleLanguage.PHP:
return new PhpSnippetSourceParser(sourceDir);
case ExampleLanguage.ELIXIR:
Expand Down Expand Up @@ -122,6 +125,8 @@ function sdkForLanguage(language: ExampleLanguage): Sdk {
return Sdk.GO;
case ExampleLanguage.JAVA:
return Sdk.JAVA;
case ExampleLanguage.KOTLIN:
return Sdk.KOTLIN;
case ExampleLanguage.PHP:
return Sdk.PHP;
case ExampleLanguage.RUST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class DartSnippetSourceParser extends RegexSnippetSourceParser {
constructor(repoSourceDir: string) {
const wholeFileExamplesDir = 'example/';
const codeSnippetFiles: Array<string> = [
'example/doc_example_apis/doc_example_apis.dart',
'example/doc_example_apis/bin/doc_example_apis.dart',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. That file moved in the dart sdk and broke the docs build. I forgot to comment.

];
super({
wholeFileExamplesDir: path.join(repoSourceDir, wholeFileExamplesDir),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
RegexSnippetSourceParser,
RegexSnippetTypeOptions,
} from '../regex-snippet-source-parser';
import {ExampleSnippetType} from '../../../examples';
import * as path from 'path';

export class KotlinSnippetSourceParser extends RegexSnippetSourceParser {
constructor(repoSourceDir: string) {
const wholeFileExamplesDir =
'examples/src/main/kotlin/software/momento/example/doc_examples';
const codeSnippetFiles: Array<string> = [
'examples/src/main/kotlin/software/momento/example/doc_examples/DocExamples.kt',
];
super({
wholeFileExamplesDir: path.join(repoSourceDir, wholeFileExamplesDir),
snippetTypeParseOptions: new Map<
ExampleSnippetType,
RegexSnippetTypeOptions
>([
[
ExampleSnippetType.CODE,
{
snippetSourceFiles: codeSnippetFiles.map(f =>
path.join(repoSourceDir, f)
),
startRegex: snippetId =>
new RegExp(`^suspend fun example_${snippetId.valueOf()}\\(`),
endRegex: () => /^}/,
numLeadingSpacesToStrip: 4,
},
],
]),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export function githubRepoNameForSdk(sdk: Sdk): string {
return 'client-sdk-go';
case Sdk.JAVA:
return 'client-sdk-java';
case Sdk.KOTLIN:
return 'client-sdk-kotlin';
case Sdk.PHP:
return 'client-sdk-php';
case Sdk.RUST:
Expand Down
3 changes: 3 additions & 0 deletions plugins/example-code-snippets/src/examples/sdk-source/sdks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum Sdk {
PYTHON = 'python',
GO = 'go',
JAVA = 'java',
KOTLIN = 'kotlin',
PHP = 'php',
RUST = 'rust',
RUBY = 'ruby',
Expand All @@ -31,6 +32,8 @@ export function sdkDisplayName(sdk: Sdk): string {
return 'Go';
case Sdk.JAVA:
return 'Java';
case Sdk.KOTLIN:
return 'Kotlin';
case Sdk.PHP:
return 'PHP';
case Sdk.RUST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function replaceValueWithExampleTabs(literal: unist.Literal): void {
js={\`${snippetForLanguage(ExampleLanguage.JAVASCRIPT, snippetId)}\`}
python={\`${snippetForLanguage(ExampleLanguage.PYTHON, snippetId)}\`}
java={\`${snippetForLanguage(ExampleLanguage.JAVA, snippetId)}\`}
kotlin={\`${snippetForLanguage(ExampleLanguage.KOTLIN, snippetId)}\`}
go={\`${snippetForLanguage(ExampleLanguage.GO, snippetId)}\`}
csharp={\`${snippetForLanguage(ExampleLanguage.CSHARP, snippetId)}\`}
php={\`${snippetForLanguage(ExampleLanguage.PHP, snippetId)}\`}
Expand All @@ -87,6 +88,7 @@ function replaceValueWithExampleFileTabs(literal: unist.Literal): void {
js={\`${fileTabContentsForLanguage(value, ExampleLanguage.JAVASCRIPT)}\`}
python={\`${fileTabContentsForLanguage(value, ExampleLanguage.PYTHON)}\`}
java={\`${fileTabContentsForLanguage(value, ExampleLanguage.JAVA)}\`}
kotlin={\`${fileTabContentsForLanguage(value, ExampleLanguage.KOTLIN)}\`}
go={\`${fileTabContentsForLanguage(value, ExampleLanguage.GO)}\`}
csharp={\`${fileTabContentsForLanguage(value, ExampleLanguage.CSHARP)}\`}
php={\`${fileTabContentsForLanguage(value, ExampleLanguage.PHP)}\`}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SdkExampleFileTabs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import React from 'react';
* @param snippetId: string
* @constructor
*/
export const SdkExampleFileTabs = ({javascript, python, java, go, csharp, php, rust, ruby, elixir, swift, dart, cli}) => {};
export const SdkExampleFileTabs = ({javascript, python, java, kotlin, go, csharp, php, rust, ruby, elixir, swift, dart, cli}) => {};


9 changes: 7 additions & 2 deletions src/components/SdkExampleFileTabsImpl/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React from 'react';
* @param js
* @param python
* @param java
* @param kotlin
* @param go
* @param csharp
* @param php
Expand All @@ -25,8 +26,8 @@ import React from 'react';
* @returns {JSX.Element|null}
* @constructor
*/
export const SdkExampleFileTabsImpl = ({js, python, java, go, csharp, php, rust, ruby, elixir, swift, dart, cli}) => {
if (js || python || java || go || csharp || php || rust || ruby || elixir || swift || dart || cli) {
export const SdkExampleFileTabsImpl = ({js, python, java, kotlin, go, csharp, php, rust, ruby, elixir, swift, dart, cli}) => {
if (js || python || java || kotlin || go || csharp || php || rust || ruby || elixir || swift || dart || cli) {
return (
<Tabs>
{js &&
Expand All @@ -41,6 +42,10 @@ export const SdkExampleFileTabsImpl = ({js, python, java, go, csharp, php, rust,
<TabItem value="java" label="Java">
<CodeBlock language={'java'}>{java}</CodeBlock>
</TabItem>}
{kotlin &&
<TabItem value="kotlin" label="Kotlin">
<CodeBlock language={'kotlin'}>{kotlin}</CodeBlock>
</TabItem>}
{go &&
<TabItem value="go" label="Go">
<CodeBlock language={'go'}>{go}</CodeBlock>
Expand Down
9 changes: 7 additions & 2 deletions src/components/SdkExampleTabsImpl/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React from 'react';
* @param js
* @param python
* @param java
* @param kotlin
* @param go
* @param csharp
* @param php
Expand All @@ -25,8 +26,8 @@ import React from 'react';
* @returns {JSX.Element|null}
* @constructor
*/
export const SdkExampleTabsImpl = ({js, python, java, go, csharp, php, rust, ruby, elixir, swift, dart, cli}) => {
if (js || python || java || go || csharp || php || rust || ruby || elixir || swift || dart || cli) {
export const SdkExampleTabsImpl = ({js, python, java, kotlin, go, csharp, php, rust, ruby, elixir, swift, dart, cli}) => {
if (js || python || java || kotlin || go || csharp || php || rust || ruby || elixir || swift || dart || cli) {
return (
<Tabs>
{js &&
Expand All @@ -41,6 +42,10 @@ export const SdkExampleTabsImpl = ({js, python, java, go, csharp, php, rust, rub
<TabItem value="java" label="Java">
<CodeBlock language={'java'}>{java}</CodeBlock>
</TabItem>}
{kotlin &&
<TabItem value="kotlin" label="Kotlin">
<CodeBlock language={'kotlin'}>{kotlin}</CodeBlock>
</TabItem>}
{go &&
<TabItem value="go" label="Go">
<CodeBlock language={'go'}>{go}</CodeBlock>
Expand Down
Loading