-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
104 additions
and
54 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/ai/reveng/toolkit/ghidra/core/services/api/APIError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ai.reveng.toolkit.ghidra.core.services.api; | ||
|
||
import org.json.JSONObject; | ||
|
||
public record APIError( | ||
String code, | ||
String message | ||
) { | ||
public static APIError fromJSONObject(JSONObject json) { | ||
return new APIError( | ||
json.getString("code"), | ||
json.getString("message") | ||
); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/ai/reveng/toolkit/ghidra/core/services/api/APIVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ai.reveng.toolkit.ghidra.core.services.api; | ||
|
||
public enum APIVersion { | ||
V1, | ||
V2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/ai/reveng/toolkit/ghidra/core/services/api/V2Response.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ai.reveng.toolkit.ghidra.core.services.api; | ||
|
||
|
||
import org.json.JSONObject; | ||
|
||
import java.util.List; | ||
|
||
import static ai.reveng.toolkit.ghidra.core.services.api.Utils.mapJSONArray; | ||
|
||
/** | ||
* Structured Response from any V2 Endpoint | ||
* { | ||
* "status": true, | ||
* "data": { | ||
* "queued": true, | ||
* "reference": "404f60e6-7b1d-4adf-951c-710925422bd8" | ||
* }, | ||
* "message": null, | ||
* "errors": null, | ||
* "meta": { | ||
* "pagination": null | ||
* } | ||
* } | ||
* | ||
*/ | ||
public record V2Response( | ||
boolean status, | ||
JSONObject data, | ||
String message, | ||
List<APIError> errors, | ||
JSONObject meta | ||
|
||
) { | ||
|
||
|
||
public static V2Response fromJSONObject(JSONObject json) { | ||
return new V2Response( | ||
json.getBoolean("status"), | ||
!json.isNull("data") ? json.getJSONObject("data") : null, | ||
!json.isNull("message") ? json.getString("message") : null, | ||
!json.isNull("errors") ? mapJSONArray(json.getJSONArray("errors"), APIError::fromJSONObject) : null, | ||
json.getJSONObject("meta") | ||
); | ||
} | ||
} |