Skip to content

Commit

Permalink
bugfixes and tests
Browse files Browse the repository at this point in the history
- failing scope permissions fix in interceptor
- fixes models fpr presences
- adds new test for presence
  • Loading branch information
navybk committed Aug 13, 2018
1 parent 901bec6 commit 8e23e02
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

group 'io.rudolph.netatmo'
version '0.3.1'
version '0.3.2'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
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<Camera>? = null,

@JsonProperty("persons")
val persons: List<Person>? = null,

/**
* comming soon
@JsonProperty("smokedetectors")
val detector: Unit,
*/

@JsonProperty("name")
val name: String? = null,

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/rudolph/netatmo/api/presence/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthResponse>(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<AuthResponse>(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
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/kotlin/apitest/PresenceTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 8e23e02

Please sign in to comment.