| author | Da Risk <da_risk@geekorum.com> |
| Mon, 15 Sep 2025 14:00:07 -0400 | |
| changeset 1370 | 13e39ef920a8 |
| parent 1174 | 731f6ee517b6 |
| permissions | -rw-r--r-- |
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
| 1370 | 4 |
* Copyright (C) 2017-2025 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:
271
diff
changeset
|
21 |
package com.geekorum.ttrss.webapi |
| 0 | 22 |
|
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
23 |
import com.geekorum.ttrss.webapi.model.LoggedRequestPayload |
|
580
a184a66bc77b
Update geekdroid, and make TokenRetriever functions suspendable
Da Risk <da_risk@geekorum.com>
parents:
310
diff
changeset
|
24 |
import kotlinx.coroutines.runBlocking |
| 0 | 25 |
import okhttp3.RequestBody |
26 |
import retrofit2.Converter |
|
27 |
import retrofit2.Retrofit |
|
28 |
import java.lang.reflect.Type |
|
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
29 |
import java.util.logging.Level |
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
30 |
import java.util.logging.Logger |
| 0 | 31 |
|
32 |
/** |
|
|
271
b4ca3126dc2d
TinyRssApi: add unsubscribeFromFeed() endpoint method
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
33 |
* This [Converter.Factory] intercept all RequestBody conversion for [LoggedRequestPayload] and its subclasses |
| 0 | 34 |
* and set the [LoggedRequestPayload.sessionId] . |
35 |
*/ |
|
36 |
// Don't @Inject it otherwise it can't be an Optional binding |
|
37 |
class LoggedRequestInterceptorFactory( |
|
38 |
private val tokenRetriever: TokenRetriever |
|
39 |
) : Converter.Factory() {
|
|
40 |
||
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
41 |
|
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
42 |
|
| 0 | 43 |
override fun requestBodyConverter( |
44 |
type: Type, parameterAnnotations: Array<out Annotation>, methodAnnotations: Array<out Annotation>, |
|
45 |
retrofit: Retrofit |
|
46 |
): Converter<*, RequestBody>? {
|
|
47 |
return when (type) {
|
|
48 |
is Class<*> -> {
|
|
49 |
if (LoggedRequestPayload::class.java.isAssignableFrom(type)) {
|
|
50 |
return Converter<LoggedRequestPayload, RequestBody> {
|
|
51 |
val delegate: Converter<LoggedRequestPayload, RequestBody> = |
|
52 |
retrofit.nextRequestBodyConverter(this, type, parameterAnnotations, methodAnnotations) |
|
53 |
try {
|
|
|
580
a184a66bc77b
Update geekdroid, and make TokenRetriever functions suspendable
Da Risk <da_risk@geekorum.com>
parents:
310
diff
changeset
|
54 |
runBlocking {
|
|
a184a66bc77b
Update geekdroid, and make TokenRetriever functions suspendable
Da Risk <da_risk@geekorum.com>
parents:
310
diff
changeset
|
55 |
it.sessionId = tokenRetriever.getToken() |
|
a184a66bc77b
Update geekdroid, and make TokenRetriever functions suspendable
Da Risk <da_risk@geekorum.com>
parents:
310
diff
changeset
|
56 |
} |
| 0 | 57 |
} catch (e: TokenRetriever.RetrieverException) {
|
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
58 |
logger.log(Level.CONFIG, "unable to retrieve token", e) |
| 0 | 59 |
} |
60 |
delegate.convert(it) |
|
61 |
} |
|
62 |
} |
|
63 |
return null |
|
64 |
} |
|
65 |
else -> null |
|
66 |
} |
|
67 |
} |
|
|
310
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
68 |
|
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
69 |
companion object {
|
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
70 |
private val logger by lazy {
|
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
71 |
Logger.getLogger(LoggedRequestInterceptorFactory::class.java.name) |
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
72 |
} |
|
bd0611482474
Extract tinyrss web api to a new module "webapi"
Da Risk <da_risk@geekorum.com>
parents:
271
diff
changeset
|
73 |
} |
| 0 | 74 |
} |