Adapted new API System with search API call
Implemented raw Pagination support to Replay Center Fixed awkward time jumps caused by MCTimerHandler Fixed Java 1.6 incompatibility with List.sort Method in GuiSpectateSelection Fixed a LOT of compatibility issues with the Shader Mod
This commit is contained in:
@@ -18,6 +18,7 @@ import com.google.gson.JsonParser;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.ApiError;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.AuthKey;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.SearchResult;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.Success;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.UserFiles;
|
||||
import eu.crushedpixel.replaymod.utils.StreamTools;
|
||||
@@ -54,21 +55,19 @@ public class ApiClient {
|
||||
QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files);
|
||||
builder.put("auth", auth);
|
||||
builder.put("ids", buildListString(ids));
|
||||
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works
|
||||
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class);
|
||||
return info;
|
||||
}
|
||||
|
||||
public FileInfo[] getRecentFiles() throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files);
|
||||
builder.put("recent", true);
|
||||
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works
|
||||
return info;
|
||||
}
|
||||
|
||||
public FileInfo[] getBestFiles() throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ApiMethods.replay_files);
|
||||
builder.put("best", true);
|
||||
FileInfo[] info = invokeAndReturn(builder, FileInfo[].class); //TODO: Test if that works
|
||||
public FileInfo[] searchFiles(SearchQuery query) throws IOException, ApiException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// build base url
|
||||
sb.append(QueryBuilder.API_BASE_URL);
|
||||
sb.append("search");
|
||||
sb.append(query.buildQuery());
|
||||
|
||||
FileInfo[] info = invokeAndReturn(sb.toString(), SearchResult.class).getResults();
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -116,8 +115,12 @@ public class ApiClient {
|
||||
invokeAndReturn(builder, Success.class);
|
||||
}
|
||||
|
||||
private <T> T invokeAndReturn(QueryBuilder builder,Class<T> classOfT) throws IOException, ApiException {
|
||||
JsonElement ele = GsonApiClient.invoke(builder);
|
||||
private <T> T invokeAndReturn(QueryBuilder builder, Class<T> classOfT) throws IOException, ApiException {
|
||||
return invokeAndReturn(builder.toString(), classOfT);
|
||||
}
|
||||
|
||||
private <T> T invokeAndReturn(String url, Class<T> classOfT) throws IOException, ApiException {
|
||||
JsonElement ele = GsonApiClient.invokeJson(url);
|
||||
return gson.fromJson(ele, classOfT);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class FileUploader {
|
||||
uploading = true;
|
||||
|
||||
String postData = "?auth="+auth+"&category="+category.getId();
|
||||
|
||||
|
||||
if(tags.size() > 0) {
|
||||
postData += "&tags=";
|
||||
for(String tag : tags) {
|
||||
@@ -58,7 +58,7 @@ public class FileUploader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
postData +="&name="+URLEncoder.encode(filename, "UTF-8");
|
||||
System.out.println(postData);
|
||||
|
||||
@@ -118,23 +118,28 @@ public class FileUploader {
|
||||
is = con.getErrorStream();
|
||||
}
|
||||
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
String info = null;
|
||||
if(responseCode != 200) {
|
||||
ApiError error = new ApiError(-1, "An unknown error occured");
|
||||
String json = "";
|
||||
while(r.ready()) {
|
||||
json += r.readLine();
|
||||
|
||||
if(is != null) {
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
||||
info = null;
|
||||
if(responseCode != 200) {
|
||||
ApiError error = new ApiError(-1, "An unknown error occured");
|
||||
String json = "";
|
||||
while(r.ready()) {
|
||||
json += r.readLine();
|
||||
}
|
||||
error = gson.fromJson(json, ApiError.class);
|
||||
info = error.getDesc();
|
||||
System.out.println(info);
|
||||
}
|
||||
System.out.println(json);
|
||||
error = gson.fromJson(json, ApiError.class);
|
||||
info = error.getDesc();
|
||||
System.out.println(info);
|
||||
}
|
||||
|
||||
|
||||
con.disconnect();
|
||||
|
||||
if(info == null) info = "An unknown error occured";
|
||||
|
||||
parent.onFinishUploading(success, info);
|
||||
|
||||
uploading = false;
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Map;
|
||||
|
||||
public class QueryBuilder {
|
||||
|
||||
private static final String API_BASE_URL = "http://ReplayMod.com/api/";
|
||||
public static final String API_BASE_URL = "http://ReplayMod.com/api/";
|
||||
|
||||
public String apiMethod;
|
||||
public Map<String,String> paramMap;
|
||||
|
||||
@@ -13,6 +13,21 @@ public class FileInfo {
|
||||
private int downloads;
|
||||
private String name;
|
||||
private boolean thumbnail;
|
||||
|
||||
|
||||
public FileInfo(int id, ReplayMetaData metadata, String owner,
|
||||
Rating ratings, int size, int category, int downloads, String name,
|
||||
boolean thumbnail) {
|
||||
this.id = id;
|
||||
this.metadata = metadata;
|
||||
this.owner = owner;
|
||||
this.ratings = ratings;
|
||||
this.size = size;
|
||||
this.category = category;
|
||||
this.downloads = downloads;
|
||||
this.name = name;
|
||||
this.thumbnail = thumbnail;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@@ -38,6 +53,9 @@ public class FileInfo {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public boolean hasThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user