From 1f012de5b26b24beab2d0c892966e78bf515e3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 11:23:09 -0300 Subject: [PATCH 01/20] update sdk to 0.0.23 update flutterEngine remove coroutines from tests - tests are failing --- app/build.gradle | 4 ++-- .../java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9ded641..4cb2fbe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.flutterEngine = "1.0.0-857bd6b74c5eb56151bfafe91e7fa6a82b6fee25" - ext.sdkVersion = "0.0.19" + ext.flutterEngine = "1.0.0-8f2221fbef28b478debb78dd233f5250b220ca99" + ext.sdkVersion = "0.0.23" repositories { mavenCentral() } diff --git a/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt b/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt index fef1534..d1073ef 100644 --- a/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt +++ b/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt @@ -2,13 +2,8 @@ package com.mytiki.tiki_sdk_android import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation -import kotlinx.coroutines.* -import kotlinx.coroutines.test.resetMain -import kotlinx.coroutines.test.setMain -import org.junit.After import org.junit.Assert import org.junit.Assert.assertEquals -import org.junit.Before import org.junit.Test import org.junit.runner.RunWith From 278b2a47f30f454738b74560910a9305a29b186b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 11:40:49 -0300 Subject: [PATCH 02/20] add moshi dependencies --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 4cb2fbe..a41ba62 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,9 +49,13 @@ android { } apply plugin: 'com.kezong.fat-aar' +apply plugin: 'kotlin-kapt' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.core:core-ktx:1.9.0' + implementation("com.squareup.moshi:moshi-kotlin:1.14.0") + kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.14.0' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' From d1673055a821a076a3e8e9cc280c6db6b49b51a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 12:28:38 -0300 Subject: [PATCH 03/20] TikiSdkDestination with tests --- .../tiki_sdk_android/TikiSdkDestination.kt | 32 +++++-------------- .../TikiSdkDestinationTest.kt | 28 ++++++++++++++++ 2 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt index 76341ed..b7d2bdd 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt @@ -1,28 +1,12 @@ package com.mytiki.tiki_sdk_android -import org.json.JSONArray -import org.json.JSONObject +import com.squareup.moshi.JsonClass -data class TikiSdkDestination(val uses: List, val paths: List) { - companion object { - fun fromJson(jsonString: String): TikiSdkDestination { - val jsonObject = JSONObject(jsonString) - val usesArr: JSONArray = jsonObject.getJSONArray("uses") - val uses: MutableList = - MutableList(usesArr.length()) { i -> usesArr.getString(i) } - val pathsArr = jsonObject.getJSONArray("paths") - val paths = MutableList(pathsArr.length()) { i -> pathsArr.getString(i) } - return TikiSdkDestination( - uses, - paths - ) - } - } - - fun toJson(): String { - val jsonObject = JSONObject() - jsonObject.put("uses", JSONArray(uses)) - jsonObject.put("paths", JSONArray(paths)) - return jsonObject.toString() - } +@JsonClass(generateAdapter = true) +open class TikiSdkDestination( + val paths: List, + val uses: List = listOf("*"), +){ + object ALL : TikiSdkDestination(listOf("*")) + object NONE : TikiSdkDestination(listOf(), listOf()) } diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt new file mode 100644 index 0000000..7a0c2d7 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt @@ -0,0 +1,28 @@ +package com.mytiki.tiki_sdk_android + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class TikiSdkDestinationTest { + @Test + fun encode_TikiSdkDestination_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkDestination::class.java) + val tikiSdkDestination = adapter.fromJson("{\"uses\":[\"*\"], \"paths\": [\"*\"]}") + Assert.assertEquals("*", tikiSdkDestination?.uses?.get(0)) + Assert.assertEquals("*", tikiSdkDestination?.paths?.get(0)) + } + @Test + fun encode_TikiSdkDestination_ALL_and_NONE_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkDestination::class.java) + val tikiSdkDestinationAll = TikiSdkDestination.ALL + val allJson = adapter.toJson(tikiSdkDestinationAll) + Assert.assertEquals("{\"paths\":[\"*\"],\"uses\":[\"*\"]}", allJson) + val tikiSdkDestinationNone = TikiSdkDestination.NONE + val jsonNone = adapter.toJson(tikiSdkDestinationNone) + Assert.assertEquals("{\"paths\":[],\"uses\":[]}", jsonNone) + } +} \ No newline at end of file From a9187cc651e485833ecd1e5d31c18c676b4d85cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 12:36:13 -0300 Subject: [PATCH 04/20] TikiSdkDestination docs --- .../tiki_sdk_android/TikiSdkDestination.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt index b7d2bdd..b7a29a3 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt @@ -2,11 +2,50 @@ package com.mytiki.tiki_sdk_android import com.squareup.moshi.JsonClass +/** + * The destination to which the data is consented to be used. + * + * @property paths + * @property uses defaults to all uses + * @constructor Create empty Tiki sdk destination + */ @JsonClass(generateAdapter = true) open class TikiSdkDestination( + /** + * The destination paths. + * + * A list of paths, preferably URL without the scheme or + * reverse FQDN. Keep list short and use wildcard (*) + * matching. Prefix with NOT to invert. + * _i.e. NOT mytiki.com + */ val paths: List, + + /** + * The destination use cases. + * + * An optional list of application specific uses cases + * applicable to the given destination. Prefix with NOT + * to invert. _i.e. NOT ads + */ val uses: List = listOf("*"), ){ + /** + * TikiSdkDestination.ALL + * + * @constructor Create a TikiSdkDestination that includes all paths and uses. + */ object ALL : TikiSdkDestination(listOf("*")) + + /// + /// + /// + /** + * TikiSdkDestination.NONE + * + * Should be used for denying all consents given before. + * + * @constructor Create a TikiSdkDestination without any paths or uses. + */ object NONE : TikiSdkDestination(listOf(), listOf()) } From 9bbb0bc245d8b146c770cbde08187bc2764ac8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 12:55:36 -0300 Subject: [PATCH 05/20] TikiSdkConsent with docs and tests --- .../mytiki/tiki_sdk_android/TikiSdkConsent.kt | 45 +++++-------------- .../tiki_sdk_android/TikiSdkConsentTest.kt | 30 +++++++++++++ 2 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkConsent.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkConsent.kt index d11b785..17bbf73 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkConsent.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkConsent.kt @@ -1,8 +1,8 @@ package com.mytiki.tiki_sdk_android -import org.json.JSONObject -import java.util.* +import com.squareup.moshi.JsonClass +@JsonClass(generateAdapter = true) data class TikiSdkConsent( /** * Transaction ID corresponding to the ownership mint for the data source. @@ -15,45 +15,22 @@ data class TikiSdkConsent( val destination: TikiSdkDestination, /** - * Optional description of the consent. + * The transaction id of this registry. */ - val about: String, + val transactionId: String, /** - * Optional reward description the user will receive for this consent. + * Optional description of the consent. */ - val reward: String, + val about: String? = null, /** - * The transaction id of this registry. + * Optional reward description the user will receive for this consent. */ - val transactionId: String, + val reward: String? = null, /** - * The Consent expiration date. Null for no expiration. + * The Consent expiration in milliseconds since Epoch. Null for no expiration. */ - val expiry: Calendar -) { - companion object { - fun fromJson(jsonString: String): TikiSdkConsent { - val jsonObject = JSONObject(jsonString) - val ownershipId: String = jsonObject.getString("ownershipId") - val destination: String = jsonObject.getString("destination") - val about: String = jsonObject.getString("about") - val reward: String = jsonObject.getString("reward") - val transactionId: String = jsonObject.getString("transactionId") - val expiry: String = jsonObject.getString("expiry") - val dateTime = GregorianCalendar() - dateTime.timeInMillis = expiry.toLong() - return TikiSdkConsent( - ownershipId, - TikiSdkDestination.fromJson(destination), - about, - reward, - transactionId, - dateTime - ) - } - } - -} \ No newline at end of file + val expiry: Int? = null +) \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt new file mode 100644 index 0000000..a0b0d7c --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt @@ -0,0 +1,30 @@ +package com.mytiki.tiki_sdk_android + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class TikiSdkConsentTest { + @Test + fun encode_TikiSdkConsent_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkConsent::class.java) + val tikiSdkConsent = adapter.fromJson("{\"ownershipId\":\"ownership\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}") + Assert.assertEquals("ownership", tikiSdkConsent?.ownershipId) + Assert.assertEquals("*", tikiSdkConsent?.destination?.uses?.get(0)) + Assert.assertEquals("txnId", tikiSdkConsent?.transactionId) + Assert.assertNull(tikiSdkConsent?.about) + Assert.assertNull(tikiSdkConsent?.reward) + Assert.assertNull(tikiSdkConsent?.expiry) + } + @Test + fun encode_TikiSdkConsent_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkConsent::class.java) + val tikiSdkConsent = TikiSdkConsent( + "ownership", TikiSdkDestination.ALL, "txnId") + val json = adapter.toJson(tikiSdkConsent) + Assert.assertEquals("{\"ownershipId\":\"ownership\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}",json) + } +} \ No newline at end of file From 85a29da583cff7f3be861d55c994f1477d2bf325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 16:13:03 -0300 Subject: [PATCH 06/20] TikiSdkDataTypeEnum with docs and tests --- .../tiki_sdk_android/TikiSdkDataTypeEnum.kt | 11 +++++++++ .../TikiSdkDataTypeEnumTest.kt | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnum.kt create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnum.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnum.kt new file mode 100644 index 0000000..32a3209 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnum.kt @@ -0,0 +1,11 @@ +package com.mytiki.tiki_sdk_android + +import com.squareup.moshi.JsonClass + +/** + * The type of data origin for an ownership registry. + */ +@JsonClass(generateAdapter = false) +enum class TikiSdkDataTypeEnum { + data_point, data_stream, data_pool +} \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt new file mode 100644 index 0000000..c1e49b3 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt @@ -0,0 +1,24 @@ +package com.mytiki.tiki_sdk_android + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class TikiSdkDataTypeEnumTest { + @Test + fun encode_TikiSdkDataTypeEnum_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkDataTypeEnum::class.java) + val tikiSdkDataTypeEnum = adapter.fromJson("\"data_pool\""); + Assert.assertEquals(TikiSdkDataTypeEnum.data_pool.name, tikiSdkDataTypeEnum?.name) + } + @Test + fun encode_TikiSdkDataTypeEnum_ALL_and_NONE_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkDataTypeEnum::class.java) + val tikiSdkDataTypeEnum = TikiSdkDataTypeEnum.data_pool + val poolJson = adapter.toJson(tikiSdkDataTypeEnum) + Assert.assertEquals("\"data_pool\"", poolJson) + } +} \ No newline at end of file From 13c07d53907afda29e460aa53a68c111e3a0a964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 16:37:19 -0300 Subject: [PATCH 07/20] TikiSdkOwnership with docs and tests --- .../tiki_sdk_android/TikiSdkOwnership.kt | 43 +++++++++++++++++++ .../tiki_sdk_android/TikiSdkOwnershipTest.kt | 31 +++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt new file mode 100644 index 0000000..de96b14 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt @@ -0,0 +1,43 @@ +package com.mytiki.tiki_sdk_android + +import com.squareup.moshi.JsonClass + +/** + * The Ownership NFT. + * + * The registry of ownership to a given data point, pool, or stream. + */ +@JsonClass(generateAdapter = true) +class TikiSdkOwnership( + + /** + * The identification of the source. + */ + val source : String, + + /** + * The type of the data source: data point, pool or stream. + */ + val type : TikiSdkDataTypeEnum, + + /** + * The origin from which the data was generated. + */ + val origin : String, + + /** + * The transaction id of this registry. + */ + val transactionId : String, + + /** + * The kinds of data this contains. + */ + val contains : List = listOf(), + + /** + * The description about the data. + */ + val about : String? = null, + + ) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt new file mode 100644 index 0000000..c9ce684 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt @@ -0,0 +1,31 @@ +package com.mytiki.tiki_sdk_android + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class TikiSdkOwnershipTest { + @Test + fun encode_TikiSdkOwnership_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkOwnership::class.java) + val json = "{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.test\",\"transactionId\":\"txnId\",\"contains\":[\"test data\"]}" + val ownership = adapter.fromJson(json) + Assert.assertEquals("source", ownership?.source) + Assert.assertEquals(TikiSdkDataTypeEnum.data_point.name, ownership?.type?.name) + Assert.assertEquals("com.mytiki.test", ownership?.origin) + Assert.assertEquals("txnId", ownership?.transactionId) + Assert.assertNull(ownership?.about) + + } + @Test + fun encode_TikiSdkOwnership_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(TikiSdkOwnership::class.java) + val tikiSdkConsent = TikiSdkOwnership("source", TikiSdkDataTypeEnum.data_point, + "com.mytiki.test", "txnId", listOf("test data")) + val json = adapter.toJson(tikiSdkConsent) + Assert.assertEquals("{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.test\",\"transactionId\":\"txnId\",\"contains\":[\"test data\"]}",json) + } +} \ No newline at end of file From 69afa6d8f3eab2e1d17988acb251d7fbc734d4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 17:59:55 -0300 Subject: [PATCH 08/20] add Req and Rsp models --- .../tiki_platform_channel/req/Req.kt | 18 ++++++++++++ .../tiki_platform_channel/req/ReqBuild.kt | 27 +++++++++++++++++ .../req/ReqConsentApply.kt | 27 +++++++++++++++++ .../req/ReqConsentGet.kt | 22 ++++++++++++++ .../req/ReqConsentModify.kt | 29 +++++++++++++++++++ .../req/ReqOwnershipAssign.kt | 29 +++++++++++++++++++ .../req/ReqOwnershipGet.kt | 22 ++++++++++++++ .../tiki_platform_channel/rsp/Rsp.kt | 20 +++++++++++++ .../tiki_platform_channel/rsp/RspBuild.kt | 21 ++++++++++++++ .../rsp/RspConsentApply.kt | 25 ++++++++++++++++ .../rsp/RspConsentGet.kt | 23 +++++++++++++++ .../tiki_platform_channel/rsp/RspError.kt | 24 +++++++++++++++ .../tiki_platform_channel/rsp/RspOwnership.kt | 21 ++++++++++++++ 13 files changed, 308 insertions(+) create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/Req.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt create mode 100644 app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/Req.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/Req.kt new file mode 100644 index 0000000..7a65f60 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/Req.kt @@ -0,0 +1,18 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.squareup.moshi.JsonClass + +/** + * The base Request object for native channels. + * + * @property requestId used to identify the request in the native platform. + * @constructor Creates a new generic request + */ +@JsonClass(generateAdapter = true) +open class Req( + open val requestId: String +) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt new file mode 100644 index 0000000..666c2ca --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.squareup.moshi.JsonClass + +/** + * The request for the `build` method call in the Platform Channel. + * + * It requires an *apiId]* and an *origin]*. If no *address* is provided the SDK + * will create a new one + * + * @property requestId + * @property apiId + * @property origin + * @property address + * @constructor Create empty Req build + */ +@JsonClass(generateAdapter = true) +data class ReqBuild( + override val requestId: String, + val apiId: String, + val origin: String, + val address: String? +) : Req(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt new file mode 100644 index 0000000..3560ab1 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.mytiki.tiki_sdk_android.TikiSdkDestination +import com.squareup.moshi.JsonClass + +/** + * The request for the `applyConsent` method call in the Platform Channel. + * + * It uses the [source] and [destination] to verify if the consent was given. + * + * @property requestId + * @property source + * @property destination + * @property origin + * @constructor Create empty Req consent apply + */ +@JsonClass(generateAdapter = true) +data class ReqConsentApply( + override val requestId: String, + val source: String, + val destination: TikiSdkDestination, + val origin: String? +) : Req(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt new file mode 100644 index 0000000..6c68b07 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.squareup.moshi.JsonClass + +/** + * The request for the `getConsent` call in the Platform Channel. + * + * @property requestId + * @property source + * @property origin + * @constructor Create empty Req consent get + */ +@JsonClass(generateAdapter = true) +data class ReqConsentGet( + override val requestId: String, + val source: String, + val origin: String? +) : Req(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt new file mode 100644 index 0000000..5ec25a9 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.mytiki.tiki_sdk_android.TikiSdkDestination +import com.squareup.moshi.JsonClass + +/** + * The request for the `modifyConsent`method call in the Platform Channel. + * + * @property requestId + * @property ownershipId + * @property destination + * @property about + * @property reward + * @property expiry + * @constructor Create empty Req consent modify + */ +@JsonClass(generateAdapter = true) +data class ReqConsentModify( + override val requestId: String, + val ownershipId: String, + val destination: TikiSdkDestination, + val about: String?, + val reward: String?, + val expiry: Int? +) : Req(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt new file mode 100644 index 0000000..13d0d64 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.mytiki.tiki_sdk_android.TikiSdkDataTypeEnum +import com.squareup.moshi.JsonClass + +/** + * The request for the `assignOwnership` method call in the Platform Channel. + * + * @property requestId + * @property source + * @property type + * @property contains + * @property about + * @property origin + * @constructor Create empty Req ownership assign + */ +@JsonClass(generateAdapter = true) +data class ReqOwnershipAssign( + override val requestId: String, + val source: String, + val type: TikiSdkDataTypeEnum, + val contains: List, + val about: String?, + val origin: String? +) : Req(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt new file mode 100644 index 0000000..74c2d05 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.squareup.moshi.JsonClass + +/** + * The request for the `getOwnership` method call in the Platform Channel. + * + * @property requestId + * @property source + * @property origin + * @constructor Create empty Req ownership get + */ +@JsonClass(generateAdapter = true) +data class ReqOwnershipGet( + override val requestId: String, + val source: String, + val origin: String? +) : Req(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt new file mode 100644 index 0000000..9e4dad7 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt @@ -0,0 +1,20 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.squareup.moshi.JsonClass + +/** + * The base Response object for native channels. + * + * The [requestId] parameter is used to identify the request in the native platform. + * + * @property requestId + * @constructor Create empty Rsp + */ +@JsonClass(generateAdapter = true) +open class Rsp( + open val requestId : String +) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt new file mode 100644 index 0000000..82c7395 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.squareup.moshi.JsonClass + + +/** + * The response for the `build` method call in the Platform Channel. + * + * @property requestId + * @property address The [address] of the built node. + * @constructor Create empty Rsp build + */ +@JsonClass(generateAdapter = true) +data class RspBuild ( + override val requestId: String, + val address : String +): Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt new file mode 100644 index 0000000..7b9bc8b --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.squareup.moshi.JsonClass + +/** + * The response for the `applyConsent` method call in the Platform Channel. + * + * It returns if the consent was applied in the *success* field. + * For failed requests, a *reason* should be provided. + * + * @property requestId + * @property success + * @property reason + * @constructor Create empty Rsp consent apply + */ +@JsonClass(generateAdapter = true) +data class RspConsentApply( + override val requestId: String, + val success: Boolean, + val reason: String? +):Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt new file mode 100644 index 0000000..bbec2c8 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.mytiki.tiki_sdk_android.TikiSdkConsent +import com.squareup.moshi.JsonClass + +/** + * The response for the `getConsent` and `modifyConsent`method calls in the Platform Channel. + * + * It returns the [consent]. Null if no consent was given. + * + * @property requestId + * @property consent + * @constructor Create empty Rsp consent get + */ +@JsonClass(generateAdapter = true) +data class RspConsentGet( + override val requestId: String, + val consent: TikiSdkConsent +): Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt new file mode 100644 index 0000000..f977f54 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.squareup.moshi.JsonClass + +/** + * The response for the errors thrown in the Platform Channel. + * + * It returns the *message* of the error and the String representation of the [stackTrace]. + * + * @property requestId + * @property message + * @property stackTrace + * @constructor Create empty Rsp error + */ +@JsonClass(generateAdapter = true) +data class RspError( + override val requestId: String, + val message: String, + val stackTrace: String +): Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt new file mode 100644 index 0000000..e011b62 --- /dev/null +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.mytiki.tiki_sdk_android.TikiSdkOwnership + +/** + * The response for the `assignOwnership` and `getOwnership` method calls in the Platform Channel. + * + * Returns the [ownership] or Null if not found. + * + * @property requestId + * @property ownership + * @constructor Create empty Rsp ownership + */ +data class RspOwnership( + override val requestId: String, + val ownership : TikiSdkOwnership +): Rsp(requestId) From 84522fc8327c21988daa850bdd4e7816395c32bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 18:29:06 -0300 Subject: [PATCH 09/20] ReqBuild docs and tests --- .../tiki_platform_channel/req/ReqBuild.kt | 2 +- .../tiki_platform_channel/req/ReqBuildTest.kt | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt index 666c2ca..b2179a6 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt @@ -23,5 +23,5 @@ data class ReqBuild( override val requestId: String, val apiId: String, val origin: String, - val address: String? + val address: String? = null ) : Req(requestId) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt new file mode 100644 index 0000000..a9f95c3 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt @@ -0,0 +1,30 @@ +package com.mytiki.tiki_sdk_android + +import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqBuild +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class ReqBuildTest { + @Test + fun encode_ReqBuild_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqBuild::class.java) + val json = "{\"requestId\":\"reqId\",\"apiId\":\"apiId\",\"origin\":\"origin\"}" + val reqBuild = adapter.fromJson(json) + Assert.assertEquals("reqId", reqBuild?.requestId) + Assert.assertEquals("apiId", reqBuild?.apiId) + Assert.assertEquals("origin", reqBuild?.origin) + Assert.assertNull(reqBuild!!.address) + + } + @Test + fun encode_ReqBuild_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqBuild::class.java) + val req = ReqBuild("reqId", "apiId", "origin") + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"reqId\",\"apiId\":\"apiId\",\"origin\":\"origin\"}", json) + } +} \ No newline at end of file From 9aed551c1765535dbee45ac68c356482bddc51c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 18:42:26 -0300 Subject: [PATCH 10/20] ReqConsentApply docs and tests --- .../req/ReqConsentApply.kt | 2 +- .../req/ReqConsentApplyTest.kt | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt index 3560ab1..5410cd0 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt @@ -23,5 +23,5 @@ data class ReqConsentApply( override val requestId: String, val source: String, val destination: TikiSdkDestination, - val origin: String? + val origin: String? = null ) : Req(requestId) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt new file mode 100644 index 0000000..8cfcba8 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt @@ -0,0 +1,28 @@ +package com.mytiki.tiki_sdk_android + +import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentApply +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class ReqConsentApplyTest { + @Test + fun encode_ReqConsentApply_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqConsentApply::class.java) + val json = "{\"requestId\":\"reqId\",\"source\":\"source\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}" + val req = adapter.fromJson(json) + Assert.assertEquals(req!!.destination.paths[0], "*") + Assert.assertEquals(req.requestId, "reqId") + Assert.assertEquals(req.source, "source") + } + @Test + fun encode_ReqConsentApply_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqConsentApply::class.java) + val req = ReqConsentApply("reqId", "source", TikiSdkDestination.ALL) + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}",json) + } +} \ No newline at end of file From 44e57c4367551004cea73bed5c0a4477efd84b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 18:46:59 -0300 Subject: [PATCH 11/20] ReqConsentGet docs and tests --- .../req/ReqConsentGetTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt new file mode 100644 index 0000000..292c973 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt @@ -0,0 +1,29 @@ +package com.mytiki.tiki_sdk_android + +import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentGet +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class ReqConsentGetTest { + @Test + fun encode_ReqConsentGet_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqConsentGet::class.java) + val json = "{\"requestId\":\"reqId\",\"source\":\"source\",\"origin\":\"origin\"}" + val req = adapter.fromJson(json) + Assert.assertEquals(req!!.requestId, "reqId") + Assert.assertEquals(req.source, "source") + Assert.assertEquals(req.origin, "origin") + } + + @Test + fun encode_ReqConsentGet_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqConsentGet::class.java) + val req = ReqConsentGet("reqId", "source", "origin") + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\",\"origin\":\"origin\"}",json) + } +} \ No newline at end of file From ab7114a26f7618b2d13a39afadeb3d1d046629ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 19:03:14 -0300 Subject: [PATCH 12/20] ReqConsentModify docs and tests --- .../req/ReqConsentModify.kt | 6 ++-- .../req/ReqConsentModifyTest.kt | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt index 5ec25a9..f831a37 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt @@ -23,7 +23,7 @@ data class ReqConsentModify( override val requestId: String, val ownershipId: String, val destination: TikiSdkDestination, - val about: String?, - val reward: String?, - val expiry: Int? + val about: String? = null, + val reward: String? = null, + val expiry: Int? = null ) : Req(requestId) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt new file mode 100644 index 0000000..beec18c --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt @@ -0,0 +1,29 @@ +package com.mytiki.tiki_sdk_android + +import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentModify +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class ReqConsentModifyTest { + @Test + fun encode_ReqConsentModify_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqConsentModify::class.java) + val json = "{\"requestId\":\"reqId\",\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}" + val req = adapter.fromJson(json) + Assert.assertEquals( "*", req!!.destination.paths[0]) + Assert.assertEquals( "ownershipId", req.ownershipId) + Assert.assertEquals( "reqId", req.requestId) + } + + @Test + fun encode_ReqConsentModify_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqConsentModify::class.java) + val req = ReqConsentModify("reqId", "ownershipId", TikiSdkDestination.ALL) + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"reqId\",\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}",json) + } +} \ No newline at end of file From ba836ff67c33c6a33d46419ed6bc4c850eee233a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 19:26:50 -0300 Subject: [PATCH 13/20] ReqOwnershipAssign docs and tests --- .../req/ReqOwnershipAssign.kt | 4 +-- .../req/ReqOwnershipAssign.kt | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt index 13d0d64..c26d3ba 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt @@ -24,6 +24,6 @@ data class ReqOwnershipAssign( val source: String, val type: TikiSdkDataTypeEnum, val contains: List, - val about: String?, - val origin: String? + val about: String? = null, + val origin: String? = null ) : Req(requestId) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt new file mode 100644 index 0000000..de2c3b9 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt @@ -0,0 +1,27 @@ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.mytiki.tiki_sdk_android.TikiSdkDataTypeEnum +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class ReqOwnershipAssignTest { + @Test + fun encode_ReqOwnershipAssign_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqOwnershipAssign::class.java) + val json = "{\"requestId\":\"reqId\",\"source\":\"source\",\"type\":\"data_point\",\"contains\":[\"testData\"]}" + val req = adapter.fromJson(json) + Assert.assertEquals( "reqId", req!!.requestId) + } + + @Test + fun encode_ReqOwnershipAssign_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqOwnershipAssign::class.java) + val req = ReqOwnershipAssign("reqId", "source", TikiSdkDataTypeEnum.data_point, listOf("testData")) + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\",\"type\":\"data_point\",\"contains\":[\"testData\"]}",json) + } +} \ No newline at end of file From 5f34aed0b3d504f0ab30f9663f769a6875a41e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 19:27:05 -0300 Subject: [PATCH 14/20] ReqOwnershipGet docs and tests --- .../req/ReqOwnershipGet.kt | 2 +- .../req/ReqOwnershipGetTest.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt index 74c2d05..8398d44 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt @@ -18,5 +18,5 @@ import com.squareup.moshi.JsonClass data class ReqOwnershipGet( override val requestId: String, val source: String, - val origin: String? + val origin: String? = null ) : Req(requestId) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt new file mode 100644 index 0000000..7cd9a42 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt @@ -0,0 +1,26 @@ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class ReqOwnershipGetTest { + @Test + fun encode_ReqOwnershipGet_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqOwnershipGet::class.java) + val json = "{\"requestId\":\"reqId\",\"source\":\"source\"}" + val req = adapter.fromJson(json) + Assert.assertEquals( "reqId", req!!.requestId) + } + + @Test + fun encode_ReqOwnershipGet_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(ReqOwnershipGet::class.java) + val req = ReqOwnershipGet("reqId", "source") + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\"}",json) + } +} \ No newline at end of file From a1c45ddd01a0b7864e2f4f0f7ec5abab9d09efcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 19:27:21 -0300 Subject: [PATCH 15/20] update test packages --- .../tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt | 2 +- .../tiki_platform_channel/req/ReqConsentApplyTest.kt | 3 ++- .../tiki_platform_channel/req/ReqConsentGetTest.kt | 2 +- .../tiki_platform_channel/req/ReqConsentModifyTest.kt | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt index a9f95c3..ba65ae7 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt @@ -1,4 +1,4 @@ -package com.mytiki.tiki_sdk_android +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqBuild import com.squareup.moshi.JsonAdapter diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt index 8cfcba8..da74859 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt @@ -1,5 +1,6 @@ -package com.mytiki.tiki_sdk_android +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req +import com.mytiki.tiki_sdk_android.TikiSdkDestination import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentApply import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt index 292c973..7569173 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt @@ -1,4 +1,4 @@ -package com.mytiki.tiki_sdk_android +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentGet import com.squareup.moshi.JsonAdapter diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt index beec18c..70cbeac 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt @@ -1,5 +1,6 @@ -package com.mytiki.tiki_sdk_android +package com.mytiki.tiki_sdk_android.tiki_platform_channel.req +import com.mytiki.tiki_sdk_android.TikiSdkDestination import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentModify import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi From 2aad149de6742bdda852322baadf59c8604b5172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Wed, 21 Dec 2022 20:51:01 -0300 Subject: [PATCH 16/20] Rsp and Req for platform channels complete --- .../rsp/RspConsentApply.kt | 2 +- .../tiki_platform_channel/rsp/RspOwnership.kt | 2 + .../tiki_platform_channel/req/ReqBuildTest.kt | 11 +++++- .../req/ReqConsentApplyTest.kt | 14 +++++-- .../req/ReqConsentGetTest.kt | 10 ++++- .../req/ReqConsentModifyTest.kt | 19 ++++++--- .../req/ReqOwnershipAssign.kt | 21 ++++++++-- .../req/ReqOwnershipGetTest.kt | 8 +++- .../tiki_platform_channel/rsp/RspBuildTest.kt | 31 +++++++++++++++ .../rsp/RspConsentApply.kt | 30 ++++++++++++++ .../rsp/RspConsentGet.kt | 37 ++++++++++++++++++ .../tiki_platform_channel/rsp/RspError.kt | 33 ++++++++++++++++ .../tiki_platform_channel/rsp/RspOwnership.kt | 39 +++++++++++++++++++ 13 files changed, 237 insertions(+), 20 deletions(-) create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuildTest.kt create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt create mode 100644 app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt index 7b9bc8b..d16d4f3 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt @@ -21,5 +21,5 @@ import com.squareup.moshi.JsonClass data class RspConsentApply( override val requestId: String, val success: Boolean, - val reason: String? + val reason: String? = null ):Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt index e011b62..0107c22 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt @@ -5,6 +5,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp import com.mytiki.tiki_sdk_android.TikiSdkOwnership +import com.squareup.moshi.JsonClass /** * The response for the `assignOwnership` and `getOwnership` method calls in the Platform Channel. @@ -15,6 +16,7 @@ import com.mytiki.tiki_sdk_android.TikiSdkOwnership * @property ownership * @constructor Create empty Rsp ownership */ +@JsonClass(generateAdapter = true) data class RspOwnership( override val requestId: String, val ownership : TikiSdkOwnership diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt index ba65ae7..552c54f 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuildTest.kt @@ -1,6 +1,9 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req -import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqBuild import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import org.junit.Assert @@ -19,12 +22,16 @@ class ReqBuildTest { Assert.assertNull(reqBuild!!.address) } + @Test fun encode_ReqBuild_to_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(ReqBuild::class.java) val req = ReqBuild("reqId", "apiId", "origin") val json = adapter.toJson(req) - Assert.assertEquals("{\"requestId\":\"reqId\",\"apiId\":\"apiId\",\"origin\":\"origin\"}", json) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"apiId\":\"apiId\",\"origin\":\"origin\"}", + json + ) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt index da74859..b361960 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApplyTest.kt @@ -1,7 +1,10 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.TikiSdkDestination -import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentApply import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import org.junit.Assert @@ -12,18 +15,23 @@ class ReqConsentApplyTest { fun encode_ReqConsentApply_from_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(ReqConsentApply::class.java) - val json = "{\"requestId\":\"reqId\",\"source\":\"source\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}" + val json = + "{\"requestId\":\"reqId\",\"source\":\"source\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}" val req = adapter.fromJson(json) Assert.assertEquals(req!!.destination.paths[0], "*") Assert.assertEquals(req.requestId, "reqId") Assert.assertEquals(req.source, "source") } + @Test fun encode_ReqConsentApply_to_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(ReqConsentApply::class.java) val req = ReqConsentApply("reqId", "source", TikiSdkDestination.ALL) val json = adapter.toJson(req) - Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}",json) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"source\":\"source\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}", + json + ) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt index 7569173..ab1a5a4 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGetTest.kt @@ -1,6 +1,9 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req -import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentGet import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import org.junit.Assert @@ -24,6 +27,9 @@ class ReqConsentGetTest { val adapter: JsonAdapter = moshi.adapter(ReqConsentGet::class.java) val req = ReqConsentGet("reqId", "source", "origin") val json = adapter.toJson(req) - Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\",\"origin\":\"origin\"}",json) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"source\":\"source\",\"origin\":\"origin\"}", + json + ) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt index 70cbeac..5866f49 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModifyTest.kt @@ -1,7 +1,10 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.TikiSdkDestination -import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.ReqConsentModify import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import org.junit.Assert @@ -12,11 +15,12 @@ class ReqConsentModifyTest { fun encode_ReqConsentModify_from_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(ReqConsentModify::class.java) - val json = "{\"requestId\":\"reqId\",\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}" + val json = + "{\"requestId\":\"reqId\",\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}" val req = adapter.fromJson(json) - Assert.assertEquals( "*", req!!.destination.paths[0]) - Assert.assertEquals( "ownershipId", req.ownershipId) - Assert.assertEquals( "reqId", req.requestId) + Assert.assertEquals("*", req!!.destination.paths[0]) + Assert.assertEquals("ownershipId", req.ownershipId) + Assert.assertEquals("reqId", req.requestId) } @Test @@ -25,6 +29,9 @@ class ReqConsentModifyTest { val adapter: JsonAdapter = moshi.adapter(ReqConsentModify::class.java) val req = ReqConsentModify("reqId", "ownershipId", TikiSdkDestination.ALL) val json = adapter.toJson(req) - Assert.assertEquals("{\"requestId\":\"reqId\",\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}",json) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]}}", + json + ) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt index de2c3b9..66aaba4 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt @@ -1,3 +1,7 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.TikiSdkDataTypeEnum @@ -11,17 +15,26 @@ class ReqOwnershipAssignTest { fun encode_ReqOwnershipAssign_from_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(ReqOwnershipAssign::class.java) - val json = "{\"requestId\":\"reqId\",\"source\":\"source\",\"type\":\"data_point\",\"contains\":[\"testData\"]}" + val json = + "{\"requestId\":\"reqId\",\"source\":\"source\",\"type\":\"data_point\",\"contains\":[\"testData\"]}" val req = adapter.fromJson(json) - Assert.assertEquals( "reqId", req!!.requestId) + Assert.assertEquals("reqId", req!!.requestId) } @Test fun encode_ReqOwnershipAssign_to_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(ReqOwnershipAssign::class.java) - val req = ReqOwnershipAssign("reqId", "source", TikiSdkDataTypeEnum.data_point, listOf("testData")) + val req = ReqOwnershipAssign( + "reqId", + "source", + TikiSdkDataTypeEnum.data_point, + listOf("testData") + ) val json = adapter.toJson(req) - Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\",\"type\":\"data_point\",\"contains\":[\"testData\"]}",json) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"source\":\"source\",\"type\":\"data_point\",\"contains\":[\"testData\"]}", + json + ) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt index 7cd9a42..e09d722 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGetTest.kt @@ -1,3 +1,7 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.squareup.moshi.JsonAdapter @@ -12,7 +16,7 @@ class ReqOwnershipGetTest { val adapter: JsonAdapter = moshi.adapter(ReqOwnershipGet::class.java) val json = "{\"requestId\":\"reqId\",\"source\":\"source\"}" val req = adapter.fromJson(json) - Assert.assertEquals( "reqId", req!!.requestId) + Assert.assertEquals("reqId", req!!.requestId) } @Test @@ -21,6 +25,6 @@ class ReqOwnershipGetTest { val adapter: JsonAdapter = moshi.adapter(ReqOwnershipGet::class.java) val req = ReqOwnershipGet("reqId", "source") val json = adapter.toJson(req) - Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\"}",json) + Assert.assertEquals("{\"requestId\":\"reqId\",\"source\":\"source\"}", json) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuildTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuildTest.kt new file mode 100644 index 0000000..de89e3a --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuildTest.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class RspBuildTest { + @Test + fun encode_RspBuild_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspBuild::class.java) + val json = "{\"requestId\":\"requestId\",\"address\":\"address\"}" + val req = adapter.fromJson(json) + Assert.assertEquals("requestId", req!!.requestId) + } + + @Test + fun encode_RspBuild_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspBuild::class.java) + val req = RspBuild("requestId", "address") + val json = adapter.toJson(req) + Assert.assertEquals("{\"requestId\":\"requestId\",\"address\":\"address\"}", json) + } +} \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt new file mode 100644 index 0000000..fc7a963 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class RspConsentApplyTest { + @Test + fun encode_RspConsentApply_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspConsentApply::class.java) + val json = "{\"requestId\":\"requestId\",\"success\":true}" + val rsp = adapter.fromJson(json) + Assert.assertEquals("requestId", rsp!!.requestId) + } + + @Test + fun encode_RspConsentApply_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspConsentApply::class.java) + val rsp = RspConsentApply("requestId", true) + val json = adapter.toJson(rsp) + Assert.assertEquals("{\"requestId\":\"requestId\",\"success\":true}", json) + } +} \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt new file mode 100644 index 0000000..98f7852 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.mytiki.tiki_sdk_android.TikiSdkConsent +import com.mytiki.tiki_sdk_android.TikiSdkDestination +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class RspConsentGetTest { + @Test + fun encode_RspConsentGet_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspConsentGet::class.java) + val json = + "{\"requestId\":\"reqId\",\"consent\":{\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}}" + val req = adapter.fromJson(json) + Assert.assertEquals("reqId", req!!.requestId) + } + + @Test + fun encode_RspConsentGet_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspConsentGet::class.java) + val rsp = + RspConsentGet("reqId", TikiSdkConsent("ownershipId", TikiSdkDestination.ALL, "txnId")) + val json = adapter.toJson(rsp) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"consent\":{\"ownershipId\":\"ownershipId\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}}", + json + ) + } +} \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt new file mode 100644 index 0000000..d61a561 --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class RspErrorTest { + @Test + fun encode_RspError_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspError::class.java) + val json = "{\"requestId\":\"reqId\",\"message\":\"error\",\"stackTrace\":\"stackTrace\"}" + val req = adapter.fromJson(json) + Assert.assertEquals("reqId", req!!.requestId) + } + + @Test + fun encode_RspError_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspError::class.java) + val rsp = RspError("reqId", "error", "stackTrace") + val json = adapter.toJson(rsp) + Assert.assertEquals( + "{\"requestId\":\"reqId\",\"message\":\"error\",\"stackTrace\":\"stackTrace\"}", + json + ) + } +} \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt new file mode 100644 index 0000000..d62f0dd --- /dev/null +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt @@ -0,0 +1,39 @@ +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp + +import com.mytiki.tiki_sdk_android.TikiSdkDataTypeEnum +import com.mytiki.tiki_sdk_android.TikiSdkOwnership +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Test + +class RspOwnershipTest { + @Test + fun encode_RspOwnership_from_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspOwnership::class.java) + val json = + "{\"requestId\":\"requestId\",\"ownership\":{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.rsp\",\"transactionId\":\"txnId\",\"contains\":[]}}" + val req = adapter.fromJson(json) + Assert.assertEquals("requestId", req!!.requestId) + } + + @Test + fun encode_RspOwnership_to_JSON() { + val moshi: Moshi = Moshi.Builder().build() + val adapter: JsonAdapter = moshi.adapter(RspOwnership::class.java) + val rsp = RspOwnership( + "requestId", + TikiSdkOwnership("source", TikiSdkDataTypeEnum.data_point, "com.mytiki.rsp", "txnId") + ) + val json = adapter.toJson(rsp) + Assert.assertEquals( + "{\"requestId\":\"requestId\",\"ownership\":{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.rsp\",\"transactionId\":\"txnId\",\"contains\":[]}}", + json + ) + } +} \ No newline at end of file From b1173304cde56c98261c7ec947ed3d35d2fedf7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Thu, 22 Dec 2022 11:23:51 -0300 Subject: [PATCH 17/20] update Android API and add coroutines closes #49, closes #34 --- .../com/mytiki/tiki_sdk_android/TikiSdk.kt | 242 +++++++++++------- .../TikiSdkFlutterChannel.kt | 27 +- .../tiki_platform_channel/req/ReqBuild.kt | 8 +- .../req/ReqConsentApply.kt | 9 +- .../req/ReqConsentGet.kt | 10 +- .../req/ReqConsentModify.kt | 11 +- .../req/ReqOwnershipAssign.kt | 10 +- .../req/ReqOwnershipGet.kt | 11 +- .../tiki_platform_channel/rsp/Rsp.kt | 2 +- .../tiki_platform_channel/rsp/RspBuild.kt | 6 +- .../rsp/RspConsentApply.kt | 2 +- .../rsp/RspConsentGet.kt | 2 +- .../tiki_platform_channel/rsp/RspError.kt | 2 +- .../tiki_platform_channel/rsp/RspOwnership.kt | 4 +- .../TikiSdkDataTypeEnumTest.kt | 2 +- 15 files changed, 216 insertions(+), 132 deletions(-) rename app/src/main/kotlin/com/mytiki/tiki_sdk_android/{ => tiki_platform_channel}/TikiSdkFlutterChannel.kt (72%) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt index 5d91fdb..f2675b8 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt @@ -1,16 +1,32 @@ package com.mytiki.tiki_sdk_android import android.content.Context +import com.mytiki.tiki_sdk_android.tiki_platform_channel.TikiSdkFlutterChannel +import com.mytiki.tiki_sdk_android.tiki_platform_channel.req.* +import com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp.RspBuild +import com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp.RspConsentApply +import com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp.RspConsentGet +import com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp.RspOwnership +import com.squareup.moshi.Moshi import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.dart.DartExecutor import io.flutter.embedding.engine.loader.FlutterLoader import io.flutter.plugins.GeneratedPluginRegistrant +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking import java.util.* -class TikiSdk(apiId: String, origin: String, context: Context) { +class TikiSdk(apiId: String, origin: String, context: Context, address: String? = null) { + private var tikiSdkFlutterChannel: TikiSdkFlutterChannel + private val moshi = Moshi.Builder().build() + var completables: MutableMap> = mutableMapOf() + val address: String init { + val buildRequest = ReqBuild("build", apiId, origin, address) + val buildRequestJson = (buildRequest) val loader = FlutterLoader() loader.startInitialization(context) loader.ensureInitializationComplete(context, null) @@ -19,154 +35,186 @@ class TikiSdk(apiId: String, origin: String, context: Context) { GeneratedPluginRegistrant.registerWith(flutterEngine) tikiSdkFlutterChannel = TikiSdkFlutterChannel() flutterEngine.plugins.add(tikiSdkFlutterChannel) - build(apiId, origin) + tikiSdkFlutterChannel.channel.invokeMethod( + "build", listOf( "request" to buildRequestJson ) + ) + val deferred = CompletableDeferred() + completables["build"] = deferred + runBlocking(Dispatchers.IO) { + val response: String = deferred.await()!! + val rspBuild: RspBuild = moshi.adapter(RspBuild::class.java).fromJson(response)!! + this@TikiSdk.address = rspBuild.address + } } - /** - * Assign ownership to a given [source]. - * - * The [type] identifies which type the ownership refers to. - * The list of items the data contains is described by [contains]. Optionally, - * a description about this ownership can be given in [about] and the [origin] - * can be overridden for the specific ownership grant. + /** Assign ownership to a given source. * * @param source String The source of the data (reversed FQDN of the company or product) * @param type String The type of data: point, pool, or stream * @param contains List The list data assets (email, phone, images, etc) - * @param callback ((ownershipId: String) -> Unit)? Optional callback to handle the ownershipId + * @param about String? Optional description about the data. * @param origin String? Optionally overrides the default origin * + * @return [TikiSdkOwnership] */ fun assignOwnership( source: String, - type: String, - callback: ((ownershipId: String) -> Unit)? = null, - contains: List? = null, + type: TikiSdkDataTypeEnum, + contains: List, about: String? = null, origin: String? = null - ) { - tikiSdkFlutterChannel.invokeMethod( - "assignOwnership", mutableMapOf( - "source" to source, - "about" to about, - "type" to type, - "contains" to contains, - "origin" to origin - ) + ): TikiSdkOwnership { + val requestId = UUID.randomUUID().toString() + var jsonString: String + tikiSdkFlutterChannel.channel.invokeMethod( + "assignOwnership", ReqOwnershipAssign( + requestId, source, type, contains, about, origin + ).toJson() ) - { result, response -> - if (result) callback?.invoke(response) + val deferred = CompletableDeferred() + completables[requestId] = deferred + runBlocking (Dispatchers.IO) { + jsonString = deferred.await()!! } + val rsp = moshi.adapter(RspOwnership::class.java).fromJson(jsonString) + return rsp!!.ownership } /** - * Modify consent for using the [source] in [destination]. + * Get ownership * - * This method overrides any consent that was given before. Ownership must be granted before - * modifying consent. - * Consent is applied on an explicit only basis. Meaning all requests will be denied by default - * unless the destination is explicitly defined in [destination]. - * A blank list of [TikiSdkDestination.uses] or [TikiSdkDestination.paths] means revoked consent. + * @param source String The source of the data (reversed FQDN of the company or product) + * @param origin String? Optionally overrides the default origin * - * @param source String - * @param destination TikiSdkDestination - * @param about String? - * @param reward String? - * @param expiry Calendar? - * @param callback ((consent: [TikiSdkConsent]) -> Unit)? Optional callback to handle the [TikiSdkConsent] object. + * @return [TikiSdkOwnership], null if not found + */ + fun getOwnership( + source: String, + origin: String? = null + ): TikiSdkOwnership? { + val requestId = UUID.randomUUID().toString() + var jsonString: String + tikiSdkFlutterChannel.channel.invokeMethod( + "assignOwnership", ReqOwnershipGet( + requestId, source, origin + ).toJson() + ) + val deferred = CompletableDeferred() + completables[requestId] = deferred + runBlocking (Dispatchers.IO) { + jsonString = deferred.await()!! + } + val rsp = moshi.adapter(RspOwnership::class.java).fromJson(jsonString) + return rsp?.ownership + } + /** + * Modify consent for an ownership identified by [ownershipId]. + * + * The Ownership must be granted before modifying consent. Consent is applied + * on an explicit only basis. Meaning all requests will be denied by default + * unless the destination is explicitly defined in *destination*. + * A blank list of [TikiSdkDestination.uses] or [TikiSdkDestination.paths] + * means revoked consent. + * + * @param ownershipId String The transaction id of the ownership registry. + * @param destination TikiSdkDestination + * @param about String? Optional description about the data. + * @param reward String? Optional reward the user will receive for granting consent. + * @param expiry Date? Optional expiration for the consent. + * @return */ fun modifyConsent( - source: String, + ownershipId: String, destination: TikiSdkDestination, - callback: ((TikiSdkConsent) -> Unit)? = null, about: String? = null, reward: String? = null, - expiry: Calendar? = null - ) { - tikiSdkFlutterChannel.invokeMethod("modifyConsent", mutableMapOf( - "source" to source, - "destination" to destination.toJson(), - "about" to about, - "reward" to reward, - "expiry" to expiry?.let { it.timeInMillis / 1000 } - )) - { result, response -> - if (result) callback?.invoke(TikiSdkConsent.fromJson(response)) + expiry: Date? = null + ): TikiSdkConsent{ + val requestId = UUID.randomUUID().toString() + var jsonString: String + tikiSdkFlutterChannel.channel.invokeMethod( + "assignOwnership", ReqConsentModify( + requestId, ownershipId, destination, about, reward, expiry?.time + ).toJson() + ) + val deferred = CompletableDeferred() + completables[requestId] = deferred + runBlocking (Dispatchers.IO) { + jsonString = deferred.await()!! } + val rsp = moshi.adapter(RspConsentGet::class.java).fromJson(jsonString) + return rsp!!.consent } /** - * Get consent + * Gets latest consent given for a *source* and *origin*. * - * Gets latest consent given for a [source] and [origin]. It does not validate if the consent is - * expired or if it can be applied to a specific destination. For that, [applyConsent] should be - * used instead. + * It does not validate if the consent is expired or if it can be applied to + * a specific destination. For that, [applyConsent] should be used instead. + * If no [origin] is specified, it uses the default origin. * - * @param source String The source of the data (reversed FQDN of the company or product) - * @param callback ((consent: [TikiSdkConsent]) -> Unit)? Optional callback to handle the [TikiSdkConsent] object. - * @param origin String? Optionally overrides the default origin + * @param source String + * @param origin String? + * + * @return TikiSdkConsent */ fun getConsent( source: String, - callback: ((TikiSdkConsent) -> Unit)? = null, origin: String? = null - ) { - tikiSdkFlutterChannel.invokeMethod( - "getConsent", mutableMapOf( - "source" to source, - "origin" to origin - ) + ): TikiSdkConsent? { + val requestId = UUID.randomUUID().toString() + var jsonString: String + tikiSdkFlutterChannel.channel.invokeMethod( + "assignOwnership", ReqConsentGet( + requestId, source, origin + ).toJson() ) - { result, response -> - if (result) callback?.invoke(TikiSdkConsent.fromJson(response)) + val deferred = CompletableDeferred() + completables[requestId] = deferred + runBlocking (Dispatchers.IO) { + jsonString = deferred.await()!! } + val rsp = moshi.adapter(RspConsentGet::class.java).fromJson(jsonString) + return rsp?.consent } /** - * Apply consent for a given [source] and [destination]. + * Apply consent for a given [source] and [destination]. * - * If consent exists for the destination and is not expired, [request] will be - * executed. Else [onBlocked] is called. + * If consent exists for the destination and is not expired, [request] will be + * executed. Else [onBlocked] is called. * * @param source String * @param destination TikiSdkDestination - * @param request (String) -> Unit - * @param onBlocked (String) -> Unit - * + * @param origin String? + * @param request () -> Unit + * @param onBlocked () -> Unit */ fun applyConsent( source: String, destination: TikiSdkDestination, - request: (String) -> Unit, - onBlocked: (String) -> Unit + origin: String?, + request: () -> Unit, + onBlocked: (value: String) -> Unit ) { - tikiSdkFlutterChannel.invokeMethod( - "applyConsent", mutableMapOf( - "source" to source, - "destination" to destination.toJson() - ) + val requestId = UUID.randomUUID().toString() + var jsonString: String + tikiSdkFlutterChannel.channel.invokeMethod( + "assignOwnership", ReqConsentApply( + requestId, source, destination, origin + ).toJson() ) - { result, response -> - if (result) { - request(response) - } else { - onBlocked("no consent") - } + val deferred = CompletableDeferred() + completables[requestId] = deferred + runBlocking (Dispatchers.IO) { + jsonString = deferred.await()!! } - } - - private fun build(apiId: String, origin: String) { - tikiSdkFlutterChannel.invokeMethod( - "build", mutableMapOf( - "apiId" to apiId, - "origin" to origin - ) - ) - { result, _ -> - if (!result) { - throw RuntimeException("Failed to build TikiSdk") - } + val rsp = moshi.adapter(RspConsentApply::class.java).fromJson(jsonString) + if(rsp!!.success){ + request() + }else{ + onBlocked(rsp.reason ?: "no consent") } } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkFlutterChannel.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt similarity index 72% rename from app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkFlutterChannel.kt rename to app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt index de2b04c..e4653f6 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkFlutterChannel.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt @@ -1,4 +1,8 @@ -package com.mytiki.tiki_sdk_android +/* + * Copyright (c) TIKI Inc. + * MIT license. See LICENSE file in root directory. + */ +package com.mytiki.tiki_sdk_android.tiki_platform_channel import androidx.annotation.NonNull import io.flutter.embedding.engine.plugins.FlutterPlugin @@ -6,20 +10,14 @@ import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import java.util.* /** - * Tiki sdk plugin - * - * @property apiKey - * @property origin - * @constructor + * Tiki sdk flutter channel * - * @param context + * @constructor Create empty Tiki sdk flutter channel */ - -class TikiSdkFlutterChannel : FlutterPlugin, MethodCallHandler { - private lateinit var channel: MethodChannel +class TikiSdkFlutterChannel : FlutterPlugin, MethodCallHandler { + lateinit var channel: MethodChannel private var callbacks: MutableMap Unit> = mutableMapOf() override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { @@ -47,11 +45,4 @@ class TikiSdkFlutterChannel : FlutterPlugin, MethodCallHandler { override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) } - - fun invokeMethod(method: String, arguments: MutableMap, callback: ((Boolean, String) -> Unit)) { - val requestId = UUID.randomUUID().toString() - callbacks[requestId] = callback - arguments["requestId"] = requestId - channel.invokeMethod(method, arguments) - } } diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt index b2179a6..884ff2b 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqBuild.kt @@ -5,6 +5,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.squareup.moshi.JsonClass +import com.squareup.moshi.Moshi /** * The request for the `build` method call in the Platform Channel. @@ -24,4 +25,9 @@ data class ReqBuild( val apiId: String, val origin: String, val address: String? = null -) : Req(requestId) +) : Req(requestId) { + + fun toJson(): String { + return Moshi.Builder().build().adapter(ReqBuild::class.java).toJson(this) + } +} diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt index 5410cd0..510e9f4 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentApply.kt @@ -6,6 +6,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.TikiSdkDestination import com.squareup.moshi.JsonClass +import com.squareup.moshi.Moshi /** * The request for the `applyConsent` method call in the Platform Channel. @@ -24,4 +25,10 @@ data class ReqConsentApply( val source: String, val destination: TikiSdkDestination, val origin: String? = null -) : Req(requestId) +) : Req(requestId) { + + fun toJson(): String { + return Moshi.Builder().build().adapter(ReqConsentApply::class.java).toJson(this) + } + +} diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt index 6c68b07..fe45ced 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentGet.kt @@ -5,6 +5,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.squareup.moshi.JsonClass +import com.squareup.moshi.Moshi /** * The request for the `getConsent` call in the Platform Channel. @@ -19,4 +20,11 @@ data class ReqConsentGet( override val requestId: String, val source: String, val origin: String? -) : Req(requestId) +) : Req(requestId) { + + fun toJson(): String { + return Moshi.Builder().build().adapter(ReqConsentGet::class.java).toJson(this) + } + +} + diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt index f831a37..0fddbdc 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqConsentModify.kt @@ -6,6 +6,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.TikiSdkDestination import com.squareup.moshi.JsonClass +import com.squareup.moshi.Moshi /** * The request for the `modifyConsent`method call in the Platform Channel. @@ -25,5 +26,11 @@ data class ReqConsentModify( val destination: TikiSdkDestination, val about: String? = null, val reward: String? = null, - val expiry: Int? = null -) : Req(requestId) + val expiry: Long? = null +) : Req(requestId) { + + fun toJson(): String { + return Moshi.Builder().build().adapter(ReqConsentModify::class.java).toJson(this) + } + +} diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt index c26d3ba..b8318e4 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipAssign.kt @@ -6,6 +6,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.mytiki.tiki_sdk_android.TikiSdkDataTypeEnum import com.squareup.moshi.JsonClass +import com.squareup.moshi.Moshi /** * The request for the `assignOwnership` method call in the Platform Channel. @@ -26,4 +27,11 @@ data class ReqOwnershipAssign( val contains: List, val about: String? = null, val origin: String? = null -) : Req(requestId) +) : Req(requestId) { + + fun toJson(): String { + return Moshi.Builder().build().adapter(ReqOwnershipAssign::class.java).toJson(this) + } + +} + diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt index 8398d44..1511b47 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/req/ReqOwnershipGet.kt @@ -5,6 +5,7 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel.req import com.squareup.moshi.JsonClass +import com.squareup.moshi.Moshi /** * The request for the `getOwnership` method call in the Platform Channel. @@ -19,4 +20,12 @@ data class ReqOwnershipGet( override val requestId: String, val source: String, val origin: String? = null -) : Req(requestId) +) : Req(requestId) { + + fun toJson(): String { + return Moshi.Builder().build().adapter(ReqOwnershipGet::class.java).toJson(this) + } + +} + + diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt index 9e4dad7..7d147ef 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/Rsp.kt @@ -16,5 +16,5 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) open class Rsp( - open val requestId : String + open val requestId: String ) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt index 82c7395..c78b4f5 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspBuild.kt @@ -15,7 +15,7 @@ import com.squareup.moshi.JsonClass * @constructor Create empty Rsp build */ @JsonClass(generateAdapter = true) -data class RspBuild ( +data class RspBuild( override val requestId: String, - val address : String -): Rsp(requestId) + val address: String +) : Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt index d16d4f3..c9178e2 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentApply.kt @@ -22,4 +22,4 @@ data class RspConsentApply( override val requestId: String, val success: Boolean, val reason: String? = null -):Rsp(requestId) +) : Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt index bbec2c8..20761d4 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspConsentGet.kt @@ -20,4 +20,4 @@ import com.squareup.moshi.JsonClass data class RspConsentGet( override val requestId: String, val consent: TikiSdkConsent -): Rsp(requestId) +) : Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt index f977f54..af896fd 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspError.kt @@ -21,4 +21,4 @@ data class RspError( override val requestId: String, val message: String, val stackTrace: String -): Rsp(requestId) +) : Rsp(requestId) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt index 0107c22..ce4cf4f 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/rsp/RspOwnership.kt @@ -19,5 +19,5 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class RspOwnership( override val requestId: String, - val ownership : TikiSdkOwnership -): Rsp(requestId) + val ownership: TikiSdkOwnership +) : Rsp(requestId) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt index c1e49b3..ffda079 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt @@ -10,7 +10,7 @@ class TikiSdkDataTypeEnumTest { fun encode_TikiSdkDataTypeEnum_from_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(TikiSdkDataTypeEnum::class.java) - val tikiSdkDataTypeEnum = adapter.fromJson("\"data_pool\""); + val tikiSdkDataTypeEnum = adapter.fromJson("\"data_pool\"") Assert.assertEquals(TikiSdkDataTypeEnum.data_pool.name, tikiSdkDataTypeEnum?.name) } @Test From e6e27d4788628cc424ae5560dab2ffd364e30bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Thu, 22 Dec 2022 11:55:24 -0300 Subject: [PATCH 18/20] reformat code and finish API update --- .../com/mytiki/tiki_sdk_android/TikiSdk.kt | 78 +++++++++++-------- .../tiki_sdk_android/TikiSdkDestination.kt | 2 +- .../tiki_sdk_android/TikiSdkOwnership.kt | 14 ++-- .../TikiSdkFlutterChannel.kt | 20 ++--- .../tiki_sdk_android/TikiSdkConsentTest.kt | 12 ++- .../TikiSdkDataTypeEnumTest.kt | 7 +- .../TikiSdkDestinationTest.kt | 1 + .../tiki_sdk_android/TikiSdkOwnershipTest.kt | 15 +++- 8 files changed, 90 insertions(+), 59 deletions(-) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt index f2675b8..ab9912b 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt @@ -26,7 +26,8 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? init { val buildRequest = ReqBuild("build", apiId, origin, address) - val buildRequestJson = (buildRequest) + val buildRequestJson = buildRequest.toJson() + var jsonString: String val loader = FlutterLoader() loader.startInitialization(context) loader.ensureInitializationComplete(context, null) @@ -34,17 +35,18 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? flutterEngine.dartExecutor.executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault()) GeneratedPluginRegistrant.registerWith(flutterEngine) tikiSdkFlutterChannel = TikiSdkFlutterChannel() + tikiSdkFlutterChannel.tikiSdk = this flutterEngine.plugins.add(tikiSdkFlutterChannel) tikiSdkFlutterChannel.channel.invokeMethod( - "build", listOf( "request" to buildRequestJson ) + "build", listOf("request" to buildRequestJson) ) val deferred = CompletableDeferred() completables["build"] = deferred runBlocking(Dispatchers.IO) { - val response: String = deferred.await()!! - val rspBuild: RspBuild = moshi.adapter(RspBuild::class.java).fromJson(response)!! - this@TikiSdk.address = rspBuild.address + jsonString = deferred.await()!! } + val rspBuild: RspBuild = moshi.adapter(RspBuild::class.java).fromJson(jsonString)!! + this@TikiSdk.address = rspBuild.address } /** Assign ownership to a given source. @@ -55,7 +57,7 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? * @param about String? Optional description about the data. * @param origin String? Optionally overrides the default origin * - * @return [TikiSdkOwnership] + * @return [TikiSdkOwnership] transaction Id */ fun assignOwnership( source: String, @@ -63,21 +65,23 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? contains: List, about: String? = null, origin: String? = null - ): TikiSdkOwnership { + ): String { val requestId = UUID.randomUUID().toString() var jsonString: String tikiSdkFlutterChannel.channel.invokeMethod( - "assignOwnership", ReqOwnershipAssign( - requestId, source, type, contains, about, origin - ).toJson() + "assignOwnership", mapOf( + "request" to ReqOwnershipAssign( + requestId, source, type, contains, about, origin + ).toJson() + ) ) val deferred = CompletableDeferred() completables[requestId] = deferred - runBlocking (Dispatchers.IO) { + runBlocking(Dispatchers.IO) { jsonString = deferred.await()!! } val rsp = moshi.adapter(RspOwnership::class.java).fromJson(jsonString) - return rsp!!.ownership + return rsp!!.ownership.transactionId } /** @@ -95,13 +99,15 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? val requestId = UUID.randomUUID().toString() var jsonString: String tikiSdkFlutterChannel.channel.invokeMethod( - "assignOwnership", ReqOwnershipGet( - requestId, source, origin - ).toJson() + "assignOwnership", mapOf( + "request" to ReqOwnershipGet( + requestId, source, origin + ).toJson() + ) ) val deferred = CompletableDeferred() completables[requestId] = deferred - runBlocking (Dispatchers.IO) { + runBlocking(Dispatchers.IO) { jsonString = deferred.await()!! } val rsp = moshi.adapter(RspOwnership::class.java).fromJson(jsonString) @@ -130,17 +136,19 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? about: String? = null, reward: String? = null, expiry: Date? = null - ): TikiSdkConsent{ + ): TikiSdkConsent { val requestId = UUID.randomUUID().toString() var jsonString: String tikiSdkFlutterChannel.channel.invokeMethod( - "assignOwnership", ReqConsentModify( - requestId, ownershipId, destination, about, reward, expiry?.time - ).toJson() + "assignOwnership", mapOf( + "request" to ReqConsentModify( + requestId, ownershipId, destination, about, reward, expiry?.time + ).toJson() + ) ) val deferred = CompletableDeferred() completables[requestId] = deferred - runBlocking (Dispatchers.IO) { + runBlocking(Dispatchers.IO) { jsonString = deferred.await()!! } val rsp = moshi.adapter(RspConsentGet::class.java).fromJson(jsonString) @@ -166,13 +174,15 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? val requestId = UUID.randomUUID().toString() var jsonString: String tikiSdkFlutterChannel.channel.invokeMethod( - "assignOwnership", ReqConsentGet( - requestId, source, origin - ).toJson() + "assignOwnership", mapOf( + "request" to ReqConsentGet( + requestId, source, origin + ).toJson() + ) ) val deferred = CompletableDeferred() completables[requestId] = deferred - runBlocking (Dispatchers.IO) { + runBlocking(Dispatchers.IO) { jsonString = deferred.await()!! } val rsp = moshi.adapter(RspConsentGet::class.java).fromJson(jsonString) @@ -194,26 +204,28 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? fun applyConsent( source: String, destination: TikiSdkDestination, - origin: String?, request: () -> Unit, - onBlocked: (value: String) -> Unit + onBlocked: (value: String) -> Unit, + origin: String?, ) { val requestId = UUID.randomUUID().toString() var jsonString: String tikiSdkFlutterChannel.channel.invokeMethod( - "assignOwnership", ReqConsentApply( - requestId, source, destination, origin - ).toJson() + "assignOwnership", mapOf( + "request" to ReqConsentApply( + requestId, source, destination, origin + ).toJson() + ) ) val deferred = CompletableDeferred() completables[requestId] = deferred - runBlocking (Dispatchers.IO) { + runBlocking(Dispatchers.IO) { jsonString = deferred.await()!! } val rsp = moshi.adapter(RspConsentApply::class.java).fromJson(jsonString) - if(rsp!!.success){ + if (rsp!!.success) { request() - }else{ + } else { onBlocked(rsp.reason ?: "no consent") } } diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt index b7a29a3..966952b 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkDestination.kt @@ -29,7 +29,7 @@ open class TikiSdkDestination( * to invert. _i.e. NOT ads */ val uses: List = listOf("*"), -){ +) { /** * TikiSdkDestination.ALL * diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt index de96b14..6989e7c 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdkOwnership.kt @@ -4,7 +4,7 @@ import com.squareup.moshi.JsonClass /** * The Ownership NFT. - * + * * The registry of ownership to a given data point, pool, or stream. */ @JsonClass(generateAdapter = true) @@ -13,31 +13,31 @@ class TikiSdkOwnership( /** * The identification of the source. */ - val source : String, + val source: String, /** * The type of the data source: data point, pool or stream. */ - val type : TikiSdkDataTypeEnum, + val type: TikiSdkDataTypeEnum, /** * The origin from which the data was generated. */ - val origin : String, + val origin: String, /** * The transaction id of this registry. */ - val transactionId : String, + val transactionId: String, /** * The kinds of data this contains. */ - val contains : List = listOf(), + val contains: List = listOf(), /** * The description about the data. */ - val about : String? = null, + val about: String? = null, ) diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt index e4653f6..ff89f7c 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/tiki_platform_channel/TikiSdkFlutterChannel.kt @@ -5,11 +5,15 @@ package com.mytiki.tiki_sdk_android.tiki_platform_channel import androidx.annotation.NonNull +import com.mytiki.tiki_sdk_android.TikiSdk +import com.mytiki.tiki_sdk_android.tiki_platform_channel.rsp.RspError +import com.squareup.moshi.Moshi import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result +import org.json.JSONObject /** * Tiki sdk flutter channel @@ -17,8 +21,8 @@ import io.flutter.plugin.common.MethodChannel.Result * @constructor Create empty Tiki sdk flutter channel */ class TikiSdkFlutterChannel : FlutterPlugin, MethodCallHandler { + lateinit var tikiSdk: TikiSdk lateinit var channel: MethodChannel - private var callbacks: MutableMap Unit> = mutableMapOf() override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { channel = MethodChannel(flutterPluginBinding.binaryMessenger, "tiki_sdk_flutter") @@ -26,20 +30,18 @@ class TikiSdkFlutterChannel : FlutterPlugin, MethodCallHandler { } override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { - val requestId: String? = call.argument("requestId") - val response: String? = call.argument("response") - if (requestId == null) result.error("-1", "missing requestId argument", call.arguments) - val callback = callbacks[requestId] + val response = call.argument("response")!! + val jsonMap = JSONObject(response) + val requestId = jsonMap["requestId"] when (call.method) { "success" -> { - if (callback != null) callback(true, response ?: "") + tikiSdk.completables[requestId]?.complete(response) } "error" -> { - if (callback != null) callback(false, response ?: "") + val error = Moshi.Builder().build().adapter(RspError::class.java).fromJson(response) + tikiSdk.completables[requestId]?.completeExceptionally(Error(error?.message)) } - else -> result.notImplemented() } - callbacks.remove(requestId) } override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt index a0b0d7c..0ce7345 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkConsentTest.kt @@ -10,7 +10,8 @@ class TikiSdkConsentTest { fun encode_TikiSdkConsent_from_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(TikiSdkConsent::class.java) - val tikiSdkConsent = adapter.fromJson("{\"ownershipId\":\"ownership\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}") + val tikiSdkConsent = + adapter.fromJson("{\"ownershipId\":\"ownership\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}") Assert.assertEquals("ownership", tikiSdkConsent?.ownershipId) Assert.assertEquals("*", tikiSdkConsent?.destination?.uses?.get(0)) Assert.assertEquals("txnId", tikiSdkConsent?.transactionId) @@ -18,13 +19,18 @@ class TikiSdkConsentTest { Assert.assertNull(tikiSdkConsent?.reward) Assert.assertNull(tikiSdkConsent?.expiry) } + @Test fun encode_TikiSdkConsent_to_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(TikiSdkConsent::class.java) val tikiSdkConsent = TikiSdkConsent( - "ownership", TikiSdkDestination.ALL, "txnId") + "ownership", TikiSdkDestination.ALL, "txnId" + ) val json = adapter.toJson(tikiSdkConsent) - Assert.assertEquals("{\"ownershipId\":\"ownership\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}",json) + Assert.assertEquals( + "{\"ownershipId\":\"ownership\",\"destination\":{\"paths\":[\"*\"],\"uses\":[\"*\"]},\"transactionId\":\"txnId\"}", + json + ) } } \ No newline at end of file diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt index ffda079..d2c28c3 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDataTypeEnumTest.kt @@ -9,14 +9,17 @@ class TikiSdkDataTypeEnumTest { @Test fun encode_TikiSdkDataTypeEnum_from_JSON() { val moshi: Moshi = Moshi.Builder().build() - val adapter: JsonAdapter = moshi.adapter(TikiSdkDataTypeEnum::class.java) + val adapter: JsonAdapter = + moshi.adapter(TikiSdkDataTypeEnum::class.java) val tikiSdkDataTypeEnum = adapter.fromJson("\"data_pool\"") Assert.assertEquals(TikiSdkDataTypeEnum.data_pool.name, tikiSdkDataTypeEnum?.name) } + @Test fun encode_TikiSdkDataTypeEnum_ALL_and_NONE_to_JSON() { val moshi: Moshi = Moshi.Builder().build() - val adapter: JsonAdapter = moshi.adapter(TikiSdkDataTypeEnum::class.java) + val adapter: JsonAdapter = + moshi.adapter(TikiSdkDataTypeEnum::class.java) val tikiSdkDataTypeEnum = TikiSdkDataTypeEnum.data_pool val poolJson = adapter.toJson(tikiSdkDataTypeEnum) Assert.assertEquals("\"data_pool\"", poolJson) diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt index 7a0c2d7..ca94f8e 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkDestinationTest.kt @@ -14,6 +14,7 @@ class TikiSdkDestinationTest { Assert.assertEquals("*", tikiSdkDestination?.uses?.get(0)) Assert.assertEquals("*", tikiSdkDestination?.paths?.get(0)) } + @Test fun encode_TikiSdkDestination_ALL_and_NONE_to_JSON() { val moshi: Moshi = Moshi.Builder().build() diff --git a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt index c9ce684..f1c5073 100644 --- a/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt +++ b/app/src/test/java/com/mytiki/tiki_sdk_android/TikiSdkOwnershipTest.kt @@ -10,7 +10,8 @@ class TikiSdkOwnershipTest { fun encode_TikiSdkOwnership_from_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(TikiSdkOwnership::class.java) - val json = "{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.test\",\"transactionId\":\"txnId\",\"contains\":[\"test data\"]}" + val json = + "{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.test\",\"transactionId\":\"txnId\",\"contains\":[\"test data\"]}" val ownership = adapter.fromJson(json) Assert.assertEquals("source", ownership?.source) Assert.assertEquals(TikiSdkDataTypeEnum.data_point.name, ownership?.type?.name) @@ -19,13 +20,19 @@ class TikiSdkOwnershipTest { Assert.assertNull(ownership?.about) } + @Test fun encode_TikiSdkOwnership_to_JSON() { val moshi: Moshi = Moshi.Builder().build() val adapter: JsonAdapter = moshi.adapter(TikiSdkOwnership::class.java) - val tikiSdkConsent = TikiSdkOwnership("source", TikiSdkDataTypeEnum.data_point, - "com.mytiki.test", "txnId", listOf("test data")) + val tikiSdkConsent = TikiSdkOwnership( + "source", TikiSdkDataTypeEnum.data_point, + "com.mytiki.test", "txnId", listOf("test data") + ) val json = adapter.toJson(tikiSdkConsent) - Assert.assertEquals("{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.test\",\"transactionId\":\"txnId\",\"contains\":[\"test data\"]}",json) + Assert.assertEquals( + "{\"source\":\"source\",\"type\":\"data_point\",\"origin\":\"com.mytiki.test\",\"transactionId\":\"txnId\",\"contains\":[\"test data\"]}", + json + ) } } \ No newline at end of file From 4681e60ed19705d757b2190756d2827460bcb912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Thu, 22 Dec 2022 12:12:06 -0300 Subject: [PATCH 19/20] update integration tests --- .../mytiki/tiki_sdk_android/TikiSdkTest.kt | 85 ++++++++----------- .../com/mytiki/tiki_sdk_android/TikiSdk.kt | 6 +- 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt b/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt index d1073ef..8dea18a 100644 --- a/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt +++ b/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt @@ -2,7 +2,6 @@ package com.mytiki.tiki_sdk_android import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation -import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith @@ -13,70 +12,58 @@ const val ORIGIN: String = "com.mytiki.tiki_sdk_android.test" @RunWith(AndroidJUnit4::class) class TikiSdkTest { - val callback = { - response: String -> print(response) - } - @Test fun init_tiki_sdk() { - getInstrumentation().runOnMainSync { - val context = getInstrumentation().targetContext - val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) - Assert.assertNotNull(tikiSdk) - } + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + assert(tikiSdk.address.length > 32) } @Test fun assign_onwership() { - getInstrumentation().runOnMainSync { - val context = getInstrumentation().targetContext - val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) - tikiSdk.assignOwnership( - "com.mytiki.androidtest", - "data_point", callback, listOf("nothing") - ) - } + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + val ownershipId = tikiSdk.assignOwnership("source", TikiSdkDataTypeEnum.data_point, listOf("test")) + assert(ownershipId.length > 32) } @Test - fun give_consent() { - getInstrumentation().runOnMainSync { - val context = getInstrumentation().targetContext - val tikiSdk = TikiSdk(ORIGIN, API_KEY, context) - tikiSdk.assignOwnership("com.mytiki.test", "pool") - tikiSdk.modifyConsent("com.mytiki.test", TikiSdkDestination(listOf("*"), listOf("*")),) - assertEquals(1, 1) - } + fun get_onwership() { + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + val ownershipId = tikiSdk.assignOwnership("source", TikiSdkDataTypeEnum.data_point, listOf("test")) + val ownership = tikiSdk.getOwnership("source") + assertEquals(ownershipId, ownership!!.transactionId) } @Test fun modify_consent() { - getInstrumentation().runOnMainSync { - val context = getInstrumentation().targetContext - val sdk = TikiSdk(API_KEY, ORIGIN, context) - sdk.assignOwnership("com.mytiki.test", "pool") - sdk.modifyConsent("com.mytiki.test", TikiSdkDestination(listOf("*"), listOf("*"))) - sdk.modifyConsent("com.mytiki.test", TikiSdkDestination(listOf(), listOf())) - assertEquals(1, 1) - } + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + val ownershipId = tikiSdk.assignOwnership("source", TikiSdkDataTypeEnum.data_point, listOf("test")) + val consent = tikiSdk.modifyConsent(ownershipId, TikiSdkDestination.ALL) + assertEquals(consent.ownershipId, ownershipId) + } + + fun get_consent() { + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + val ownershipId = tikiSdk.assignOwnership("source", TikiSdkDataTypeEnum.data_point, listOf("test")) + val consent = tikiSdk.modifyConsent(ownershipId, TikiSdkDestination.ALL) + val consentGet = tikiSdk.getConsent("source") + assertEquals(consent.transactionId, consentGet!!.transactionId) } @Test fun apply_consent() { - getInstrumentation().runOnMainSync { - var ok = false - val context = getInstrumentation().targetContext - val sdk = TikiSdk(API_KEY, ORIGIN, context) - sdk.assignOwnership("com.mytiki.test", "pool") - sdk.modifyConsent("com.mytiki.test", TikiSdkDestination(listOf("*"), listOf("*"))) - sdk.applyConsent("com.mytiki.test", TikiSdkDestination(listOf("*"), listOf("*")), - { - ok = true - }, - { - ok = false - }) - Thread.sleep(1000) - } + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + val ownershipId = tikiSdk.assignOwnership("source", TikiSdkDataTypeEnum.data_point, listOf("test")) + tikiSdk.modifyConsent(ownershipId, TikiSdkDestination.ALL) + var ok = false + tikiSdk.applyConsent("source", TikiSdkDestination.ALL, { + ok = true + }) + assert(ok) } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt index ab9912b..9301f25 100644 --- a/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt +++ b/app/src/main/kotlin/com/mytiki/tiki_sdk_android/TikiSdk.kt @@ -205,8 +205,8 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? source: String, destination: TikiSdkDestination, request: () -> Unit, - onBlocked: (value: String) -> Unit, - origin: String?, + onBlocked: ((value: String) -> Unit)? = null, + origin: String? = null, ) { val requestId = UUID.randomUUID().toString() var jsonString: String @@ -226,7 +226,7 @@ class TikiSdk(apiId: String, origin: String, context: Context, address: String? if (rsp!!.success) { request() } else { - onBlocked(rsp.reason ?: "no consent") + onBlocked?.invoke(rsp.reason ?: "no consent") } } } \ No newline at end of file From 877d17367624a7a03acec3ab70dee2255e399994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Thu, 22 Dec 2022 12:14:38 -0300 Subject: [PATCH 20/20] add test - init sdk with address --- .../java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt b/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt index 8dea18a..de56a05 100644 --- a/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt +++ b/app/src/androidTest/java/com/mytiki/tiki_sdk_android/TikiSdkTest.kt @@ -19,6 +19,15 @@ class TikiSdkTest { assert(tikiSdk.address.length > 32) } + @Test + fun init_tiki_sdk_with_address() { + val context = getInstrumentation().targetContext + val tikiSdk = TikiSdk(API_KEY, ORIGIN, context) + val address = tikiSdk.address + val tikiSdk2 = TikiSdk(API_KEY, ORIGIN, context, address) + assertEquals(tikiSdk.address, tikiSdk2.address) + } + @Test fun assign_onwership() { val context = getInstrumentation().targetContext