Skip to content

Commit

Permalink
[MOD/#6] local.properties baseUrl 값 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Nov 16, 2022
1 parent 6d429b2 commit 69df91b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
namespace 'org.sopt.sample'
compileSdk 33
Expand All @@ -16,6 +19,9 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "String", "BASE_URL", properties['base_url']
buildConfigField "String", "REQRES_URL", properties['reqres_url']
}

buildTypes {
Expand Down Expand Up @@ -56,7 +62,7 @@ dependencies {
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
16 changes: 9 additions & 7 deletions app/src/main/java/org/sopt/sample/data/remote/ApiFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@ import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.sopt.sample.BuildConfig.BASE_URL
import org.sopt.sample.BuildConfig.REQRES_URL
import org.sopt.sample.api.AuthService
import org.sopt.sample.api.FollowerService
import retrofit2.Retrofit

object ApiFactory {
val retrofit by lazy {
Retrofit.Builder()
.baseUrl("http://3.39.169.52:3000/")
.baseUrl(BASE_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) // JSON -> Kotlin
.build()
}

var mHttpLoggingInterceptor = HttpLoggingInterceptor()
var httpLoggingInterceptor = HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BODY)

var mOkHttpClient = OkHttpClient
var okHttpClient = OkHttpClient
.Builder()
.addInterceptor(mHttpLoggingInterceptor)
.addInterceptor(httpLoggingInterceptor)
.build()

val retrofitReqres by lazy {
Retrofit.Builder()
.baseUrl("https://reqres.in/")
.baseUrl(REQRES_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) // JSON -> Kotlin
.client(mOkHttpClient)
.client(okHttpClient)
.build()
}

Expand All @@ -40,4 +42,4 @@ object ApiFactory {
object ServicePool {
val authService = ApiFactory.create<AuthService>()
val followerService = ApiFactory.createReqres<FollowerService>()
}
}

0 comments on commit 69df91b

Please sign in to comment.