Skip to content

Commit

Permalink
Merge pull request #2 from Headbright/add-feedback-client
Browse files Browse the repository at this point in the history
Allow sending feedback with attributes
  • Loading branch information
kkostov authored May 19, 2024
2 parents f15a803 + 4bb49f6 commit 300e2ec
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 52 deletions.
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
## Local development setup
# Feedbackbulb SDK for Kotlin Multiplatform

This is the Feedbackbulb SDK for Kotlin Multiplatform.
It is a library that allows you to easily integrate Feedbackbulb into your Kotlin project.

⚠️ This is a work in progress and doesn't support all features of the Feedbackbulb API yet. If you encounter a bug or need a specific feature, please open an issue or a pull request.


Currently supported platforms are:

- Kotlin/JVM
- Android
- iOS


## Getting started

### Add the dependency

The library is available directly from [Maven Central](https://central.sonatype.com/artifact/com.feedbackbulb/core-sdk. Add the following to your `build.gradle.kts` file:

```kotlin
implementation("com.feedbackbulb:core-sdk:X.X.X")
```

(replace `X.X.X` with the latest version)


### Initialize the SDK

Begin by obtaining an app key from the [Feedbackbulb dashboard](https://app.feedbackbulb.com/). Then, initialize the SDK with the app key:

```kotlin
val client= FeedbackSDKClient("YOUR_APP_KEY")
```

### Send feedback

To send feedback, use the `sendFeedback` method:

```kotlin
client.sendFeedback("This is a test feedback from Feedback SDK for Kotlin Multiplatform")
// or
client.sendFeedback("This is a test feedback from Feedback SDK for Kotlin Multiplatform", mapOf("example" to "Kotlin Multiplatform"))
```


## Local development

The following are notes for local development of the SDK and publishing updates.

Create or update gradle.properties file in the root of the project with the following content:

Expand All @@ -10,4 +59,7 @@ mavenCentralUsername=...
mavenCentralPassword=...
```

DO NOT CHECK THIS IN!
DO NOT CHECK THIS IN!


To publish a new version, run `./gradlew publishAndReleaseToMavenCentral --no-configuration-cache`
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

allprojects {
group = "com.feedbackbulb"
version = "0.0.2"
version = "0.0.3"
}

nexusPublishing {
Expand Down
12 changes: 10 additions & 2 deletions core-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.vanniktech.publish)
alias(libs.plugins.kotlin.serialization)
}

kotlin {
Expand All @@ -30,19 +31,26 @@ kotlin {
}
}

jvm()

sourceSets {
commonMain.dependencies {
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.core)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.serialization.kotlinx.protobuf)
}

androidMain.dependencies {
implementation(libs.ktor.client.okhttp)
implementation(libs.kotlinx.coroutines.android)
}

iosMain.dependencies {
implementation(libs.ktor.client.darwin)
}

commonTest.dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
Expand All @@ -64,7 +72,7 @@ mavenPublishing {
coordinates(
groupId = "com.feedbackbulb",
artifactId = "core-sdk",
version = "0.0.2"
version = "0.0.3"
)

// Configure POM metadata for the published artifact
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.feedbackbulb.libs.core

import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertTrue
import org.junit.Test

class AndroidGreetingTest {

@Test
fun testExample() = runTest {
val result = Greeting().greeting()
kotlin.test.assertTrue(result.isNotEmpty())
fun testSubmittingFeedback() = runTest {
val client = FeedbackSDKClient("01b7f627-37c0-43f8-8815-2d730f55134b")
client.sendFeedback(
"This is a test feedback from Feedback SDK for Kotlin Multiplatform send from Android",
mapOf("example" to "Kotlin Multiplatform")
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.feedbackbulb.libs.core

import io.ktor.client.HttpClient
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.serialization.kotlinx.json.json


/**
* This class represents the Feedback SDK client.
* It is used to send feedback to the FeedbackBulb service.
*
* @property appKey The application key which will receive feedback reports. You can obtain it from the Feedbackbulb dashboard.
*/
class FeedbackSDKClient(val appKey: String) {
// HttpClient used for making HTTP requests.
private val client = HttpClient {
install(ContentNegotiation) {
json()
}
}

/**
* Sends feedback to the Feedbackbulb service.
* It makes a POST request to the FeedbackBulb API with the feedback content and attributes.
*
* @param content The content of the feedback.
* @param attributes Additional attributes for the feedback. Default is an empty map.
*/
suspend fun sendFeedback(content: String, attributes: Map<String, String> = emptyMap()) {
// post value to https://feedbackbulb.com/api/values

val report = FeedbackbulbReport(appKey, content, attributes)
val value = FeedbackbulbValue(report)

client.post("https://feedbackbulb.com/api/values") {
contentType(ContentType.Application.Json)
setBody(value)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.feedbackbulb.libs.core

import kotlinx.serialization.Serializable

@Serializable
data class FeedbackbulbReport(
val key: String,
val content: String,
val attributes: Map<String, String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.feedbackbulb.libs.core

import kotlinx.serialization.Serializable

@Serializable
data class FeedbackbulbValue(val value: FeedbackbulbReport)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.feedbackbulb.libs.core

import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertTrue

class CommonGreetingTest {

@Test
fun testExample() = runTest {
assertTrue(Greeting().greeting().isNotEmpty())
fun testSubmittingFeedback() = runTest {
val client = FeedbackSDKClient("01b7f627-37c0-43f8-8815-2d730f55134b")
client.sendFeedback(
"This is a test feedback from Feedback SDK for Kotlin Multiplatform",
mapOf("example" to "Kotlin Multiplatform")
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.feedbackbulb.libs.core

import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertTrue

class IosGreetingTest {

@Test
fun testExample() = runTest {
assertTrue(Greeting().greeting().contains("iOS"), "Check iOS is mentioned")
fun testSubmittingFeedback() = runTest {
val client = FeedbackSDKClient("01b7f627-37c0-43f8-8815-2d730f55134b")
client.sendFeedback(
"This is a test feedback from Feedback SDK for Kotlin Multiplatform send from iOS",
mapOf("example" to "Kotlin Multiplatform")
)
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ compose-material3 = { module = "androidx.compose.material3:material3", version.r
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-serialization-kotlinx-protobuf = { module = "io.ktor:ktor-serialization-kotlinx-protobuf", version.ref = "ktor" }
nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" }

[plugins]
Expand All @@ -36,3 +39,4 @@ kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref =
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
kotlinDokka = { id = "org.jetbrains.dokka", version.ref = "kotlin" }
vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }

0 comments on commit 300e2ec

Please sign in to comment.