From 3d3869585e76a6f2a92c389e12f46cc55200e2e2 Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Tue, 9 Aug 2022 10:00:29 +0200 Subject: [PATCH] Update BibLib API version to 0.7.0 --- .../biblib/network/client/BibLibClient.kt | 2 +- .../biblib/network/client/IBibLibClient.kt | 10 +- .../network/client/IBibLibWebServiceAPI.kt | 36 +++--- .../data/response/BookDetailResponse.kt | 119 +++++++++--------- .../network/data/response/BookListResponse.kt | 2 +- .../data/response/GenreListResponse.kt | 2 +- .../data/response/SeriesListResponse.kt | 2 +- .../network/data/response/UserResponse.kt | 2 +- .../biblib/network/factory/BookFactory.kt | 42 ++++--- 9 files changed, 112 insertions(+), 105 deletions(-) diff --git a/app/src/main/java/com/pixelized/biblib/network/client/BibLibClient.kt b/app/src/main/java/com/pixelized/biblib/network/client/BibLibClient.kt index e0bcaa8..83797d8 100644 --- a/app/src/main/java/com/pixelized/biblib/network/client/BibLibClient.kt +++ b/app/src/main/java/com/pixelized/biblib/network/client/BibLibClient.kt @@ -14,7 +14,7 @@ class BibLibClient @Inject constructor( ) : IBibLibClient { private val bearerInterceptor = BearerInterceptor() private val httpInterceptor = HttpLoggingInterceptor().apply { - this.level = HttpLoggingInterceptor.Level.BODY + this.level = HttpLoggingInterceptor.Level.HEADERS } private val retrofit: Retrofit = Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create(gson)) diff --git a/app/src/main/java/com/pixelized/biblib/network/client/IBibLibClient.kt b/app/src/main/java/com/pixelized/biblib/network/client/IBibLibClient.kt index 93a2536..63cb156 100644 --- a/app/src/main/java/com/pixelized/biblib/network/client/IBibLibClient.kt +++ b/app/src/main/java/com/pixelized/biblib/network/client/IBibLibClient.kt @@ -7,10 +7,10 @@ interface IBibLibClient { var 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" - const val EDIT_PROFILE = "$BASE_URL/profile" + const val BASE_URL = "https://bib.bibulle.fr/api/" + const val THUMBNAIL_URL = "${BASE_URL}book/thumbnail" + const val COVER_URL = "${BASE_URL}book/cover" + const val REGISTER_URL = "${BASE_URL}signup" + const val EDIT_PROFILE = "${BASE_URL}profile" } } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/network/client/IBibLibWebServiceAPI.kt b/app/src/main/java/com/pixelized/biblib/network/client/IBibLibWebServiceAPI.kt index 6af7104..cb0a5f9 100644 --- a/app/src/main/java/com/pixelized/biblib/network/client/IBibLibWebServiceAPI.kt +++ b/app/src/main/java/com/pixelized/biblib/network/client/IBibLibWebServiceAPI.kt @@ -6,42 +6,42 @@ import com.pixelized.biblib.network.data.response.* import retrofit2.http.* interface IBibLibWebServiceAPI { - @POST("/authent/login") + @POST("authent/login") 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 - @GET("/authent/user") + @GET("authent/user") suspend fun user(): UserResponse - @GET("/api/book/new") - suspend fun new(): BookListResponse - - @GET("/api/book") + @GET("book") suspend fun list(): BookListResponse - @GET("/api/series") - suspend fun series(): SeriesListResponse + @GET("book/new") + suspend fun new(): BookListResponse - @GET("/api/tag") - suspend fun genre(): GenreListResponse - - @GET("/api/book/{id}") + @GET("book/{id}") 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 -// @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 // -// @GET("/api/book/{id}/mobi/url") +// @GET("/book/{id}/mobi/url") // 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 // -// @GET("/api/book/{id}/mobi") +// @GET("/book/{id}/mobi") // fun downloadMobi(@Path("id") bookId: Int, @Query("token") token: String): Call } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/network/data/response/BookDetailResponse.kt b/app/src/main/java/com/pixelized/biblib/network/data/response/BookDetailResponse.kt index 28b9ec2..6bfd1b8 100644 --- a/app/src/main/java/com/pixelized/biblib/network/data/response/BookDetailResponse.kt +++ b/app/src/main/java/com/pixelized/biblib/network/data/response/BookDetailResponse.kt @@ -3,61 +3,66 @@ package com.pixelized.biblib.network.data.response import com.google.gson.annotations.SerializedName data class BookDetailResponse( - @SerializedName("book_id") - val book_id: Int? = null, - @SerializedName("book_title") - val book_title: String? = null, - @SerializedName("book_sort") - val book_sort: String? = null, - @SerializedName("book_has_cover") - val book_has_cover: Int? = null, - @SerializedName("book_date") - val book_date: String? = null, - @SerializedName("book_series_index") - val book_series_index: Float? = null, - @SerializedName("timestamp") - val timestamp: String? = null, - @SerializedName("last_modified") - val last_modified: String? = null, - @SerializedName("author_id") - val author_id: List? = null, - @SerializedName("author_name") - val author_name: List? = null, - @SerializedName("author_sort") - val author_sort: List? = null, - @SerializedName("lang_id") - val lang_id: String? = null, - @SerializedName("lang_code") - val lang_code: String? = null, - @SerializedName("tag_id") - val tag_id: List? = null, - @SerializedName("tag_name") - val tag_name: List? = null, - @SerializedName("rating") - val rating: String? = null, - @SerializedName("series_id") - val series_id: String? = null, - @SerializedName("series_name") - val series_name: String? = null, - @SerializedName("series_sort") - val series_sort: String? = null, - @SerializedName("comment") - val comment: String? = null, - @SerializedName("data") - val data: List? = null, + @SerializedName("book") + val book: Book?, ) : ErrorResponse() { - data class Data( - // "data_id": "9344", - @SerializedName("data_id") - val data_id: String? = null, - // "data_format": "MOBI", - @SerializedName("data_format") - val data_format: String? = null, - // "data_size": "699027", - @SerializedName("data_size") - val data_size: String? = null, - // "data_name": "Fondation - Isaac Asimov" - @SerializedName("data_name") - val data_name: String? = null, - ) -} + data class Book( + @SerializedName("book_id") + val book_id: Int? = null, + @SerializedName("book_title") + val book_title: String? = null, + @SerializedName("book_sort") + val book_sort: String? = null, + @SerializedName("book_has_cover") + val book_has_cover: Int? = null, + @SerializedName("book_date") + val book_date: String? = null, + @SerializedName("book_series_index") + val book_series_index: Float? = null, + @SerializedName("timestamp") + val timestamp: String? = null, + @SerializedName("last_modified") + val last_modified: String? = null, + @SerializedName("author_id") + val author_id: List? = null, + @SerializedName("author_name") + val author_name: List? = null, + @SerializedName("author_sort") + val author_sort: List? = null, + @SerializedName("lang_id") + val lang_id: String? = null, + @SerializedName("lang_code") + val lang_code: String? = null, + @SerializedName("tag_id") + val tag_id: List? = null, + @SerializedName("tag_name") + val tag_name: List? = null, + @SerializedName("rating") + val rating: String? = null, + @SerializedName("series_id") + val series_id: String? = null, + @SerializedName("series_name") + val series_name: String? = null, + @SerializedName("series_sort") + val series_sort: String? = null, + @SerializedName("comment") + val comment: String? = null, + @SerializedName("data") + val data: List? = null, + ) { + data class Data( + // "data_id": "9344", + @SerializedName("data_id") + val data_id: String? = null, + // "data_format": "MOBI", + @SerializedName("data_format") + val data_format: String? = null, + // "data_size": "699027", + @SerializedName("data_size") + val data_size: String? = null, + // "data_name": "Fondation - Isaac Asimov" + @SerializedName("data_name") + val data_name: String? = null, + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/network/data/response/BookListResponse.kt b/app/src/main/java/com/pixelized/biblib/network/data/response/BookListResponse.kt index 4d99078..b303a93 100644 --- a/app/src/main/java/com/pixelized/biblib/network/data/response/BookListResponse.kt +++ b/app/src/main/java/com/pixelized/biblib/network/data/response/BookListResponse.kt @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName data class BookListResponse( @SerializedName("lastUpdated") val lastUpdated: String? = null, // "2020-12-16T23:50:34.258Z" - @SerializedName("data") + @SerializedName("books") val data: List? = null, ) : ErrorResponse() { data class Book( diff --git a/app/src/main/java/com/pixelized/biblib/network/data/response/GenreListResponse.kt b/app/src/main/java/com/pixelized/biblib/network/data/response/GenreListResponse.kt index 0550902..5cd394a 100644 --- a/app/src/main/java/com/pixelized/biblib/network/data/response/GenreListResponse.kt +++ b/app/src/main/java/com/pixelized/biblib/network/data/response/GenreListResponse.kt @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName data class GenreListResponse( @SerializedName("lastUpdated") val lastUpdated: String?, - @SerializedName("data") + @SerializedName("tags") val genres: List?, ) : ErrorResponse() { diff --git a/app/src/main/java/com/pixelized/biblib/network/data/response/SeriesListResponse.kt b/app/src/main/java/com/pixelized/biblib/network/data/response/SeriesListResponse.kt index 6d71b42..5bf65e4 100644 --- a/app/src/main/java/com/pixelized/biblib/network/data/response/SeriesListResponse.kt +++ b/app/src/main/java/com/pixelized/biblib/network/data/response/SeriesListResponse.kt @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName data class SeriesListResponse( @SerializedName("lastUpdated") val lastUpdated: String?, - @SerializedName("data") + @SerializedName("series") val series: List?, ) : ErrorResponse() { diff --git a/app/src/main/java/com/pixelized/biblib/network/data/response/UserResponse.kt b/app/src/main/java/com/pixelized/biblib/network/data/response/UserResponse.kt index a78c5e7..186ba55 100644 --- a/app/src/main/java/com/pixelized/biblib/network/data/response/UserResponse.kt +++ b/app/src/main/java/com/pixelized/biblib/network/data/response/UserResponse.kt @@ -3,7 +3,7 @@ package com.pixelized.biblib.network.data.response import com.google.gson.annotations.SerializedName data class UserResponse( - @SerializedName("data") + @SerializedName("user") val data: Data? = null, ) : ErrorResponse() { data class Data( diff --git a/app/src/main/java/com/pixelized/biblib/network/factory/BookFactory.kt b/app/src/main/java/com/pixelized/biblib/network/factory/BookFactory.kt index 58e2a73..6b02167 100644 --- a/app/src/main/java/com/pixelized/biblib/network/factory/BookFactory.kt +++ b/app/src/main/java/com/pixelized/biblib/network/factory/BookFactory.kt @@ -88,12 +88,14 @@ class BookFactory { fun fromDetailResponseToBook(response: BookDetailResponse, isNew: Boolean = false): Book { fun error(name: String) = missingField("#fromDetailResponseToBook()", name, response) - val id: Int? = response.book_id - val title: String? = response.book_title - val sort: String? = response.book_sort - val authorId: List? = response.author_id?.mapNotNull { it.toIntOrNull() } - val authorName: List? = response.author_name - val authorSort: List? = response.author_sort + val book = response.book ?: throw error("book") + + val id: Int? = book.book_id + val title: String? = book.book_title + val sort: String? = book.book_sort + val authorId: List? = book.author_id?.mapNotNull { it.toIntOrNull() } + val authorName: List? = book.author_name + val authorSort: List? = book.author_sort val authorIdSize = authorId?.size val authorNameSize = authorName?.size val authorSortSize = authorSort?.size @@ -109,35 +111,35 @@ class BookFactory { } else { null } - val cover: Boolean? = response.book_has_cover?.toBoolean() - val releaseDate = response.book_date?.let { parser.parse(it) } - val languageId = response.lang_id?.toIntOrNull() - val languageCode = response.lang_code + val cover: Boolean? = book.book_has_cover?.toBoolean() + val releaseDate = book.book_date?.let { parser.parse(it) } + val languageId = book.lang_id?.toIntOrNull() + val languageCode = book.lang_code val language = if (languageId != null && languageCode != null) { Language(languageId, languageCode) } else { null } - val rating = response.rating?.toIntOrNull() - val seriesId = response.series_id?.toIntOrNull() - val seriesName = response.series_name - val seriesSort = response.series_sort - val seriesIndex: Int? = response.book_series_index?.toInt() + val rating = book.rating?.toIntOrNull() + val seriesId = book.series_id?.toIntOrNull() + val seriesName = book.series_name + val seriesSort = book.series_sort + val seriesIndex: Int? = book.book_series_index?.toInt() val series: Series? = if (seriesId != null && seriesName != null && seriesSort != null) { Series(id = seriesId, name = seriesName, sort = seriesSort, seriesIndex) } else { null } - val tagId: List? = response.tag_id?.mapNotNull { it.toIntOrNull() } - val tagName: List? = response.tag_name - val tagIdSize: Int? = response.tag_id?.size - val tagNameSize: Int? = response.tag_name?.size + val tagId: List? = book.tag_id?.mapNotNull { it.toIntOrNull() } + val tagName: List? = book.tag_name + val tagIdSize: Int? = book.tag_id?.size + val tagNameSize: Int? = book.tag_name?.size val tag: List? = if (tagId != null && tagName != null && tagIdSize == tagNameSize) { tagId.indices.map { Genre(tagId[it], tagName[it]) } } else { null } - val synopsis: String? = response.comment + val synopsis: String? = book.comment return Book( id = id ?: throw error("id"),