mirror of https://github.com/jlelse/teleposter
Add API method to login (untested)
This commit is contained in:
parent
e9f035e260
commit
d82166935f
|
@ -10,6 +10,7 @@ import com.github.kittinunf.fuel.httpPost
|
||||||
import com.github.kittinunf.result.Result
|
import com.github.kittinunf.result.Result
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.net.HttpCookie
|
||||||
|
|
||||||
object TelegraphApi {
|
object TelegraphApi {
|
||||||
|
|
||||||
|
@ -151,4 +152,23 @@ object TelegraphApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Telegra.ph
|
||||||
|
|
||||||
|
fun login(authUrl: String, callback: (success: Boolean, accessToken: String?, account: Account?) -> Unit) {
|
||||||
|
authUrl.httpPost().response { _, response, _ ->
|
||||||
|
var token: String? = null
|
||||||
|
response.headers["Set-Cookie"]
|
||||||
|
?.flatMap { HttpCookie.parse(it) }
|
||||||
|
?.find { it.name == "tph_token" }
|
||||||
|
?.let {
|
||||||
|
token = it.value
|
||||||
|
}
|
||||||
|
if (token != null) getAccountInfo(accessToken = token!!) { success, account, _ ->
|
||||||
|
if (success) callback(true, token, account)
|
||||||
|
else callback(false, null, null)
|
||||||
|
}
|
||||||
|
else callback(false, null, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue