Skip to content

Commit

Permalink
Fix: Convert server config string into json string (#2103)
Browse files Browse the repository at this point in the history
  • Loading branch information
therajanmaurya authored May 29, 2024
1 parent 443bfa1 commit aa8f2c9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ secrets {
}

dependencies {
implementation(projects.core.model)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.turbine)

Expand Down
12 changes: 6 additions & 6 deletions core/common/src/main/java/com/mifos/core/common/utils/BaseUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import com.mifos.core.common.BuildConfig

object BaseUrl {

private val configs = BuildConfig.DEMO_SERVER_CONFIG.split(",")
private val configs = BuildConfig.DEMO_SERVER_CONFIG.asServerConfig()

// "/" in the last of the base url always

val PROTOCOL_HTTPS = configs[0]
val PROTOCOL_HTTPS = configs.protocol

val API_ENDPOINT = configs[1]
val API_ENDPOINT = configs.endPoint

val API_PATH = configs[2]
val API_PATH = configs.apiPath

val PORT = configs[3]
val PORT = configs.port

val TENANT = configs[4]
val TENANT = configs.tenant
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mifos.core.common.utils

import com.google.gson.Gson
import com.mifos.core.model.ServerConfig

fun String.asServerConfig(): ServerConfig {
val jsonString = this.replace("'", "\"")
return Gson().fromJson(jsonString, ServerConfig::class.java)
}
2 changes: 1 addition & 1 deletion core/model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ plugins {
}

dependencies {

implementation(libs.converter.gson)
}
13 changes: 13 additions & 0 deletions core/model/src/main/kotlin/com/mifos/core/model/ServerConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mifos.core.model

import com.google.gson.annotations.SerializedName

data class ServerConfig(
val protocol: String,
@SerializedName("end_point")
val endPoint: String,
@SerializedName("api_path")
val apiPath: String,
val port: String,
val tenant: String
)
13 changes: 8 additions & 5 deletions core/network/src/main/java/com/mifos/core/network/BaseUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
*/
package com.mifos.core.network

import com.mifos.core.common.BuildConfig
import com.mifos.core.common.utils.asServerConfig

/**
* @author fomenkoo
*/
class BaseUrl {

// "/" in the last of the base url always
companion object {
private val configs = BuildConfig.DEMO_SERVER_CONFIG.split(",")
private val configs = BuildConfig.DEMO_SERVER_CONFIG.asServerConfig()

val PROTOCOL_HTTPS = configs[0]
val API_ENDPOINT = configs[1]
val API_PATH = configs[2]
val PORT = configs[3]
val PROTOCOL_HTTPS = configs.protocol
val API_ENDPOINT = configs.endPoint
val API_PATH = configs.apiPath
val PORT = configs.port
}
}
2 changes: 1 addition & 1 deletion secrets.defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Separated By Comma (,) Without Space like below
# PROTOCOL_HTTPS,API_ENDPOINT,API_PATH,PORT,TENANT

DEMO_SERVER_CONFIG="https://,dev.mifos.io,/fineract-provider/api/v1/,80,default"
DEMO_SERVER_CONFIG="{\'protocol\':\'https://\',\'end_point\':\'dev.mifos.io\',\'api_path\':\'/fineract-provider/api/v1/\',\'port\':\'80\',\'tenant\':\'default\'}"

# Provide GEO API Key
GEO_API_KEY=AIzaSyAZTZqvDGyyw21z2Ee7N-dE_WuZQwKL0

0 comments on commit aa8f2c9

Please sign in to comment.