aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-26 18:35:01 -0500
committerAllan Wang <me@allanwang.ca>2018-12-26 18:35:01 -0500
commitbddb58f035b9190732f22db4b2cc1464b68fff17 (patch)
treef650731e97bd94d5dd2725b13d657059eb9c4ee1 /app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
parent3a3096be58bacd9408c10ef5d8add6c32204d4e9 (diff)
downloadfrost-bddb58f035b9190732f22db4b2cc1464b68fff17.tar.gz
frost-bddb58f035b9190732f22db4b2cc1464b68fff17.tar.bz2
frost-bddb58f035b9190732f22db4b2cc1464b68fff17.zip
Merge new auth flyweight and update hd image fetcher
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt25
1 files changed, 5 insertions, 20 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
index 1aa2a1b6..0692fbfd 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
@@ -24,38 +24,25 @@ import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FB_USER_MATCHER
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.facebook.get
-import com.pitchedapps.frost.rx.RxFlyweight
+import com.pitchedapps.frost.rx.Flyweight
import com.pitchedapps.frost.utils.L
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.channels.Channel
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.selects.select
+import kotlinx.coroutines.GlobalScope
import okhttp3.Call
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.logging.HttpLoggingInterceptor
import org.apache.commons.text.StringEscapeUtils
-import kotlin.coroutines.Continuation
-import kotlin.coroutines.suspendCoroutine
/**
* Created by Allan Wang on 21/12/17.
*/
-private class RxAuth : RxFlyweight<String, Long, RequestAuth>() {
-
- override fun call(input: String) = input.getAuth()
-
- override fun validate(input: String, cond: Long) =
- System.currentTimeMillis() - cond < 3600000 // valid for an hour
-
- override fun cache(input: String) = System.currentTimeMillis()
+ val fbAuth = Flyweight<String, RequestAuth>(GlobalScope, 100,3600000 /* an hour */) {
+ it.getAuth()
}
-private val auth = RxAuth()
-
/**
* Synchronously fetch [RequestAuth] from cookie
* [action] will only be called if a valid auth is found.
@@ -64,7 +51,7 @@ private val auth = RxAuth()
fun String?.fbRequest(fail: () -> Unit = {}, action: RequestAuth.() -> Unit) {
if (this == null) return fail()
try {
- val auth = auth(this).blockingGet()
+ val auth = fbAuth(this).blockingGet()
auth.action()
} catch (e: Exception) {
L.e { "Failed auth for ${hashCode()}: ${e.message}" }
@@ -72,8 +59,6 @@ fun String?.fbRequest(fail: () -> Unit = {}, action: RequestAuth.() -> Unit) {
}
}
-data class FbRequest(val cookie: String, val request: suspend (RequestAuth) -> Unit)
-
/**
* Underlying container for all fb requests
*/