@@ -19,6 +19,20 @@ public class SPWorldsApi {
1919 private static final HttpClient httpClient = HttpClient .newHttpClient ();
2020 private static final String API_URL = "https://spworlds.ru/api/public/" ;
2121
22+ public static int getAuthStatus (String id , String token ) {
23+ try {
24+ HttpRequest request = HttpRequest .newBuilder ()
25+ .uri (URI .create (API_URL + "card" ))
26+ .header ("Authorization" , getAuthorizationHeader (id , token ))
27+ .timeout (Duration .ofSeconds (10 ))
28+ .build ();
29+ HttpResponse <String > response = httpClient .send (request , HttpResponse .BodyHandlers .ofString ());
30+ return response .statusCode ();
31+ } catch (Exception e ) {
32+ return -1 ;
33+ }
34+ }
35+
2236 public static int getBalance (Card card ) {
2337 try {
2438
@@ -101,10 +115,10 @@ public static JsonObject getOwnerInfo(Card card) {
101115 }
102116 }
103117
104- public static BaseCard [] getCards (String nick ){
118+ public static BaseCard [] getCards (String nick ) {
105119 try {
106120 HttpRequest request = HttpRequest .newBuilder ()
107- .uri (URI .create (API_URL + "accounts/" + nick + "/cards" ))
121+ .uri (URI .create (API_URL + "accounts/" + nick + "/cards" ))
108122 .header ("Authorization" , getAuthorizationHeader (SPmHelperConfig .get ().getMainCard ()))
109123 .build ();
110124
@@ -121,4 +135,11 @@ public static BaseCard[] getCards(String nick){
121135 private static String getAuthorizationHeader (Card card ) {
122136 return "Bearer " + card .getBase64Key ();
123137 }
138+
139+ private static String getAuthorizationHeader (String id , String token ) {
140+ Card card = new Card ();
141+ card .id = id ;
142+ card .token = token ;
143+ return "Bearer " + card .getBase64Key ();
144+ }
124145}
0 commit comments