Compare commits

...

1 Commits

Author SHA1 Message Date
Damien NORTIER 81fc8a62b5 refactor : réécriture du contrôleur des chapters
continuous-integration/drone/push Build is passing Details
1 year ago

@ -11,14 +11,15 @@ import java.io.IOException
class ControllerChapter {
companion object {
// Client HTTP API
val client = OkHttpClient()
fun getChapters(): ArrayList<Chapter>? {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access
val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/all/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO/1")
@ -45,9 +46,6 @@ class ControllerChapter {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access
val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/chapters/$idchapter/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
@ -62,8 +60,7 @@ class ControllerChapter {
val typeTokenProduct = object : TypeToken<ArrayList<Chapter>>() {}.type
// Parse API response and return the list of chapters
val chapter: ArrayList<Chapter> = gson.fromJson(response.body!!.string(), typeTokenProduct)
return chapter[0].name
return (gson.fromJson(response.body!!.string(), typeTokenProduct) as ArrayList<Chapter>)[0].name
}
return null

Loading…
Cancel
Save