Make Client and RpcClient constructors public

This commit is contained in:
netkas 2024-10-24 14:16:29 -04:00
parent 1d0cd21965
commit 23ac46eee8
2 changed files with 59 additions and 7 deletions

View file

@ -17,7 +17,9 @@ import java.util.Map;
public class Client extends RpcClient
{
protected Client(String domain) throws ResolutionException, CryptographyException
public Client(String domain) throws ResolutionException, CryptographyException
{
super(domain);
}

View file

@ -22,8 +22,6 @@ import java.util.Map;
public class RpcClient
{
private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private final static String CLIENT_NAME = "SocialClient Java";
private final static String CLIENT_VERSION = "1.0";
private final static MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
private final String domain;
@ -31,6 +29,9 @@ public class RpcClient
private final PublicKey serverPublicKey;
private final OkHttpClient httpClient;
private String clientName = "SocialClient Java";
private String clientVersion = "1.0.0";
protected String sessionUuid;
protected PrivateKey privateKey;
@ -42,7 +43,7 @@ public class RpcClient
* @throws ResolutionException If the domain cannot be resolved or if required information is missing.
* @throws CryptographyException If an error occurs while importing the public key.
*/
protected RpcClient(String domain) throws ResolutionException, CryptographyException
public RpcClient(String domain) throws ResolutionException, CryptographyException
{
this.domain = domain;
this.httpClient = new OkHttpClient();
@ -137,6 +138,56 @@ public class RpcClient
this.privateKey = privateKey;
}
/**
* Retrieves the client name associated with this RpcClient instance.
*
* @return the client name as a string.
*/
public String getClientName()
{
return clientName;
}
/**
* Sets the name of the client.
*
* @param clientName The name to be set for the client.
* @throws NullPointerException if the provided*/
public void setClientName(String clientName)
{
if(clientName == null)
{
throw new NullPointerException("Client name cannot be null");
}
this.clientName = clientName;
}
/**
* Returns the client's version.
*
* @return the client version as a string.
*/
public String getClientVersion()
{
return clientVersion;
}
/**
* Sets the client version for the RpcClient instance.
*
* @param clientVersion The version of the client software to be set.
* @throws NullPointerException if the provided clientVersion*/
public void setClientVersion(String clientVersion)
{
if(clientVersion == null)
{
throw new NullPointerException("Client version cannot be null");
}
this.clientVersion = clientVersion;
}
/**
* Clears the current session by setting the sessionUuid and privateKey fields to null.
* This method effectively logs out the user from the current session.
@ -161,8 +212,8 @@ public class RpcClient
{{
this.url(endpoint);
this.post(RequestBody.create(MEDIA_TYPE_JSON, jsonData));
this.addHeader("Client-Name", CLIENT_NAME);
this.addHeader("Client-Version", CLIENT_VERSION);
this.addHeader("Client-Name", clientName);
this.addHeader("Client-Version", clientVersion);
if(sessionUuid != null)
{
@ -268,7 +319,6 @@ public class RpcClient
return sendRequest(encode(requests));
}
/**
* Decodes a JSON string into a corresponding Java object. If the JSON string
* represents an object, it decodes it into a Map. If the JSON string represents