mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 14:07:05 +05:30
feat(api/model): initial Shiori API
This commit is contained in:
parent
f55d89b17e
commit
f39bf0b043
9 changed files with 212 additions and 0 deletions
52
api/src/main/kotlin/dev/msfjarvis/claw/api/ShioriApi.kt
Normal file
52
api/src/main/kotlin/dev/msfjarvis/claw/api/ShioriApi.kt
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.api
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import dev.msfjarvis.claw.model.shiori.AuthRequest
|
||||
import dev.msfjarvis.claw.model.shiori.AuthResponse
|
||||
import dev.msfjarvis.claw.model.shiori.Bookmark
|
||||
import dev.msfjarvis.claw.model.shiori.BookmarkRequest
|
||||
import dev.msfjarvis.claw.model.shiori.BookmarksResponse
|
||||
import dev.msfjarvis.claw.model.shiori.EditedBookmark
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.HTTP
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.PUT
|
||||
|
||||
private const val SESSION_ID_HEADER = "X-Session-Id"
|
||||
|
||||
interface ShioriApi {
|
||||
@POST("/api/login") suspend fun login(@Body body: AuthRequest): AuthResponse
|
||||
|
||||
@SuppressLint("RetrofitUsage") // POST without a body is apparently fine?
|
||||
@POST("/api/logout")
|
||||
suspend fun logout(@Header(SESSION_ID_HEADER) sessionId: String)
|
||||
|
||||
@GET("/api/bookmarks")
|
||||
suspend fun getBookmarks(@Header(SESSION_ID_HEADER) sessionId: String): BookmarksResponse
|
||||
|
||||
@POST("/api/bookmarks")
|
||||
suspend fun addBookmark(
|
||||
@Header(SESSION_ID_HEADER) sessionId: String,
|
||||
@Body bookmarkRequest: BookmarkRequest,
|
||||
): Bookmark
|
||||
|
||||
@PUT("/api/bookmarks")
|
||||
suspend fun editBookmark(
|
||||
@Header(SESSION_ID_HEADER) sessionId: String,
|
||||
@Body bookmark: EditedBookmark,
|
||||
): Bookmark
|
||||
|
||||
@HTTP(method = "DELETE", path = "/api/bookmarks", hasBody = true)
|
||||
suspend fun deleteBookmark(
|
||||
@Header(SESSION_ID_HEADER) sessionId: String,
|
||||
@Body ids: List<Int>,
|
||||
): Int
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class Account(
|
||||
val id: Int,
|
||||
val username: String,
|
||||
val owner: Boolean,
|
||||
)
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class AuthRequest(
|
||||
val username: String,
|
||||
val password: String,
|
||||
val remember: Boolean = true,
|
||||
val owner: Boolean = false,
|
||||
)
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class AuthResponse(
|
||||
val session: String,
|
||||
val expires: String,
|
||||
val account: Account,
|
||||
)
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class Bookmark(
|
||||
val id: Int,
|
||||
val url: String,
|
||||
val title: String,
|
||||
val excerpt: String,
|
||||
val author: String,
|
||||
val public: Int,
|
||||
val modified: String,
|
||||
val imageURL: String,
|
||||
val hasContent: Boolean,
|
||||
val hasArchive: Boolean,
|
||||
val tags: List<Tag>,
|
||||
val createArchive: Boolean,
|
||||
)
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class BookmarkRequest(
|
||||
val url: String,
|
||||
val createArchive: Boolean,
|
||||
val public: Int,
|
||||
val tags: List<Tag>,
|
||||
val title: String,
|
||||
val excerpt: String,
|
||||
)
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class BookmarksResponse(
|
||||
val bookmarks: List<Bookmark>,
|
||||
val maxPage: Int,
|
||||
val page: Int,
|
||||
)
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Poko
|
||||
class EditedBookmark(
|
||||
val id: Int,
|
||||
val url: String? = null,
|
||||
val title: String? = null,
|
||||
val excerpt: String? = null,
|
||||
val author: String? = null,
|
||||
val public: Int? = null,
|
||||
val modified: String? = null,
|
||||
val imageURL: String? = null,
|
||||
val hasContent: Boolean? = null,
|
||||
val hasArchive: Boolean? = null,
|
||||
val tags: List<Tag>? = null,
|
||||
val createArchive: Boolean? = null,
|
||||
)
|
12
model/src/main/kotlin/dev/msfjarvis/claw/model/shiori/Tag.kt
Normal file
12
model/src/main/kotlin/dev/msfjarvis/claw/model/shiori/Tag.kt
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright © 2022-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model.shiori
|
||||
|
||||
import dev.drewhamilton.poko.Poko
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable @Poko class Tag(val name: String)
|
Loading…
Add table
Add a link
Reference in a new issue