Skip to content

Commit aa8f2c9

Browse files
Fix: Convert server config string into json string (#2103)
1 parent 443bfa1 commit aa8f2c9

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

core/common/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ secrets {
1818
}
1919

2020
dependencies {
21+
implementation(projects.core.model)
2122
testImplementation(libs.kotlinx.coroutines.test)
2223
testImplementation(libs.turbine)
2324

core/common/src/main/java/com/mifos/core/common/utils/BaseUrl.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import com.mifos.core.common.BuildConfig
44

55
object BaseUrl {
66

7-
private val configs = BuildConfig.DEMO_SERVER_CONFIG.split(",")
7+
private val configs = BuildConfig.DEMO_SERVER_CONFIG.asServerConfig()
88

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

11-
val PROTOCOL_HTTPS = configs[0]
11+
val PROTOCOL_HTTPS = configs.protocol
1212

13-
val API_ENDPOINT = configs[1]
13+
val API_ENDPOINT = configs.endPoint
1414

15-
val API_PATH = configs[2]
15+
val API_PATH = configs.apiPath
1616

17-
val PORT = configs[3]
17+
val PORT = configs.port
1818

19-
val TENANT = configs[4]
19+
val TENANT = configs.tenant
2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.mifos.core.common.utils
2+
3+
import com.google.gson.Gson
4+
import com.mifos.core.model.ServerConfig
5+
6+
fun String.asServerConfig(): ServerConfig {
7+
val jsonString = this.replace("'", "\"")
8+
return Gson().fromJson(jsonString, ServerConfig::class.java)
9+
}

core/model/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ plugins {
33
}
44

55
dependencies {
6-
6+
implementation(libs.converter.gson)
77
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mifos.core.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class ServerConfig(
6+
val protocol: String,
7+
@SerializedName("end_point")
8+
val endPoint: String,
9+
@SerializedName("api_path")
10+
val apiPath: String,
11+
val port: String,
12+
val tenant: String
13+
)

core/network/src/main/java/com/mifos/core/network/BaseUrl.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
*/
55
package com.mifos.core.network
66

7+
import com.mifos.core.common.BuildConfig
8+
import com.mifos.core.common.utils.asServerConfig
9+
710
/**
811
* @author fomenkoo
912
*/
1013
class BaseUrl {
1114

1215
// "/" in the last of the base url always
1316
companion object {
14-
private val configs = BuildConfig.DEMO_SERVER_CONFIG.split(",")
17+
private val configs = BuildConfig.DEMO_SERVER_CONFIG.asServerConfig()
1518

16-
val PROTOCOL_HTTPS = configs[0]
17-
val API_ENDPOINT = configs[1]
18-
val API_PATH = configs[2]
19-
val PORT = configs[3]
19+
val PROTOCOL_HTTPS = configs.protocol
20+
val API_ENDPOINT = configs.endPoint
21+
val API_PATH = configs.apiPath
22+
val PORT = configs.port
2023
}
2124
}

secrets.defaults.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Separated By Comma (,) Without Space like below
1111
# PROTOCOL_HTTPS,API_ENDPOINT,API_PATH,PORT,TENANT
1212

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

1515
# Provide GEO API Key
1616
GEO_API_KEY=AIzaSyAZTZqvDGyyw21z2Ee7N-dE_WuZQwKL0

0 commit comments

Comments
 (0)