tmp
This commit is contained in:
parent
7898a51252
commit
8fbe3c0b7b
21 changed files with 359 additions and 35 deletions
|
|
@ -0,0 +1,23 @@
|
|||
package com.pixelized.biblib.network.client
|
||||
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
class BearerInterceptor : Interceptor {
|
||||
private val bearer get() = "$BEARER $token"
|
||||
var token: String? = null
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
var request = chain.request()
|
||||
if (request.header(NO_AUTHORIZATION) == null && token.isNullOrEmpty().not()) {
|
||||
request = request.newBuilder().addHeader(AUTHORIZATION, bearer).build()
|
||||
}
|
||||
return chain.proceed(request)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val NO_AUTHORIZATION = "No-Authentication"
|
||||
private const val AUTHORIZATION = "Authorization"
|
||||
private const val BEARER = "Bearer"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.pixelized.biblib.network.client
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.pixelized.biblib.injection.inject
|
||||
import com.pixelized.biblib.network.client.IBibLibClient.Companion.BASE_URL
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
class BibLibClient : IBibLibClient {
|
||||
private val gson by inject<Gson>()
|
||||
private val interceptor = BearerInterceptor()
|
||||
private val retrofit: Retrofit = Retrofit.Builder()
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.client(OkHttpClient.Builder().addInterceptor(interceptor).build())
|
||||
.baseUrl(BASE_URL)
|
||||
.build()
|
||||
|
||||
override val service: IBibLibWebServiceAPI = retrofit.create(IBibLibWebServiceAPI::class.java)
|
||||
|
||||
// endregion
|
||||
///////////////////////////////////
|
||||
// region BibLib webservice Auth
|
||||
|
||||
override fun updateBearerToken(token: String?) {
|
||||
interceptor.token = token
|
||||
}
|
||||
|
||||
// endregion
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.pixelized.biblib.network.client
|
||||
|
||||
interface IBibLibClient {
|
||||
|
||||
val service: IBibLibWebServiceAPI
|
||||
|
||||
fun updateBearerToken(token: String?)
|
||||
|
||||
companion object {
|
||||
const val BASE_URL = "https://bib.bibulle.fr"
|
||||
const val THUMBNAIL_URL = "$BASE_URL/api/book/thumbnail"
|
||||
const val COVER_URL = "$BASE_URL/api/book/cover"
|
||||
const val REGISTER_URL = "$BASE_URL/signup"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.pixelized.biblib.network.client
|
||||
|
||||
import com.pixelized.biblib.data.network.query.AuthLoginQuery
|
||||
import com.pixelized.biblib.data.network.response.AuthLoginResponse
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface IBibLibWebServiceAPI {
|
||||
@POST("/authent/login")
|
||||
suspend fun login(@Body query: AuthLoginQuery): AuthLoginResponse
|
||||
|
||||
@GET("/authent/google-id-token")
|
||||
suspend fun loginWithGoogle(@Query("id_token") token: String): AuthLoginResponse
|
||||
|
||||
// @GET("/authent/user")
|
||||
// suspend fun user(): UserResponse
|
||||
//
|
||||
// @GET("/api/book/new")
|
||||
// suspend fun new(): BookListResponse
|
||||
//
|
||||
// @GET("/api/book")
|
||||
// suspend fun list(): BookListResponse
|
||||
//
|
||||
// @GET("/api/book/{id}")
|
||||
// suspend fun detail(@Path("id") bookId: Int): BookDetailResponse
|
||||
//
|
||||
// @GET("/api/book/{id}/send/kindle")
|
||||
// suspend fun send(@Path("id") bookId: Int, @Query("mail") mail: String): LinkedTreeMap<String, Any>
|
||||
//
|
||||
// @GET("/api/book/{id}/epub/url")
|
||||
// suspend fun epub(@Path("id") bookId: Int): TokenResponse
|
||||
//
|
||||
// @GET("/api/book/{id}/mobi/url")
|
||||
// suspend fun mobi(@Path("id") bookId: Int): TokenResponse
|
||||
//
|
||||
// @GET("/api/book/{id}/epub")
|
||||
// fun downloadEpub(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody>
|
||||
//
|
||||
// @GET("/api/book/{id}/mobi")
|
||||
// fun downloadMobi(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue