| author | Da Risk <da_risk@geekorum.com> |
| Sun, 27 Oct 2019 19:08:06 -0700 | |
| changeset 529 | 816733b3fd0c |
| parent 310 | bd0611482474 |
| child 563 | c901622a9a73 |
| 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 |
* |
|
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
113
diff
changeset
|
4 |
* Copyright (C) 2017-2019 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 |
*/ |
|
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
300
diff
changeset
|
21 |
package com.geekorum.ttrss.webapi.model |
| 0 | 22 |
|
23 |
import androidx.annotation.Keep |
|
24 |
import kotlinx.serialization.CompositeDecoder |
|
25 |
import kotlinx.serialization.Decoder |
|
26 |
import kotlinx.serialization.Encoder |
|
27 |
import kotlinx.serialization.KSerializer |
|
28 |
import kotlinx.serialization.SerialName |
|
29 |
import kotlinx.serialization.Serializable |
|
30 |
import kotlinx.serialization.Serializer |
|
31 |
import kotlinx.serialization.internal.IntSerializer |
|
32 |
import kotlinx.serialization.internal.makeNullable |
|
33 |
||
34 |
/** |
|
35 |
* The payload gor a getHeadlines request. |
|
36 |
* |
|
37 |
* It allows to retrieve articles from the Tiny Tiny Rss server. |
|
38 |
*/ |
|
39 |
@Keep |
|
40 |
@Serializable |
|
41 |
data class GetArticlesRequestPayload( |
|
42 |
@SerialName("feed_id")
|
|
43 |
val feedId: Long, |
|
44 |
||
45 |
@SerialName("view_mode")
|
|
46 |
val viewMode: ViewMode = ViewMode.ALL_ARTICLES, |
|
47 |
||
48 |
@SerialName("show_content")
|
|
49 |
val showContent: Boolean = true, |
|
50 |
||
51 |
@SerialName("show_excerpt")
|
|
52 |
val showExcerpt: Boolean = true, |
|
53 |
||
54 |
private val skip: Int = 0, |
|
55 |
||
56 |
@SerialName("since_id")
|
|
57 |
val sinceId: Long = 0, |
|
58 |
||
59 |
val limit: Int = 200, |
|
60 |
||
61 |
@SerialName("order_by")
|
|
62 |
val orderBy: SortOrder = SortOrder.NOTHING |
|
63 |
) : LoggedRequestPayload() {
|
|
64 |
||
65 |
@SerialName("op")
|
|
66 |
override val operation = "getHeadlines" |
|
67 |
||
68 |
enum class ViewMode {
|
|
69 |
@SerialName("all_articles")
|
|
70 |
ALL_ARTICLES, |
|
71 |
@SerialName("unread")
|
|
72 |
UNREAD, |
|
73 |
@SerialName("adaptive")
|
|
74 |
ADAPTIVE, |
|
75 |
@SerialName("marked")
|
|
76 |
MARKED, |
|
77 |
@SerialName("updated")
|
|
78 |
UPDATED |
|
79 |
} |
|
80 |
||
81 |
enum class SortOrder {
|
|
82 |
@SerialName("title")
|
|
83 |
TITLE, |
|
84 |
@SerialName("date_reverse")
|
|
85 |
DATE_REVERSE, |
|
86 |
@SerialName("feed_dates")
|
|
87 |
FEED_DATES, |
|
88 |
@SerialName("")
|
|
89 |
NOTHING |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
||
94 |
/** |
|
95 |
* Request payload to update an Article. |
|
96 |
*/ |
|
97 |
@Keep |
|
98 |
@Serializable |
|
99 |
data class UpdateArticleRequestPayload( |
|
100 |
@SerialName("article_ids")
|
|
101 |
val articleIds: String, |
|
102 |
val mode: Int, |
|
103 |
val field: Int, |
|
104 |
val data: String? = null |
|
105 |
) : LoggedRequestPayload() {
|
|
106 |
||
107 |
@SerialName("op")
|
|
108 |
override val operation = "updateArticle" |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* The response of an update article request. |
|
113 |
*/ |
|
114 |
@Keep |
|
115 |
//@Serializable |
|
116 |
data class UpdateArticleResponsePayload( |
|
117 |
@SerialName("seq")
|
|
118 |
override val sequence: Int? = null, |
|
119 |
override val status: Int = 0, |
|
120 |
override val content: UpdateArticleResponsePayload.Content |
|
121 |
) : ResponsePayload<UpdateArticleResponsePayload.Content>() {
|
|
122 |
||
123 |
@Transient |
|
124 |
val updated: Int = content.updated ?: 0 |
|
125 |
||
126 |
@Serializable |
|
127 |
data class Content( |
|
128 |
val status: String? = null, |
|
129 |
val updated: Int? = null, |
|
|
248
47e6ff1ded90
Json: use enum for Error in BaseContent
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
130 |
override var error: Error? = null |
| 0 | 131 |
): BaseContent() |
132 |
||
133 |
companion object {
|
|
134 |
fun serializer(): KSerializer<UpdateArticleResponsePayload> {
|
|
|
529
816733b3fd0c
webapi: convert serializers to objects when appropriate
Da Risk <da_risk@geekorum.com>
parents:
310
diff
changeset
|
135 |
return UpdateArticleResponsePayloadSerializer |
| 0 | 136 |
} |
137 |
} |
|
138 |
||
139 |
@Serializer(UpdateArticleResponsePayload::class) |
|
|
529
816733b3fd0c
webapi: convert serializers to objects when appropriate
Da Risk <da_risk@geekorum.com>
parents:
310
diff
changeset
|
140 |
object UpdateArticleResponsePayloadSerializer : KSerializer<UpdateArticleResponsePayload> {
|
| 300 | 141 |
override fun serialize(encoder: Encoder, obj: UpdateArticleResponsePayload) {
|
| 0 | 142 |
TODO("not implemented")
|
143 |
} |
|
144 |
||
| 300 | 145 |
override fun deserialize(decoder: Decoder): UpdateArticleResponsePayload {
|
146 |
val contentDecoder = decoder.beginStructure(descriptor) |
|
| 0 | 147 |
lateinit var content: Content |
148 |
var seq: Int? = null |
|
149 |
var status = 0 |
|
150 |
loop@ while (true) {
|
|
151 |
when(val i = contentDecoder.decodeElementIndex(descriptor)) {
|
|
152 |
CompositeDecoder.READ_DONE -> break@loop |
|
153 |
0 -> seq = contentDecoder.decodeNullableSerializableElement(descriptor, i, |
|
154 |
makeNullable(IntSerializer)) |
|
155 |
1 -> status = contentDecoder.decodeIntElement(descriptor, i) |
|
156 |
2 -> {
|
|
157 |
val contentSerializer = Content.serializer() |
|
158 |
content = contentDecoder.decodeSerializableElement(contentSerializer.descriptor, i, |
|
159 |
contentSerializer) |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
contentDecoder.endStructure(descriptor) |
|
164 |
return UpdateArticleResponsePayload( |
|
165 |
content = content, |
|
166 |
sequence = seq, |
|
167 |
status = status |
|
168 |
) |
|
169 |
} |
|
170 |
} |
|
171 |
} |