mirror of https://github.com/jlelse/teleposter
Upgrade Fuel to 2.0.1 (also bump min sdk to 19 - required for update)
This commit is contained in:
parent
b17d8802a5
commit
c93a7ae575
|
@ -6,7 +6,7 @@ android {
|
|||
buildToolsVersion "28.0.3"
|
||||
defaultConfig {
|
||||
applicationId "telegra.ph"
|
||||
minSdkVersion 17
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 28
|
||||
versionCode 15
|
||||
versionName "1.5.2"
|
||||
|
@ -34,6 +34,7 @@ dependencies {
|
|||
implementation 'com.github.delight-im:Android-AdvancedWebView:3.1.3'
|
||||
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc10'
|
||||
implementation 'com.afollestad.material-dialogs:input:2.0.0-rc10'
|
||||
implementation 'com.github.kittinunf.fuel:fuel:1.16.0'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-android:1.16.0'
|
||||
implementation 'com.github.kittinunf.fuel:fuel:2.0.1'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-android:2.0.1'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-json:2.0.1'
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package telegra.ph
|
||||
|
||||
import com.github.kittinunf.fuel.android.core.Json
|
||||
import com.github.kittinunf.fuel.android.extension.responseJson
|
||||
import com.github.kittinunf.fuel.core.FuelError
|
||||
import com.github.kittinunf.fuel.core.FuelManager
|
||||
import com.github.kittinunf.fuel.core.Request
|
||||
import com.github.kittinunf.fuel.core.Response
|
||||
import com.github.kittinunf.fuel.core.interceptors.redirectResponseInterceptor
|
||||
import com.github.kittinunf.fuel.core.interceptors.validatorResponseInterceptor
|
||||
import com.github.kittinunf.fuel.httpPost
|
||||
import com.github.kittinunf.fuel.json.FuelJson
|
||||
import com.github.kittinunf.fuel.json.responseJson
|
||||
import com.github.kittinunf.result.Result
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
@ -27,12 +26,11 @@ object TelegraphApi {
|
|||
// Fix login
|
||||
FuelManager.instance.addResponseInterceptor {
|
||||
redirectResponseInterceptor(FuelManager.instance)
|
||||
validatorResponseInterceptor(200..299)
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
private fun callService(method: String, parameters: List<Pair<String, Any?>>, handler: (Request, Response, Result<Json, FuelError>) -> Unit) {
|
||||
private fun callService(method: String, parameters: List<Pair<String, Any?>>, handler: (Request, Response, Result<FuelJson, FuelError>) -> Unit) {
|
||||
val requestObject = JSONObject()
|
||||
parameters.forEach {
|
||||
requestObject.put(it.first, it.second)
|
||||
|
@ -153,7 +151,7 @@ object TelegraphApi {
|
|||
|
||||
// Teleposter
|
||||
|
||||
private fun <T> handleResponse(result: Result<Json, FuelError>, handler: (success: Boolean, obj: T?, error: String?) -> Unit, callback: (obj: JSONObject) -> Unit) {
|
||||
private fun <T> handleResponse(result: Result<FuelJson, FuelError>, handler: (success: Boolean, obj: T?, error: String?) -> Unit, callback: (obj: JSONObject) -> Unit) {
|
||||
val (json, error) = result
|
||||
if (error == null && json != null) {
|
||||
val jsonObj = json.obj()
|
||||
|
@ -182,8 +180,8 @@ object TelegraphApi {
|
|||
private fun telegraphLoginInterceptor(): (Request, Response) -> Response =
|
||||
{ _, response ->
|
||||
response.headers["Set-Cookie"]
|
||||
?.flatMap { HttpCookie.parse(it) }
|
||||
?.find { it.name == "tph_token" }
|
||||
.flatMap { HttpCookie.parse(it) }
|
||||
.find { it.name == "tph_token" }
|
||||
?.let {
|
||||
loginAccessToken = it.value
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue