add getUserInfo function

This commit is contained in:
dalbodeule
2024-08-09 13:11:09 +09:00
parent 80dbf10e7e
commit 94b87dc87e
2 changed files with 24 additions and 4 deletions

View File

@@ -146,3 +146,22 @@ fun getStreamInfo(userId: String) : IData<IStreamInfo?> {
}
}
}
fun getUserInfo(userId: String): IData<Channel?> {
val url = "https://api.chzzk.naver.com/service/v1/channels/${userId}"
val request = Request.Builder()
.url(url)
.build()
client.newCall(request).execute().use { response ->
try {
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
val body = response.body?.string()
val channel = gson.fromJson(body, object: TypeToken<IData<Channel?>>() {})
return channel
} catch(e: Exception) {
throw e
}
}
}