Update BibLib API version to 0.7.0

This commit is contained in:
Thomas Andres Gomez 2022-08-09 10:00:29 +02:00
parent baa3055c0d
commit 3d3869585e
9 changed files with 112 additions and 105 deletions

View file

@ -14,7 +14,7 @@ class BibLibClient @Inject constructor(
) : IBibLibClient { ) : IBibLibClient {
private val bearerInterceptor = BearerInterceptor() private val bearerInterceptor = BearerInterceptor()
private val httpInterceptor = HttpLoggingInterceptor().apply { private val httpInterceptor = HttpLoggingInterceptor().apply {
this.level = HttpLoggingInterceptor.Level.BODY this.level = HttpLoggingInterceptor.Level.HEADERS
} }
private val retrofit: Retrofit = Retrofit.Builder() private val retrofit: Retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson)) .addConverterFactory(GsonConverterFactory.create(gson))

View file

@ -7,10 +7,10 @@ interface IBibLibClient {
var token: String? var token: String?
companion object { companion object {
const val BASE_URL = "https://bib.bibulle.fr" const val BASE_URL = "https://bib.bibulle.fr/api/"
const val THUMBNAIL_URL = "$BASE_URL/api/book/thumbnail" const val THUMBNAIL_URL = "${BASE_URL}book/thumbnail"
const val COVER_URL = "$BASE_URL/api/book/cover" const val COVER_URL = "${BASE_URL}book/cover"
const val REGISTER_URL = "$BASE_URL/signup" const val REGISTER_URL = "${BASE_URL}signup"
const val EDIT_PROFILE = "$BASE_URL/profile" const val EDIT_PROFILE = "${BASE_URL}profile"
} }
} }

View file

@ -6,42 +6,42 @@ import com.pixelized.biblib.network.data.response.*
import retrofit2.http.* import retrofit2.http.*
interface IBibLibWebServiceAPI { interface IBibLibWebServiceAPI {
@POST("/authent/login") @POST("authent/login")
suspend fun login(@Body query: AuthLoginQuery): AuthLoginResponse suspend fun login(@Body query: AuthLoginQuery): AuthLoginResponse
@GET("/authent/google-id-token") @GET("authent/google-id-token")
suspend fun loginWithGoogle(@Query("id_token") token: String): AuthLoginResponse suspend fun loginWithGoogle(@Query("id_token") token: String): AuthLoginResponse
@GET("/authent/user") @GET("authent/user")
suspend fun user(): UserResponse suspend fun user(): UserResponse
@GET("/api/book/new") @GET("book")
suspend fun new(): BookListResponse
@GET("/api/book")
suspend fun list(): BookListResponse suspend fun list(): BookListResponse
@GET("/api/series") @GET("book/new")
suspend fun series(): SeriesListResponse suspend fun new(): BookListResponse
@GET("/api/tag") @GET("book/{id}")
suspend fun genre(): GenreListResponse
@GET("/api/book/{id}")
suspend fun detail(@Path("id") bookId: Int): BookDetailResponse suspend fun detail(@Path("id") bookId: Int): BookDetailResponse
@GET("/api/book/{id}/send/kindle") @GET("book/{id}/send/kindle")
suspend fun send(@Path("id") bookId: Int, @Query("mail") mail: String): LinkedTreeMap<String, Any> suspend fun send(@Path("id") bookId: Int, @Query("mail") mail: String): LinkedTreeMap<String, Any>
// @GET("/api/book/{id}/epub/url") @GET("series")
suspend fun series(): SeriesListResponse
@GET("tags")
suspend fun genre(): GenreListResponse
// @GET("/book/{id}/epub/url")
// suspend fun epub(@Path("id") bookId: Int): TokenResponse // suspend fun epub(@Path("id") bookId: Int): TokenResponse
// //
// @GET("/api/book/{id}/mobi/url") // @GET("/book/{id}/mobi/url")
// suspend fun mobi(@Path("id") bookId: Int): TokenResponse // suspend fun mobi(@Path("id") bookId: Int): TokenResponse
// //
// @GET("/api/book/{id}/epub") // @GET("/book/{id}/epub")
// fun downloadEpub(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody> // fun downloadEpub(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody>
// //
// @GET("/api/book/{id}/mobi") // @GET("/book/{id}/mobi")
// fun downloadMobi(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody> // fun downloadMobi(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody>
} }

View file

@ -3,6 +3,10 @@ package com.pixelized.biblib.network.data.response
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
data class BookDetailResponse( data class BookDetailResponse(
@SerializedName("book")
val book: Book?,
) : ErrorResponse() {
data class Book(
@SerializedName("book_id") @SerializedName("book_id")
val book_id: Int? = null, val book_id: Int? = null,
@SerializedName("book_title") @SerializedName("book_title")
@ -45,7 +49,7 @@ data class BookDetailResponse(
val comment: String? = null, val comment: String? = null,
@SerializedName("data") @SerializedName("data")
val data: List<Data>? = null, val data: List<Data>? = null,
) : ErrorResponse() { ) {
data class Data( data class Data(
// "data_id": "9344", // "data_id": "9344",
@SerializedName("data_id") @SerializedName("data_id")
@ -60,4 +64,5 @@ data class BookDetailResponse(
@SerializedName("data_name") @SerializedName("data_name")
val data_name: String? = null, val data_name: String? = null,
) )
}
} }

View file

@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName
data class BookListResponse( data class BookListResponse(
@SerializedName("lastUpdated") @SerializedName("lastUpdated")
val lastUpdated: String? = null, // "2020-12-16T23:50:34.258Z" val lastUpdated: String? = null, // "2020-12-16T23:50:34.258Z"
@SerializedName("data") @SerializedName("books")
val data: List<Book>? = null, val data: List<Book>? = null,
) : ErrorResponse() { ) : ErrorResponse() {
data class Book( data class Book(

View file

@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName
data class GenreListResponse( data class GenreListResponse(
@SerializedName("lastUpdated") @SerializedName("lastUpdated")
val lastUpdated: String?, val lastUpdated: String?,
@SerializedName("data") @SerializedName("tags")
val genres: List<Genres>?, val genres: List<Genres>?,
) : ErrorResponse() { ) : ErrorResponse() {

View file

@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName
data class SeriesListResponse( data class SeriesListResponse(
@SerializedName("lastUpdated") @SerializedName("lastUpdated")
val lastUpdated: String?, val lastUpdated: String?,
@SerializedName("data") @SerializedName("series")
val series: List<Series>?, val series: List<Series>?,
) : ErrorResponse() { ) : ErrorResponse() {

View file

@ -3,7 +3,7 @@ package com.pixelized.biblib.network.data.response
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
data class UserResponse( data class UserResponse(
@SerializedName("data") @SerializedName("user")
val data: Data? = null, val data: Data? = null,
) : ErrorResponse() { ) : ErrorResponse() {
data class Data( data class Data(

View file

@ -88,12 +88,14 @@ class BookFactory {
fun fromDetailResponseToBook(response: BookDetailResponse, isNew: Boolean = false): Book { fun fromDetailResponseToBook(response: BookDetailResponse, isNew: Boolean = false): Book {
fun error(name: String) = missingField("#fromDetailResponseToBook()", name, response) fun error(name: String) = missingField("#fromDetailResponseToBook()", name, response)
val id: Int? = response.book_id val book = response.book ?: throw error("book")
val title: String? = response.book_title
val sort: String? = response.book_sort val id: Int? = book.book_id
val authorId: List<Int>? = response.author_id?.mapNotNull { it.toIntOrNull() } val title: String? = book.book_title
val authorName: List<String>? = response.author_name val sort: String? = book.book_sort
val authorSort: List<String>? = response.author_sort val authorId: List<Int>? = book.author_id?.mapNotNull { it.toIntOrNull() }
val authorName: List<String>? = book.author_name
val authorSort: List<String>? = book.author_sort
val authorIdSize = authorId?.size val authorIdSize = authorId?.size
val authorNameSize = authorName?.size val authorNameSize = authorName?.size
val authorSortSize = authorSort?.size val authorSortSize = authorSort?.size
@ -109,35 +111,35 @@ class BookFactory {
} else { } else {
null null
} }
val cover: Boolean? = response.book_has_cover?.toBoolean() val cover: Boolean? = book.book_has_cover?.toBoolean()
val releaseDate = response.book_date?.let { parser.parse(it) } val releaseDate = book.book_date?.let { parser.parse(it) }
val languageId = response.lang_id?.toIntOrNull() val languageId = book.lang_id?.toIntOrNull()
val languageCode = response.lang_code val languageCode = book.lang_code
val language = if (languageId != null && languageCode != null) { val language = if (languageId != null && languageCode != null) {
Language(languageId, languageCode) Language(languageId, languageCode)
} else { } else {
null null
} }
val rating = response.rating?.toIntOrNull() val rating = book.rating?.toIntOrNull()
val seriesId = response.series_id?.toIntOrNull() val seriesId = book.series_id?.toIntOrNull()
val seriesName = response.series_name val seriesName = book.series_name
val seriesSort = response.series_sort val seriesSort = book.series_sort
val seriesIndex: Int? = response.book_series_index?.toInt() val seriesIndex: Int? = book.book_series_index?.toInt()
val series: Series? = if (seriesId != null && seriesName != null && seriesSort != null) { val series: Series? = if (seriesId != null && seriesName != null && seriesSort != null) {
Series(id = seriesId, name = seriesName, sort = seriesSort, seriesIndex) Series(id = seriesId, name = seriesName, sort = seriesSort, seriesIndex)
} else { } else {
null null
} }
val tagId: List<Int>? = response.tag_id?.mapNotNull { it.toIntOrNull() } val tagId: List<Int>? = book.tag_id?.mapNotNull { it.toIntOrNull() }
val tagName: List<String>? = response.tag_name val tagName: List<String>? = book.tag_name
val tagIdSize: Int? = response.tag_id?.size val tagIdSize: Int? = book.tag_id?.size
val tagNameSize: Int? = response.tag_name?.size val tagNameSize: Int? = book.tag_name?.size
val tag: List<Genre>? = if (tagId != null && tagName != null && tagIdSize == tagNameSize) { val tag: List<Genre>? = if (tagId != null && tagName != null && tagIdSize == tagNameSize) {
tagId.indices.map { Genre(tagId[it], tagName[it]) } tagId.indices.map { Genre(tagId[it], tagName[it]) }
} else { } else {
null null
} }
val synopsis: String? = response.comment val synopsis: String? = book.comment
return Book( return Book(
id = id ?: throw error("id"), id = id ?: throw error("id"),