-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/example/openapigenerationtest/QiitaItemService.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,39 @@ | ||
package com.example.openapigenerationtest | ||
|
||
import com.example.openapigenerationtestapi.infrastructure.ApiClient | ||
import com.example.openapigenerationtestapi.sp.api.ItemApi | ||
import com.example.openapigenerationtestapi.sp.model.Item | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Callback | ||
|
||
class QiitaItemService { | ||
|
||
private val itemApi: ItemApi | ||
|
||
init { | ||
val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
setLevel(HttpLoggingInterceptor.Level.BODY) | ||
} | ||
val httpClient: OkHttpClient = OkHttpClient.Builder().apply { | ||
addInterceptor(loggingInterceptor) | ||
addInterceptor(Interceptor { chain -> | ||
chain.proceed( | ||
chain.request() | ||
.newBuilder() | ||
.header("Content-Type", "application/json") | ||
.header("Authorization", "Bearer 46f9e2655f4f0afb5ee0d721acb03693171aed26") | ||
.build() | ||
) | ||
}) | ||
}.build() | ||
|
||
itemApi = ApiClient(okHttpClient = httpClient).createService(ItemApi::class.java) | ||
} | ||
|
||
fun getAllItems(page: Int, perPage: Int, query: String, callback: Callback<Array<Item>>) { | ||
val call = itemApi.getAllItems(page.toString(), perPage.toString(), query) | ||
call.enqueue(callback) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/example/openapigenerationtest/QiitaUserService.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,44 @@ | ||
package com.example.openapigenerationtest | ||
|
||
import com.example.openapigenerationtestapi.infrastructure.ApiClient | ||
import com.example.openapigenerationtestapi.sp.api.UserApi | ||
import com.example.openapigenerationtestapi.sp.model.User | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Callback | ||
|
||
class QiitaUserService { | ||
|
||
private val userApi: UserApi | ||
|
||
init { | ||
val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
setLevel(HttpLoggingInterceptor.Level.BODY) | ||
} | ||
val httpClient: OkHttpClient = OkHttpClient.Builder().apply { | ||
addInterceptor(loggingInterceptor) | ||
addInterceptor(Interceptor { chain -> | ||
chain.proceed( | ||
chain.request() | ||
.newBuilder() | ||
.header("Content-Type", "application/json") | ||
.header("Authorization", "Bearer 46f9e2655f4f0afb5ee0d721acb03693171aed26") | ||
.build() | ||
) | ||
}) | ||
}.build() | ||
|
||
userApi = ApiClient(okHttpClient = httpClient).createService(UserApi::class.java) | ||
} | ||
|
||
fun getAllUser(page: Int, perPage: Int, callback: Callback<Array<User>>) { | ||
val call = userApi.getAllUser(page.toString(), perPage.toString()) | ||
call.enqueue(callback) | ||
} | ||
|
||
fun getUser(userId: String, callback: Callback<User>) { | ||
val call = userApi.getUser(userId) | ||
call.enqueue(callback) | ||
} | ||
} |