Skip to content

Commit

Permalink
refactor(common): modify access rights
Browse files Browse the repository at this point in the history
  • Loading branch information
gaebel committed Aug 24, 2020
1 parent c925f07 commit c3c7736
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 233 deletions.
13 changes: 1 addition & 12 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*

plugins {
Expand All @@ -12,9 +11,7 @@ plugins {
}

kotlin {
ios() {
binaries.framework()
}
ios()

android {
publishLibraryVariants("debug", "release")
Expand Down Expand Up @@ -54,14 +51,6 @@ kotlin {
}
}
}

targets.all {
compilations.all {
kotlinOptions.apply {
freeCompilerArgs = listOf("-Xallow-result-return-type")
}
}
}
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.liftric.base

actual class Environment {
actual internal class Environment {
actual companion object {
actual fun variable(value: String): String? {
return System.getenv(value)
Expand Down
2 changes: 1 addition & 1 deletion auth/src/commonMain/kotlin/com/liftric/base/Environment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.liftric.base

expect class Environment() {
expect internal class Environment() {
companion object {
/**
* Accesses environment variable
Expand Down
12 changes: 6 additions & 6 deletions auth/src/commonMain/kotlin/com/liftric/base/Payload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ package com.liftric.base
import kotlinx.serialization.Serializable

@Serializable
data class Authentication(
internal data class Authentication(
val AuthFlow: String,
val ClientId: String,
val AuthParameters: AuthParameters
)

@Serializable
data class AuthParameters(
internal data class AuthParameters(
val USERNAME: String,
val PASSWORD: String
)

@Serializable
data class AccessToken(
internal data class AccessToken(
val AccessToken: String
)

@Serializable
data class ChangePassword(
internal data class ChangePassword(
val AccessToken: String,
val PreviousPassword: String,
val ProposedPassword: String
)

@Serializable
data class SignUp(
internal data class SignUp(
val ClientId: String,
val Password: String,
val Username: String,
Expand All @@ -42,7 +42,7 @@ data class UserAttribute(
)

@Serializable
data class UpdateUserAttributes(
internal data class UpdateUserAttributes(
val AccessToken: String,
val UserAttributes: List<UserAttribute>
)
3 changes: 2 additions & 1 deletion auth/src/commonMain/kotlin/com/liftric/base/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class AuthenticationResult(
val RefreshToken: String = "",
val TokenType: String = ""
)

// Sign up

@Serializable
Expand Down Expand Up @@ -61,4 +62,4 @@ data class MFAOptions(
@Serializable
data class UpdateUserAttributesResponse(
val CodeDeliveryDetailsList: List<CodeDeliveryDetails> = listOf()
)
)
29 changes: 29 additions & 0 deletions auth/src/commonMain/kotlin/com/liftric/base/Result.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.liftric.base

class Result<out T> constructor(val value: Any?) {
val isSuccess: Boolean get() = value !is Failure
val isFailure: Boolean get() = value is Failure

companion object {
fun <T> success(value: T): Result<T> = Result(value)
fun <T> failure(exception: Throwable): Result<T> = Result(Failure(exception))
}

class Failure(val exception: Throwable) {
override fun equals(other: Any?): Boolean = other is Failure && exception == other.exception
override fun hashCode(): Int = exception.hashCode()
override fun toString(): String = "Failure($exception)"
}

fun getOrNull(): T? =
when {
isFailure -> null
else -> value as T
}

fun exceptionOrNull(): Throwable? =
when (value) {
is Failure -> value.exception
else -> null
}
}
4 changes: 2 additions & 2 deletions auth/src/commonMain/kotlin/com/liftric/base/Serialization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.Json

fun <T> serialize(strategy: SerializationStrategy<T>, value: T): String {
internal fun <T> serialize(strategy: SerializationStrategy<T>, value: T): String {
return Json {
allowStructuredMapKeys = true
}.encodeToString(strategy, value)
}

fun <T> parse(strategy: DeserializationStrategy<T>, value: String): T {
internal fun <T> parse(strategy: DeserializationStrategy<T>, value: String): T {
return Json {
allowStructuredMapKeys = true
}.decodeFromString(strategy, value)
Expand Down
Loading

0 comments on commit c3c7736

Please sign in to comment.