-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Applied previous commits from develop
- Token feature + Record Activity, cannot cast Activity[] - ListOf instead of ArrayOf + post<String>
- Loading branch information
Joaquim Puyo
authored and
Joaquim Puyo
committed
Jun 23, 2020
1 parent
16bdfa1
commit 9c9a394
Showing
12 changed files
with
141 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...dk/src/main/java/com/wordline/helios/rewarding/sdk/data/datasource/remote/TokenFeature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.wordline.helios.rewarding.sdk.data.datasource.remote | ||
|
||
import com.wordline.helios.rewarding.sdk.data.datasource.local.LocalDataSource | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.features.HttpClientFeature | ||
import io.ktor.client.request.HttpRequestPipeline | ||
import io.ktor.client.request.header | ||
import io.ktor.util.AttributeKey | ||
|
||
class TokenFeature private constructor( | ||
private val tokenHeaderName: String, | ||
private val tokenProvider: LocalDataSource | ||
) { | ||
|
||
class Config { | ||
var tokenHeaderName: String? = null | ||
var tokenProvider: LocalDataSource? = null | ||
fun build() = TokenFeature( | ||
tokenHeaderName ?: throw IllegalArgumentException("HeaderName should be contain"), | ||
tokenProvider ?: throw IllegalArgumentException("TokenProvider should be contain") | ||
) | ||
} | ||
|
||
companion object Feature : HttpClientFeature<Config, TokenFeature> { | ||
override val key = AttributeKey<TokenFeature>("TokenFeature") | ||
|
||
override fun prepare(block: Config.() -> Unit) = Config().apply(block).build() | ||
|
||
override fun install(feature: TokenFeature, scope: HttpClient) { | ||
scope.requestPipeline.intercept(HttpRequestPipeline.State) { | ||
feature.tokenProvider.getToken().apply { | ||
this.fold( | ||
error = {}, | ||
success = { context.header(feature.tokenHeaderName, "Bearer $it") } | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...os-rewarding-sdk/src/main/java/com/wordline/helios/rewarding/sdk/domain/model/Activity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.wordline.helios.rewarding.sdk.domain.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Activity( | ||
val action: String, | ||
val date: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters