| author | Da Risk <da_risk@geekorum.com> |
| Fri, 07 Feb 2020 00:03:27 -0400 | |
| changeset 611 | 91b8d76c03cd |
| parent 600 | c9d6a339dd04 |
| child 624 | cd636ef89d05 |
| 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 |
* |
|
| 611 | 4 |
* Copyright (C) 2017-2020 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 |
|
| 563 | 32 |
import kotlinx.serialization.internal.nullable |
| 0 | 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 |
||
|
600
c9d6a339dd04
build: update some androidx dependencies
Da Risk <da_risk@geekorum.com>
parents:
565
diff
changeset
|
68 |
@Serializable |
| 0 | 69 |
enum class ViewMode {
|
70 |
@SerialName("all_articles")
|
|
71 |
ALL_ARTICLES, |
|
72 |
@SerialName("unread")
|
|
73 |
UNREAD, |
|
74 |
@SerialName("adaptive")
|
|
75 |
ADAPTIVE, |
|
76 |
@SerialName("marked")
|
|
77 |
MARKED, |
|
78 |
@SerialName("updated")
|
|
79 |
UPDATED |
|
80 |
} |
|
81 |
||
|
600
c9d6a339dd04
build: update some androidx dependencies
Da Risk <da_risk@geekorum.com>
parents:
565
diff
changeset
|
82 |
@Serializable |
| 0 | 83 |
enum class SortOrder {
|
84 |
@SerialName("title")
|
|
85 |
TITLE, |
|
86 |
@SerialName("date_reverse")
|
|
87 |
DATE_REVERSE, |
|
88 |
@SerialName("feed_dates")
|
|
89 |
FEED_DATES, |
|
90 |
@SerialName("")
|
|
91 |
NOTHING |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
||
96 |
/** |
|
97 |
* Request payload to update an Article. |
|
98 |
*/ |
|
99 |
@Keep |
|
100 |
@Serializable |
|
101 |
data class UpdateArticleRequestPayload( |
|
102 |
@SerialName("article_ids")
|
|
103 |
val articleIds: String, |
|
104 |
val mode: Int, |
|
105 |
val field: Int, |
|
106 |
val data: String? = null |
|
107 |
) : LoggedRequestPayload() {
|
|
108 |
||
109 |
@SerialName("op")
|
|
110 |
override val operation = "updateArticle" |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* The response of an update article request. |
|
115 |
*/ |
|
116 |
@Keep |
|
|
565
22a9c6bb238d
webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents:
563
diff
changeset
|
117 |
@Serializable(UpdateArticleResponsePayload.OwnSerializer::class) |
| 0 | 118 |
data class UpdateArticleResponsePayload( |
119 |
@SerialName("seq")
|
|
120 |
override val sequence: Int? = null, |
|
121 |
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
|
122 |
override val content: Content |
| 0 | 123 |
) : ResponsePayload<UpdateArticleResponsePayload.Content>() {
|
124 |
||
125 |
@Transient |
|
126 |
val updated: Int = content.updated ?: 0 |
|
127 |
||
128 |
@Serializable |
|
129 |
data class Content( |
|
130 |
val status: String? = null, |
|
131 |
val updated: Int? = null, |
|
|
248
47e6ff1ded90
Json: use enum for Error in BaseContent
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
132 |
override var error: Error? = null |
| 0 | 133 |
): BaseContent() |
134 |
||
135 |
@Serializer(UpdateArticleResponsePayload::class) |
|
|
565
22a9c6bb238d
webapi: use @Serializable to generate the serializer() method
Da Risk <da_risk@geekorum.com>
parents:
563
diff
changeset
|
136 |
internal object OwnSerializer : KSerializer<UpdateArticleResponsePayload> {
|
| 300 | 137 |
override fun serialize(encoder: Encoder, obj: UpdateArticleResponsePayload) {
|
| 0 | 138 |
TODO("not implemented")
|
139 |
} |
|
140 |
||
| 300 | 141 |
override fun deserialize(decoder: Decoder): UpdateArticleResponsePayload {
|
142 |
val contentDecoder = decoder.beginStructure(descriptor) |
|
| 0 | 143 |
lateinit var content: Content |
144 |
var seq: Int? = null |
|
145 |
var status = 0 |
|
146 |
loop@ while (true) {
|
|
147 |
when(val i = contentDecoder.decodeElementIndex(descriptor)) {
|
|
148 |
CompositeDecoder.READ_DONE -> break@loop |
|
149 |
0 -> seq = contentDecoder.decodeNullableSerializableElement(descriptor, i, |
|
| 563 | 150 |
IntSerializer.nullable) |
| 0 | 151 |
1 -> status = contentDecoder.decodeIntElement(descriptor, i) |
152 |
2 -> {
|
|
153 |
val contentSerializer = Content.serializer() |
|
154 |
content = contentDecoder.decodeSerializableElement(contentSerializer.descriptor, i, |
|
155 |
contentSerializer) |
|
156 |
} |
|
157 |
} |
|
158 |
} |
|
159 |
contentDecoder.endStructure(descriptor) |
|
160 |
return UpdateArticleResponsePayload( |
|
161 |
content = content, |
|
162 |
sequence = seq, |
|
163 |
status = status |
|
164 |
) |
|
165 |
} |
|
166 |
} |
|
167 |
} |