mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-03-01 09:49:41 -05:00
Compare commits
2 Commits
develop-1.
...
1.5.0-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48d1138754 | ||
|
|
a5320db820 |
@@ -1,22 +1,15 @@
|
|||||||
package io.github.jwdeveloper.tiktok.common;
|
package io.github.jwdeveloper.tiktok.common;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import io.github.jwdeveloper.tiktok.http.mappers.*;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.net.http.*;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ActionResult<T> {
|
public class ActionResult<T> {
|
||||||
|
|
||||||
private static final Gson gson = new Gson().newBuilder().disableHtmlEscaping()
|
|
||||||
.registerTypeHierarchyAdapter(HttpResponse.class, new HttpResponseJsonMapper())
|
|
||||||
.registerTypeHierarchyAdapter(HttpRequest.class, new HttpRequestJsonMapper())
|
|
||||||
.setPrettyPrinting().create();
|
|
||||||
|
|
||||||
private boolean success = true;
|
private boolean success = true;
|
||||||
private T content;
|
private T content;
|
||||||
private String message;
|
private String message;
|
||||||
@@ -100,7 +93,7 @@ public class ActionResult<T> {
|
|||||||
public JsonObject toJson() {
|
public JsonObject toJson() {
|
||||||
JsonObject map = new JsonObject();
|
JsonObject map = new JsonObject();
|
||||||
map.addProperty("success", success);
|
map.addProperty("success", success);
|
||||||
map.add("content", gson.toJsonTree(content));
|
map.add("content", new Gson().toJsonTree(content));
|
||||||
map.addProperty("message", message);
|
map.addProperty("message", message);
|
||||||
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
||||||
return map;
|
return map;
|
||||||
@@ -108,6 +101,6 @@ public class ActionResult<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ActionResult: "+gson.toJson(toJson());
|
return "ActionResult: "+new Gson().newBuilder().setPrettyPrinting().create().toJson(toJson());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.net.http.HttpRequest;
|
|
||||||
|
|
||||||
public class HttpRequestJsonMapper implements JsonSerializer<HttpRequest>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public JsonElement serialize(HttpRequest src, Type typeOfSrc, JsonSerializationContext context) {
|
|
||||||
JsonObject object = new JsonObject();
|
|
||||||
object.addProperty("method", src.method());
|
|
||||||
object.add("timeout", context.serialize(src.timeout().toString()));
|
|
||||||
object.addProperty("expectContinue", src.expectContinue());
|
|
||||||
object.add("uri", context.serialize(src.uri()));
|
|
||||||
object.add("version", context.serialize(src.version().toString()));
|
|
||||||
object.add("headers", context.serialize(src.headers().map()));
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.net.http.HttpResponse;
|
|
||||||
|
|
||||||
public class HttpResponseJsonMapper implements JsonSerializer<HttpResponse>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public JsonElement serialize(HttpResponse src, Type typeOfSrc, JsonSerializationContext context) {
|
|
||||||
JsonObject object = new JsonObject();
|
|
||||||
object.addProperty("statusCode", src.statusCode());
|
|
||||||
object.add("request", context.serialize(src.request()));
|
|
||||||
object.add("headers", context.serialize(src.headers().map()));
|
|
||||||
object.add("body", context.serialize(src.body()));
|
|
||||||
object.add("uri", context.serialize(src.uri().toString()));
|
|
||||||
object.add("version", context.serialize(src.version().toString()));
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -65,7 +65,7 @@ public class LiveUserDataMapper
|
|||||||
};
|
};
|
||||||
|
|
||||||
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
return new LiveUserData.Response(json, statusEnum, roomId, startTime);
|
||||||
} catch (JsonSyntaxException | IllegalStateException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
logger.warning("Malformed Json: '"+json+"' - Error Message: "+e.getMessage());
|
||||||
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
return new LiveUserData.Response(json, LiveUserData.UserStatus.NotFound, "", -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ Maven
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
<version>1.4.0-Release</version>
|
<version>1.5.0-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -87,7 +87,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.1.0-Release'
|
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.5.0-Release'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user