From 8e23e02e0bbe7a98675c3ef30ebdb63ffe0f2066 Mon Sep 17 00:00:00 2001 From: Michael Rudolph Date: Mon, 13 Aug 2018 16:35:11 +0200 Subject: [PATCH] bugfixes and tests - failing scope permissions fix in interceptor - fixes models fpr presences - adds new test for presence --- build.gradle | 2 +- .../api/presence/model/PresenceHome.kt | 9 +++++++- .../netatmo/api/presence/model/User.kt | 5 ++++- .../networkinterceptor/AuthInterceptor.kt | 21 ++++++++++++------- src/test/kotlin/apitest/PresenceTest.kt | 16 ++++++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 src/test/kotlin/apitest/PresenceTest.kt diff --git a/build.gradle b/build.gradle index f528612..8f8d5cf 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { } group 'io.rudolph.netatmo' -version '0.3.1' +version '0.3.2' repositories { mavenCentral() diff --git a/src/main/java/io/rudolph/netatmo/api/presence/model/PresenceHome.kt b/src/main/java/io/rudolph/netatmo/api/presence/model/PresenceHome.kt index 4613792..72e3d85 100644 --- a/src/main/java/io/rudolph/netatmo/api/presence/model/PresenceHome.kt +++ b/src/main/java/io/rudolph/netatmo/api/presence/model/PresenceHome.kt @@ -1,9 +1,10 @@ package io.rudolph.netatmo.api.presence.model +import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonProperty import io.rudolph.netatmo.api.aircare.model.Place - +@JsonIgnoreProperties(ignoreUnknown = true) data class PresenceHome( @JsonProperty("cameras") val cameras: List? = null, @@ -11,6 +12,12 @@ data class PresenceHome( @JsonProperty("persons") val persons: List? = null, + /** + * comming soon + @JsonProperty("smokedetectors") + val detector: Unit, + */ + @JsonProperty("name") val name: String? = null, diff --git a/src/main/java/io/rudolph/netatmo/api/presence/model/User.kt b/src/main/java/io/rudolph/netatmo/api/presence/model/User.kt index 0097c8c..5c7cc25 100644 --- a/src/main/java/io/rudolph/netatmo/api/presence/model/User.kt +++ b/src/main/java/io/rudolph/netatmo/api/presence/model/User.kt @@ -11,5 +11,8 @@ data class User( val lang: String? = null, @JsonProperty("country") - val country: String? = null + val country: String? = null, + + @JsonProperty("mail") + val mail: String ) \ No newline at end of file diff --git a/src/main/java/io/rudolph/netatmo/oauth2/networkinterceptor/AuthInterceptor.kt b/src/main/java/io/rudolph/netatmo/oauth2/networkinterceptor/AuthInterceptor.kt index 7f072d3..95fb847 100644 --- a/src/main/java/io/rudolph/netatmo/oauth2/networkinterceptor/AuthInterceptor.kt +++ b/src/main/java/io/rudolph/netatmo/oauth2/networkinterceptor/AuthInterceptor.kt @@ -96,14 +96,21 @@ internal class AuthInterceptor(private val userMail: String?, } private fun proceedAuthRequest(chain: Interceptor.Chain, request: Request): String? { - return chain.proceed(request)?.body()?.string()?.let { - JacksonTransform.deserialize(it) + return chain.proceed(request)?.let { + if (!it.isSuccessful) { + return@let null + } + it.body() + ?.string() ?.let { - if (!(it.scope.sortedBy { it.value }.toTypedArray() contentEquals tokenStore.scope.sortedBy { it.value }.toTypedArray())) { - logger.warn("Scope from response does not match requested scope") - } - tokenStore.setTokens(it.accessToken, it.refreshToken, it.scope) - it.accessToken + JacksonTransform.deserialize(it) + ?.let { + if (!(it.scope.sortedBy { it.value }.toTypedArray() contentEquals tokenStore.scope.sortedBy { it.value }.toTypedArray())) { + logger.warn("Scope from response does not match requested scope") + } + tokenStore.setTokens(it.accessToken, it.refreshToken, it.scope) + it.accessToken + } } } } diff --git a/src/test/kotlin/apitest/PresenceTest.kt b/src/test/kotlin/apitest/PresenceTest.kt new file mode 100644 index 0000000..34a148a --- /dev/null +++ b/src/test/kotlin/apitest/PresenceTest.kt @@ -0,0 +1,16 @@ +package apitest + +import io.rudolph.netatmo.oauth2.model.Scope +import org.junit.Test + +class PresenceTest : BaseTest(listOf(Scope.READ_CAMERA, Scope.ACCESS_CAMERA, Scope.READ_PRESENCE, Scope.ACCESS_PRESENCE)) { + + val connector = api.presenceApi + + @Test + fun getPublicData() { + connector.getHomeData().executeSync().apply { + assert(this != null) + } + } +} \ No newline at end of file