Skip to content

Commit

Permalink
Add Kotlin sample for API reference
Browse files Browse the repository at this point in the history
  • Loading branch information
addb committed Jan 31, 2023
1 parent 8962b6b commit 17736af
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 3 deletions.
158 changes: 156 additions & 2 deletions Documentation/api-reference.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Adobe Experience Platform Identity for Edge Network Extension - Android
# Adobe Experience Platform Identity for Edge Network Extension Android API Reference

## Prerequisites

Expand Down Expand Up @@ -35,13 +35,25 @@ public static String extensionVersion()
```java
String extensionVersion = Identity.extensionVersion();
```

#### Kotlin

##### Syntax
```kotlin
fun extensionVersion(): String
```

##### Example
```kotlin
val extensionVersion = Identity.extensionVersion()
```
------

### getExperienceCloudId

This API retrieves the Experience Cloud ID (ECID) that was generated when the app was initially launched. This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall.

> **Note**
> **Note**
> The ECID value is returned via the `AdobeCallback`. When `AdobeCallbackWithError` is provided to this API, the timeout value is 500ms. If the operation times out or an unexpected error occurs, the `fail` method is called with the appropriate `AdobeError`.
#### Java
Expand All @@ -63,6 +75,20 @@ Identity.getExperienceCloudId(new AdobeCallback<String>() {
});
```

#### Kotlin

##### Syntax
```kotlin
fun getExperienceCloudId(callback: AdobeCallback<String>)
```

##### Example
```kotlin
Identity.getExperienceCloudId { id ->
//Handle the ID returned here
}
```

------

### getIdentities
Expand Down Expand Up @@ -90,6 +116,20 @@ Identity.getIdentities(new AdobeCallback<IdentityMap>() {
});
```

#### Kotlin

##### Syntax
```kotlin
fun getIdentities(callback: AdobeCallback<IdentityMap>)
```

##### Example
```kotlin
Identity.getIdentities { identityMap ->
//Handle the IdentityMap returned here
}
```

------

### getUrlVariables
Expand Down Expand Up @@ -128,6 +168,23 @@ Identity.getUrlVariables(new AdobeCallback<String>() {
});
```

#### Kotlin

##### Syntax
```kotlin
fun getUrlVariables(callback: AdobeCallback<String>)
```

##### Example
```kotlin
Identity.getUrlVariables { urlVariablesString ->
//handle the URL query parameter string here
//For example, open the URL in a webView
val webView = findViewById<WebView>(R.id.your_webview) // initialize with your webView
webView.loadUrl("http://www.example.com?" + urlVariablesString)
}
```

------

### registerExtension
Expand Down Expand Up @@ -155,6 +212,18 @@ import com.adobe.marketing.mobile.edge.identity.Identity
Identity.registerExtension();
```

#### Kotlin

##### Syntax
```kotlin
fun registerExtension()
```

##### Example
```kotlin
Identity.registerExtension()
```

------

### removeIdentity
Expand Down Expand Up @@ -182,6 +251,19 @@ IdentityItem item = new IdentityItem("[email protected]");
Identity.removeIdentity(item, "Email");
```

#### Kotlin

##### Syntax
```kotlin
fun removeIdentity(item: IdentityItem, namespace: String)
```

##### Example
```kotlin
val item = IdentityItem("[email protected]")
Identity.removeIdentity(item, "Email")
```

------

### resetIdentities
Expand Down Expand Up @@ -370,6 +452,22 @@ identityMap.addItem(item, "Email")
Identity.updateIdentities(identityMap);
```


#### Kotlin

##### Syntax
```kotlin
fun updateIdentities(identityMap: IdentityMap)
```

##### Example
```kotlin
val item = IdentityItem("[email protected]")
val identityMap = IdentityMap()
identityMap.addItem(item, "Email")
Identity.updateIdentities(identityMap)
```

------

## Public Classes
Expand Down Expand Up @@ -415,6 +513,8 @@ For more information, please read an overview of the [Adobe Experience Platform

**Example**

#### Java

```java
// Construct
IdentityMap identityMap = new IdentityMap();
Expand All @@ -437,6 +537,30 @@ List<String> namespaces = identityMap.getNamespaces();
boolean hasNotIdentities = identityMap.isEmpty();
```

#### Kotlin

```kotlin
// Construct
val identityMap = IdentityMap()

// Add an item
val item = IdentityItem("[email protected]")
identityMap.addItem(item, "Email")

// Remove an item
val item = IdentityItem("[email protected]")
identityMap.removeItem(item, "Email")

// Get a list of items for a given namespace
val items = identityMap.getIdentityItemsForNamespace("Email")

// Get a list of all namespaces used in current IdentityMap
val namespaces = identityMap.getNamespaces()

// Check if IdentityMap has no identities
val hasNotIdentities = identityMap.isEmpty()
```

------

### IdentityItem
Expand All @@ -447,6 +571,8 @@ The format of the IdentityItem class is defined by the [XDM Identity Item Schema

**Example**

#### Java

```java
// Construct
IdentityItem item = new IdentityItem("identifier");
Expand All @@ -462,6 +588,23 @@ AuthenticatedState state = item.getAuthenticatedState();
boolean primary = item.isPrimary();
```

#### Kotlin

```kotlin
// Construct
val item = IdentityItem("identifier")

val item = IdentityItem("identifier", AuthenticatedState.AUTHENTICATED, false)


// Getters
val id = item.getId()

val state = item.getAuthenticatedState()

val primary = item.isPrimary()
```

------

### AuthenticatedState
Expand All @@ -476,10 +619,21 @@ The possible authenticated states are:

**Syntax**

#### Java

```java
public enum AuthenticatedState {
AMBIGUOUS("ambiguous"),
AUTHENTICATED("authenticated"),
LOGGED_OUT("loggedOut");
}
```
#### Kotlin

```kotlin
enum class AuthenticatedState(val name: String) {
AMBIGUOUS("ambiguous"),
AUTHENTICATED("authenticated"),
LOGGED_OUT("loggedOut")
}
```
2 changes: 1 addition & 1 deletion Documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The Adobe Experience Platform Identity for Edge Network extension depends on the
1. Add the Mobile Core, Edge, and Edge Identity extensions to your project using the app's Gradle file:

```java
```gradle
implementation 'com.adobe.marketing.mobile:core:2.+'
implementation 'com.adobe.marketing.mobile:edge:2.+'
implementation 'com.adobe.marketing.mobile:edgeidentity:2.+'
Expand Down

0 comments on commit 17736af

Please sign in to comment.