| author | Da Risk <da_risk@geekorum.com> |
| Mon, 16 Jan 2023 17:05:31 -0400 | |
| changeset 943 | 298742859784 |
| parent 882 | 7a74abf66c49 |
| child 1135 | 5dd06d1fbe83 |
| permissions | -rw-r--r-- |
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
113
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
|
943
298742859784
build: update license headers
Da Risk <da_risk@geekorum.com>
parents:
882
diff
changeset
|
4 |
* Copyright (C) 2017-2023 by Frederic-Charles Barthelery. |
| 0 | 5 |
* |
6 |
* This file is part of Geekttrss. |
|
7 |
* |
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* Geekttrss is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
|
754
a138890f66f0
webapi: update dependencies and fix some warnings
Da Risk <da_risk@geekorum.com>
parents:
750
diff
changeset
|
21 |
@file:OptIn(ExperimentalSerializationApi::class) |
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
300
diff
changeset
|
22 |
package com.geekorum.ttrss.webapi.model |
| 0 | 23 |
|
24 |
import androidx.annotation.Keep |
|
|
754
a138890f66f0
webapi: update dependencies and fix some warnings
Da Risk <da_risk@geekorum.com>
parents:
750
diff
changeset
|
25 |
import kotlinx.serialization.ExperimentalSerializationApi |
| 0 | 26 |
import kotlinx.serialization.KSerializer |
27 |
import kotlinx.serialization.SerialName |
|
28 |
import kotlinx.serialization.Serializable |
|
29 |
import kotlinx.serialization.Serializer |
|
|
651
dac728baf12b
webapi: update to latest serialization runtime library
Da Risk <da_risk@geekorum.com>
parents:
649
diff
changeset
|
30 |
import kotlinx.serialization.builtins.nullable |
|
dac728baf12b
webapi: update to latest serialization runtime library
Da Risk <da_risk@geekorum.com>
parents:
649
diff
changeset
|
31 |
import kotlinx.serialization.builtins.serializer |
| 750 | 32 |
import kotlinx.serialization.encoding.CompositeDecoder |
33 |
import kotlinx.serialization.encoding.Decoder |
|
34 |
import kotlinx.serialization.encoding.Encoder |
|
| 0 | 35 |
|
36 |
/** |
|
37 |
* The payload gor a getHeadlines request. |
|
38 |
* |
|
39 |
* It allows to retrieve articles from the Tiny Tiny Rss server. |
|
40 |
*/ |
|
41 |
@Keep |
|
42 |
@Serializable |
|
43 |
data class GetArticlesRequestPayload( |
|
44 |
@SerialName("feed_id")
|
|
45 |
val feedId: Long, |
|
46 |
||
47 |
@SerialName("view_mode")
|
|
48 |
val viewMode: ViewMode = ViewMode.ALL_ARTICLES, |
|
49 |
||
50 |
@SerialName("show_content")
|
|
51 |
val showContent: Boolean = true, |
|
52 |
||
53 |
@SerialName("show_excerpt")
|
|
54 |
val showExcerpt: Boolean = true, |
|
55 |
||
|
624
cd636ef89d05
webapi: Allow to request headline attachments
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
56 |
@SerialName("include_attachments")
|
|
cd636ef89d05
webapi: Allow to request headline attachments
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
57 |
val includeAttachments: Boolean = false, |
|
cd636ef89d05
webapi: Allow to request headline attachments
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
58 |
|
| 0 | 59 |
private val skip: Int = 0, |
60 |
||
61 |
@SerialName("since_id")
|
|
62 |
val sinceId: Long = 0, |
|
63 |
||
64 |
val limit: Int = 200, |
|
65 |
||
66 |
@SerialName("order_by")
|
|
67 |
val orderBy: SortOrder = SortOrder.NOTHING |
|
68 |
) : LoggedRequestPayload() {
|
|
69 |
||
70 |
@SerialName("op")
|
|
71 |
override val operation = "getHeadlines" |
|
72 |
||
|
600
c9d6a339dd04
build: update some androidx dependencies
Da Risk <da_risk@geekorum.com>
parents:
565
diff
changeset
|
73 |
@Serializable |
| 0 | 74 |
enum class ViewMode {
|
75 |
@SerialName("all_articles")
|
|
76 |
ALL_ARTICLES, |
|
77 |
@SerialName("unread")
|
|
78 |
UNREAD, |
|
79 |
@SerialName("adaptive")
|
|
80 |
ADAPTIVE, |
|
81 |
@SerialName("marked")
|
|
82 |
MARKED, |
|
83 |
@SerialName("updated")
|
|
84 |
UPDATED |
|
85 |
} |
|
86 |
||
|
600
c9d6a339dd04
build: update some androidx dependencies
Da Risk <da_risk@geekorum.com>
parents:
565
diff
changeset
|
87 |
@Serializable |
| 0 | 88 |
enum class SortOrder {
|
89 |
@SerialName("title")
|
|
90 |
TITLE, |
|
91 |
@SerialName("date_reverse")
|
|
92 |
DATE_REVERSE, |
|
93 |
@SerialName("feed_dates")
|
|
94 |
FEED_DATES, |
|
95 |
@SerialName("")
|
|
96 |
NOTHING |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
||
101 |
/** |
|
102 |
* Request payload to update an Article. |
|
103 |
*/ |
|
104 |
@Keep |
|
105 |
@Serializable |
|
106 |
data class UpdateArticleRequestPayload( |
|
107 |
@SerialName("article_ids")
|
|
108 |
val articleIds: String, |
|
109 |
val mode: Int, |
|
110 |
val field: Int, |
|
111 |
val data: String? = null |
|
112 |
) : LoggedRequestPayload() {
|
|
113 |
||
114 |
@SerialName("op")
|
|
115 |
override val operation = "updateArticle" |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* The response of an update article request. |
|
120 |
*/ |
|
121 |
@Keep |
|
|
565
22a9c6bb238d
webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents:
563
diff
changeset
|
122 |
@Serializable(UpdateArticleResponsePayload.OwnSerializer::class) |
| 0 | 123 |
data class UpdateArticleResponsePayload( |
124 |
@SerialName("seq")
|
|
125 |
override val sequence: Int? = null, |
|
126 |
override val status: Int = 0, |
|
|
565
22a9c6bb238d
webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents:
563
diff
changeset
|
127 |
override val content: Content |
| 0 | 128 |
) : ResponsePayload<UpdateArticleResponsePayload.Content>() {
|
129 |
||
130 |
@Transient |
|
131 |
val updated: Int = content.updated ?: 0 |
|
132 |
||
133 |
@Serializable |
|
134 |
data class Content( |
|
135 |
val status: String? = null, |
|
136 |
val updated: Int? = null, |
|
|
248
47e6ff1ded90
Json: use enum for Error in BaseContent
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
137 |
override var error: Error? = null |
| 0 | 138 |
): BaseContent() |
139 |
||
140 |
@Serializer(UpdateArticleResponsePayload::class) |
|
|
565
22a9c6bb238d
webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents:
563
diff
changeset
|
141 |
internal object OwnSerializer : KSerializer<UpdateArticleResponsePayload> {
|
| 649 | 142 |
override fun serialize(encoder: Encoder, value: UpdateArticleResponsePayload) {
|
| 0 | 143 |
TODO("not implemented")
|
144 |
} |
|
145 |
||
| 300 | 146 |
override fun deserialize(decoder: Decoder): UpdateArticleResponsePayload {
|
147 |
val contentDecoder = decoder.beginStructure(descriptor) |
|
| 0 | 148 |
lateinit var content: Content |
149 |
var seq: Int? = null |
|
150 |
var status = 0 |
|
151 |
loop@ while (true) {
|
|
152 |
when(val i = contentDecoder.decodeElementIndex(descriptor)) {
|
|
| 750 | 153 |
CompositeDecoder.DECODE_DONE -> break@loop |
| 0 | 154 |
0 -> seq = contentDecoder.decodeNullableSerializableElement(descriptor, i, |
|
640
f6f64ebc7773
webapi, faviKonSnoop: update serialization runtime for kotlin 1.3.70
Da Risk <da_risk@geekorum.com>
parents:
624
diff
changeset
|
155 |
Int.serializer().nullable) |
| 0 | 156 |
1 -> status = contentDecoder.decodeIntElement(descriptor, i) |
157 |
2 -> {
|
|
158 |
val contentSerializer = Content.serializer() |
|
159 |
content = contentDecoder.decodeSerializableElement(contentSerializer.descriptor, i, |
|
160 |
contentSerializer) |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
contentDecoder.endStructure(descriptor) |
|
165 |
return UpdateArticleResponsePayload( |
|
166 |
content = content, |
|
167 |
sequence = seq, |
|
168 |
status = status |
|
169 |
) |
|
170 |
} |
|
171 |
} |
|
172 |
} |