Linting ajax files

This commit is contained in:
ivan agosto 2019-02-17 17:29:52 -06:00
parent 90aac608be
commit d680eb77b8
5 changed files with 62 additions and 69 deletions

View File

@ -6,7 +6,7 @@ import java.io.InputStreamReader
class Actions: Client() {
fun subscribe(token: String, account: String):Int{
var con=this._newCon("users/me/subscriptions","POST", token)
val con = this._newCon("users/me/subscriptions","POST", token)
val params:String= "uri=$account"
con.outputStream.write(params.toByteArray())
var response = 0
@ -25,7 +25,7 @@ class Actions: Client() {
}
fun unSubscribe(token: String, account: String):Int{
var con=this._newCon("users/me/subscriptions/$account","DELETE", token)
val con = this._newCon("users/me/subscriptions/$account","DELETE", token)
var response = 0
try {
@ -42,13 +42,13 @@ class Actions: Client() {
}
fun getSubscription(token: String, account: String): Boolean{
var con=this._newCon("users/me/subscriptions/exist?uris=$account","GET", token)
val con = this._newCon("users/me/subscriptions/exist?uris=$account","GET", token)
var isSubscribed = false
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()){
val key = data.nextName()
@ -72,8 +72,8 @@ class Actions: Client() {
}
fun rate(token: String, id_video: Int, rate: String):Int{
var con=this._newCon("videos/$id_video/rate","PUT", token)
val params:String= "rating=$rate"
val con = this._newCon("videos/$id_video/rate","PUT", token)
val params = "rating=$rate"
con.outputStream.write(params.toByteArray())
var response = 0
@ -91,13 +91,13 @@ class Actions: Client() {
}
fun getRate(token: String, id_video: Int):String{
var con=this._newCon("users/me/videos/$id_video/rating","GET", token)
val con = this._newCon("users/me/videos/$id_video/rating","GET", token)
var rating = "none"
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()){
val key = data.nextName()

View File

@ -10,19 +10,19 @@ import org.libre.agosto.p2play.models.UserModel
import java.io.InputStreamReader
class Auth: Client() {
val stockParams = "grant_type=password"
private val stockParams = "grant_type=password"
fun login(username: String, password: String, client_id: String, client_secret: String): TokenModel{
var con = this._newCon("users/token","POST")
val params:String= "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
val con = this._newCon("users/token","POST")
val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
con.outputStream.write(params.toByteArray())
var token = TokenModel()
val token = TokenModel()
try {
if(con.responseCode==200){
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while(data.hasNext()){
@ -51,8 +51,8 @@ class Auth: Client() {
}
fun register(username: String, password: String, email: String): Int{
var con = this._newCon("users/register","POST")
val params:String= "username=$username&password=$password&email=$email"
val con = this._newCon("users/register","POST")
val params = "username=$username&password=$password&email=$email"
con.outputStream.write(params.toByteArray())
var response = 0
@ -72,15 +72,15 @@ class Auth: Client() {
}
fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel{
var con = this._newCon("users/token", "POST", token.token)
val params:String = "refresh_token=${token.refresh_token}&response_type=code&grant_type=refresh_token&client_id=$client_id&client_secret=$client_secret"
val con = this._newCon("users/token", "POST", token.token)
val params = "refresh_token=${token.refresh_token}&response_type=code&grant_type=refresh_token&client_id=$client_id&client_secret=$client_secret"
con.outputStream.write(params.toByteArray())
var token = TokenModel()
// val token = TokenModel()
try {
if(con.responseCode==200){
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while(data.hasNext()){
@ -109,15 +109,14 @@ class Auth: Client() {
}
fun me(token: String): UserModel{
var con = this._newCon("users/me","GET", token)
var user = UserModel()
val con = this._newCon("users/me","GET", token)
val user = UserModel()
try {
if(con.responseCode==200){
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while(data.hasNext()){

View File

@ -1,6 +1,5 @@
package org.libre.agosto.p2play.ajax
import android.content.SharedPreferences
import android.util.JsonReader
import android.util.Log
import org.libre.agosto.p2play.ManagerSingleton
@ -13,22 +12,22 @@ open class Client {
protected fun _newCon(uri: String, method: String, token: String = ""): HttpURLConnection {
var url = URL("https://"+ManagerSingleton.url+"/api/v1/"+uri)
var con = url.openConnection() as HttpURLConnection
val url = URL("https://${ManagerSingleton.url}/api/v1/$uri")
val con = url.openConnection() as HttpURLConnection
con.setRequestProperty("User-Agent", "P2play/0.1")
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
con.setRequestProperty("Accept", "*/*")
if(token != ""){
con.setRequestProperty("Authorization", "Bearer ${token}")
con.setRequestProperty("Authorization", "Bearer $token")
}
con.requestMethod=method
con.connectTimeout=10000
con.readTimeout=10000
if(method.equals("POST"))
if(method == "POST")
con.doOutput=true
Log.d("Petition", url.toString())
@ -36,12 +35,12 @@ open class Client {
}
fun getKeys():HostModel{
var con=this._newCon("oauth-clients/local","GET")
var keys = HostModel("","")
val con = this._newCon("oauth-clients/local","GET")
val keys = HostModel("","")
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()) {
val key = data.nextName()
@ -58,12 +57,10 @@ open class Client {
}
}
}
Log.d("Key",keys.client_id)
return keys
} catch(err:Exception){
Log.d("Error",err.message)
return keys
err.printStackTrace()
}
return keys
}

View File

@ -9,7 +9,7 @@ import java.io.InputStreamReader
class Comments: Client() {
fun parseCommentaries(data: JsonReader): ArrayList<CommentaryModel> {
var commentaries = arrayListOf<CommentaryModel>()
val commentaries = arrayListOf<CommentaryModel>()
data.beginObject()
while (data.hasNext()){
when(data.nextName()) {
@ -76,14 +76,12 @@ class Comments: Client() {
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
commentaries = parseCommentaries(data)
}
} catch(err:Exception){
err?.printStackTrace()
Log.d("TypeErr",err?.message ,err.cause)
Log.d("Error","fallo la coneccion")
err.printStackTrace()
}
return commentaries
@ -91,7 +89,7 @@ class Comments: Client() {
fun makeCommentary(token: String, videoId: Int, text: String): Boolean {
val con = this._newCon("videos/$videoId/comment-threads", "POST", token)
val params:String= "text=$text"
val params = "text=$text"
con.outputStream.write(params.toByteArray())
try {

View File

@ -2,7 +2,6 @@ package org.libre.agosto.p2play.ajax
import android.util.JsonReader
import android.util.JsonToken
import android.util.Log
import org.libre.agosto.p2play.ManagerSingleton
import org.libre.agosto.p2play.models.VideoModel
import java.io.InputStreamReader
@ -10,7 +9,7 @@ import java.io.InputStreamReader
class Videos: Client() {
private fun parseVideos(data: JsonReader): ArrayList<VideoModel>{
var videos = arrayListOf<VideoModel>()
val videos = arrayListOf<VideoModel>()
data.beginObject()
while (data.hasNext()){
when(data.nextName()){
@ -98,16 +97,16 @@ class Videos: Client() {
var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw"
if(filter != "")
params+="&filter=$filter"
var con=this._newCon("videos?$params","GET")
val con = this._newCon("videos?$params","GET")
var videos = arrayListOf<VideoModel>()
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
videos = parseVideos(data)
}
} catch(err:Exception){
err?.printStackTrace()
err.printStackTrace()
}
return videos
}
@ -127,16 +126,16 @@ class Videos: Client() {
fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel>{
val count = ManagerSingleton.videos_count
val params = "start=$start&count=$count"
var con=this._newCon("users/me/videos?$params","GET", token)
val con = this._newCon("users/me/videos?$params","GET", token)
var videos = arrayListOf<VideoModel>()
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
videos = parseVideos(data)
}
} catch(err:Exception){
err?.printStackTrace()
err.printStackTrace()
}
return videos
}
@ -144,16 +143,16 @@ class Videos: Client() {
fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel>{
val count = ManagerSingleton.videos_count
val params = "start=$start&count=$count"
var con=this._newCon("users/me/subscriptions/videos?$params","GET", token)
val con = this._newCon("users/me/subscriptions/videos?$params","GET", token)
var videos = arrayListOf<VideoModel>()
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
videos = parseVideos(data)
}
} catch(err:Exception){
err?.printStackTrace()
err.printStackTrace()
}
return videos
}
@ -162,27 +161,27 @@ class Videos: Client() {
val count = ManagerSingleton.videos_count
val nsfw = ManagerSingleton.nfsw
val params = "search=$text&start=$start&count=$count&nsfw=$nsfw"
var con=this._newCon("search/videos?$params","GET")
val con = this._newCon("search/videos?$params","GET")
var videos = arrayListOf<VideoModel>()
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
videos = parseVideos(data)
}
} catch(err:Exception){
err?.printStackTrace()
err.printStackTrace()
}
return videos
}
fun fullDescription(videoId: Int): String{
var con=this._newCon("videos/$videoId/description","GET")
val con = this._newCon("videos/$videoId/description","GET")
var description = ""
try {
if (con.responseCode == 200) {
var response = InputStreamReader(con.inputStream)
var data = JsonReader(response)
val response = InputStreamReader(con.inputStream)
val data = JsonReader(response)
data.beginObject()
while (data.hasNext()){