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 {
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))

View file

@ -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"
}
}

View file

@ -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<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
//
// @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<ResponseBody>
//
// @GET("/api/book/{id}/mobi")
// @GET("/book/{id}/mobi")
// fun downloadMobi(@Path("id") bookId: Int, @Query("token") token: String): Call<ResponseBody>
}

View file

@ -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<String>? = null,
@SerializedName("author_name")
val author_name: List<String>? = null,
@SerializedName("author_sort")
val author_sort: List<String>? = null,
@SerializedName("lang_id")
val lang_id: String? = null,
@SerializedName("lang_code")
val lang_code: String? = null,
@SerializedName("tag_id")
val tag_id: List<String>? = null,
@SerializedName("tag_name")
val tag_name: List<String>? = 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<Data>? = 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<String>? = null,
@SerializedName("author_name")
val author_name: List<String>? = null,
@SerializedName("author_sort")
val author_sort: List<String>? = null,
@SerializedName("lang_id")
val lang_id: String? = null,
@SerializedName("lang_code")
val lang_code: String? = null,
@SerializedName("tag_id")
val tag_id: List<String>? = null,
@SerializedName("tag_name")
val tag_name: List<String>? = 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<Data>? = 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,
)
}
}

View file

@ -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<Book>? = null,
) : ErrorResponse() {
data class Book(

View file

@ -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<Genres>?,
) : ErrorResponse() {

View file

@ -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<Series>?,
) : ErrorResponse() {

View file

@ -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(

View file

@ -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<Int>? = response.author_id?.mapNotNull { it.toIntOrNull() }
val authorName: List<String>? = response.author_name
val authorSort: List<String>? = 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<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 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<Int>? = response.tag_id?.mapNotNull { it.toIntOrNull() }
val tagName: List<String>? = response.tag_name
val tagIdSize: Int? = response.tag_id?.size
val tagNameSize: Int? = response.tag_name?.size
val tagId: List<Int>? = book.tag_id?.mapNotNull { it.toIntOrNull() }
val tagName: List<String>? = book.tag_name
val tagIdSize: Int? = book.tag_id?.size
val tagNameSize: Int? = book.tag_name?.size
val tag: List<Genre>? = 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"),