Linting ajax files
This commit is contained in:
parent
90aac608be
commit
d680eb77b8
|
@ -6,7 +6,7 @@ import java.io.InputStreamReader
|
||||||
class Actions: Client() {
|
class Actions: Client() {
|
||||||
|
|
||||||
fun subscribe(token: String, account: String):Int{
|
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"
|
val params:String= "uri=$account"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
var response = 0
|
var response = 0
|
||||||
|
@ -25,7 +25,7 @@ class Actions: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unSubscribe(token: String, account: String):Int{
|
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
|
var response = 0
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -42,13 +42,13 @@ class Actions: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSubscription(token: String, account: String): Boolean{
|
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
|
var isSubscribed = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()){
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
|
@ -72,8 +72,8 @@ class Actions: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rate(token: String, id_video: Int, rate: String):Int{
|
fun rate(token: String, id_video: Int, rate: String):Int{
|
||||||
var con=this._newCon("videos/$id_video/rate","PUT", token)
|
val con = this._newCon("videos/$id_video/rate","PUT", token)
|
||||||
val params:String= "rating=$rate"
|
val params = "rating=$rate"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
var response = 0
|
var response = 0
|
||||||
|
|
||||||
|
@ -91,13 +91,13 @@ class Actions: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRate(token: String, id_video: Int):String{
|
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"
|
var rating = "none"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()){
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
|
|
|
@ -10,19 +10,19 @@ import org.libre.agosto.p2play.models.UserModel
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
class Auth: Client() {
|
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{
|
fun login(username: String, password: String, client_id: String, client_secret: String): TokenModel{
|
||||||
var con = this._newCon("users/token","POST")
|
val con = this._newCon("users/token","POST")
|
||||||
val params:String= "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
|
val params = "$stockParams&username=$username&password=$password&client_id=$client_id&client_secret=$client_secret"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
var token = TokenModel()
|
val token = TokenModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(con.responseCode==200){
|
if(con.responseCode==200){
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while(data.hasNext()){
|
while(data.hasNext()){
|
||||||
|
@ -51,8 +51,8 @@ class Auth: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun register(username: String, password: String, email: String): Int{
|
fun register(username: String, password: String, email: String): Int{
|
||||||
var con = this._newCon("users/register","POST")
|
val con = this._newCon("users/register","POST")
|
||||||
val params:String= "username=$username&password=$password&email=$email"
|
val params = "username=$username&password=$password&email=$email"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
|
|
||||||
var response = 0
|
var response = 0
|
||||||
|
@ -72,15 +72,15 @@ class Auth: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel{
|
fun refreshToken(token: TokenModel, client_id: String, client_secret: String): TokenModel{
|
||||||
var con = this._newCon("users/token", "POST", token.token)
|
val 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 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())
|
con.outputStream.write(params.toByteArray())
|
||||||
var token = TokenModel()
|
// val token = TokenModel()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(con.responseCode==200){
|
if(con.responseCode==200){
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while(data.hasNext()){
|
while(data.hasNext()){
|
||||||
|
@ -109,15 +109,14 @@ class Auth: Client() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun me(token: String): UserModel{
|
fun me(token: String): UserModel{
|
||||||
var con = this._newCon("users/me","GET", token)
|
val con = this._newCon("users/me","GET", token)
|
||||||
|
val user = UserModel()
|
||||||
var user = UserModel()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(con.responseCode==200){
|
if(con.responseCode==200){
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
|
|
||||||
while(data.hasNext()){
|
while(data.hasNext()){
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.libre.agosto.p2play.ajax
|
package org.libre.agosto.p2play.ajax
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import org.libre.agosto.p2play.ManagerSingleton
|
import org.libre.agosto.p2play.ManagerSingleton
|
||||||
|
@ -13,22 +12,22 @@ open class Client {
|
||||||
|
|
||||||
|
|
||||||
protected fun _newCon(uri: String, method: String, token: String = ""): HttpURLConnection {
|
protected fun _newCon(uri: String, method: String, token: String = ""): HttpURLConnection {
|
||||||
var url = URL("https://"+ManagerSingleton.url+"/api/v1/"+uri)
|
val url = URL("https://${ManagerSingleton.url}/api/v1/$uri")
|
||||||
var con = url.openConnection() as HttpURLConnection
|
val con = url.openConnection() as HttpURLConnection
|
||||||
|
|
||||||
con.setRequestProperty("User-Agent", "P2play/0.1")
|
con.setRequestProperty("User-Agent", "P2play/0.1")
|
||||||
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
|
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
|
||||||
con.setRequestProperty("Accept", "*/*")
|
con.setRequestProperty("Accept", "*/*")
|
||||||
|
|
||||||
if(token != ""){
|
if(token != ""){
|
||||||
con.setRequestProperty("Authorization", "Bearer ${token}")
|
con.setRequestProperty("Authorization", "Bearer $token")
|
||||||
}
|
}
|
||||||
|
|
||||||
con.requestMethod=method
|
con.requestMethod=method
|
||||||
con.connectTimeout=10000
|
con.connectTimeout=10000
|
||||||
con.readTimeout=10000
|
con.readTimeout=10000
|
||||||
|
|
||||||
if(method.equals("POST"))
|
if(method == "POST")
|
||||||
con.doOutput=true
|
con.doOutput=true
|
||||||
|
|
||||||
Log.d("Petition", url.toString())
|
Log.d("Petition", url.toString())
|
||||||
|
@ -36,12 +35,12 @@ open class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getKeys():HostModel{
|
fun getKeys():HostModel{
|
||||||
var con=this._newCon("oauth-clients/local","GET")
|
val con = this._newCon("oauth-clients/local","GET")
|
||||||
var keys = HostModel("","")
|
val keys = HostModel("","")
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()) {
|
while (data.hasNext()) {
|
||||||
val key = data.nextName()
|
val key = data.nextName()
|
||||||
|
@ -58,12 +57,10 @@ open class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d("Key",keys.client_id)
|
|
||||||
return keys
|
|
||||||
} catch(err:Exception){
|
} catch(err:Exception){
|
||||||
Log.d("Error",err.message)
|
err.printStackTrace()
|
||||||
return keys
|
|
||||||
}
|
}
|
||||||
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.io.InputStreamReader
|
||||||
class Comments: Client() {
|
class Comments: Client() {
|
||||||
|
|
||||||
fun parseCommentaries(data: JsonReader): ArrayList<CommentaryModel> {
|
fun parseCommentaries(data: JsonReader): ArrayList<CommentaryModel> {
|
||||||
var commentaries = arrayListOf<CommentaryModel>()
|
val commentaries = arrayListOf<CommentaryModel>()
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()){
|
||||||
when(data.nextName()) {
|
when(data.nextName()) {
|
||||||
|
@ -76,14 +76,12 @@ class Comments: Client() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
commentaries = parseCommentaries(data)
|
commentaries = parseCommentaries(data)
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch(err:Exception){
|
||||||
err?.printStackTrace()
|
err.printStackTrace()
|
||||||
Log.d("TypeErr",err?.message ,err.cause)
|
|
||||||
Log.d("Error","fallo la coneccion")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return commentaries
|
return commentaries
|
||||||
|
@ -91,7 +89,7 @@ class Comments: Client() {
|
||||||
|
|
||||||
fun makeCommentary(token: String, videoId: Int, text: String): Boolean {
|
fun makeCommentary(token: String, videoId: Int, text: String): Boolean {
|
||||||
val con = this._newCon("videos/$videoId/comment-threads", "POST", token)
|
val con = this._newCon("videos/$videoId/comment-threads", "POST", token)
|
||||||
val params:String= "text=$text"
|
val params = "text=$text"
|
||||||
con.outputStream.write(params.toByteArray())
|
con.outputStream.write(params.toByteArray())
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.libre.agosto.p2play.ajax
|
||||||
|
|
||||||
import android.util.JsonReader
|
import android.util.JsonReader
|
||||||
import android.util.JsonToken
|
import android.util.JsonToken
|
||||||
import android.util.Log
|
|
||||||
import org.libre.agosto.p2play.ManagerSingleton
|
import org.libre.agosto.p2play.ManagerSingleton
|
||||||
import org.libre.agosto.p2play.models.VideoModel
|
import org.libre.agosto.p2play.models.VideoModel
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
@ -10,7 +9,7 @@ import java.io.InputStreamReader
|
||||||
class Videos: Client() {
|
class Videos: Client() {
|
||||||
|
|
||||||
private fun parseVideos(data: JsonReader): ArrayList<VideoModel>{
|
private fun parseVideos(data: JsonReader): ArrayList<VideoModel>{
|
||||||
var videos = arrayListOf<VideoModel>()
|
val videos = arrayListOf<VideoModel>()
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()){
|
||||||
when(data.nextName()){
|
when(data.nextName()){
|
||||||
|
@ -98,16 +97,16 @@ class Videos: Client() {
|
||||||
var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw"
|
var params = "start=$start&count=$count&sort=$sort&nsfw=$nsfw"
|
||||||
if(filter != "")
|
if(filter != "")
|
||||||
params+="&filter=$filter"
|
params+="&filter=$filter"
|
||||||
var con=this._newCon("videos?$params","GET")
|
val con = this._newCon("videos?$params","GET")
|
||||||
var videos = arrayListOf<VideoModel>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch(err:Exception){
|
||||||
err?.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
@ -127,16 +126,16 @@ class Videos: Client() {
|
||||||
fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel>{
|
fun myVideos(token: String, start: Int = 0): ArrayList<VideoModel>{
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val params = "start=$start&count=$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>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch(err:Exception){
|
||||||
err?.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
@ -144,16 +143,16 @@ class Videos: Client() {
|
||||||
fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel>{
|
fun videoSubscriptions(token: String, start: Int = 0): ArrayList<VideoModel>{
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val params = "start=$start&count=$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>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch(err:Exception){
|
||||||
err?.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
@ -162,27 +161,27 @@ class Videos: Client() {
|
||||||
val count = ManagerSingleton.videos_count
|
val count = ManagerSingleton.videos_count
|
||||||
val nsfw = ManagerSingleton.nfsw
|
val nsfw = ManagerSingleton.nfsw
|
||||||
val params = "search=$text&start=$start&count=$count&nsfw=$nsfw"
|
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>()
|
var videos = arrayListOf<VideoModel>()
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
videos = parseVideos(data)
|
videos = parseVideos(data)
|
||||||
}
|
}
|
||||||
} catch(err:Exception){
|
} catch(err:Exception){
|
||||||
err?.printStackTrace()
|
err.printStackTrace()
|
||||||
}
|
}
|
||||||
return videos
|
return videos
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fullDescription(videoId: Int): String{
|
fun fullDescription(videoId: Int): String{
|
||||||
var con=this._newCon("videos/$videoId/description","GET")
|
val con = this._newCon("videos/$videoId/description","GET")
|
||||||
var description = ""
|
var description = ""
|
||||||
try {
|
try {
|
||||||
if (con.responseCode == 200) {
|
if (con.responseCode == 200) {
|
||||||
var response = InputStreamReader(con.inputStream)
|
val response = InputStreamReader(con.inputStream)
|
||||||
var data = JsonReader(response)
|
val data = JsonReader(response)
|
||||||
|
|
||||||
data.beginObject()
|
data.beginObject()
|
||||||
while (data.hasNext()){
|
while (data.hasNext()){
|
||||||
|
|
Loading…
Reference in New Issue