Compare commits

..

No commits in common. "master" and "1.2.1-e0f590b2bf" have entirely different histories.

4 changed files with 43 additions and 107 deletions

View File

@ -16,10 +16,5 @@
<option name="name" value="MavenRepo" /> <option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" /> <option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://git.nevets.tech/api/packages/5gi/maven" />
</remote-repository>
</component> </component>
</project> </project>

View File

@ -1,58 +1,24 @@
# DeepJ # DeepJ
[![Build Number](https://api.5servers.us/get/badges?uniqueid=deepj&get-type=version.badge)](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/) █▀█ █▀█ █ █▀▀ █ █▄ █ ▄▀█ █
[![Build Status](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/badge/icon)](https://ci.nevets.tech/view/Alec/job/DeepJ%20Improved/) █▄█ █▀▄ █ █▄█ █ █ ▀█ █▀█ █▄▄
> Quick Setup
<details><summary>Gradle</summary>
<p>
Go to your build.gradle file and type: █▄▄ █▄█
█▄█‎ ‎█
``` █▀‎ ▀█▀‎ █▀▀‎ █‎ █‎ █▀▀‎ █▄‎ █
repositories { ▄█ ██▄ ▀▄▀ ██▄ █ ▀█
maven {
url "https://git.nevets.tech/api/packages/5gi/maven"
}
}
```
and
``` ________________________________________
dependencies {
implementation group: 'com.the5gi.deepj', name: 'DeepJ', version: 'VERSION'
}
```
</p>
</details>
<details><summary>Maven</summary> █‎ ‎█ █▀█ █▀█ ▄▀█ ▀█▀ █▀▀ █▀█
<p> █▄█ █▀▀‎ █▄█ █▀█‎ █‎ ‎██▄ █▄█
Go to your pom.xml file and type: █▄▄ █▄█
█▄█
``` █▀ █▀▀ ▀█▀
<repositories> ▄█ █▄█ ▄█▄
<repository>
<id>gitea</id>
<url>https://git.nevets.tech/api/packages/5gi/maven</url>
</repository>
</repositories>
```
and
```
<dependencies>
<dependency>
<groupId>com.the5gi.deepj</groupId>
<artifactId>DeepJ</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
```
</p>
</details>
> Info
[To see more details, see the wiki](https://git.nevets.tech/5gi/DeepJ/wiki/Home#user-content-usage-setup).
________________________________________ ________________________________________
DeepJ is a Java Wrapper for the DeepL Free Public API. This was originally made by Steven (Forked From) and Updated by 5gi DeepJ is a Java Wrapper for the DeepL Free Public API. This was originally made by Steven (Forked From) and Updated by 5gi

View File

@ -5,15 +5,12 @@ plugins {
} }
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
group 'com.the5gi.deepj' group 'com.the5gi.deepj'
version '1.3.7' version '1.2.1'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11 sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url "https://git.nevets.tech/api/packages/5gi/maven"
}
} }
dependencies { dependencies {
@ -23,20 +20,19 @@ dependencies {
publishing { publishing {
publications{ publications{
publish(MavenPublication) { publish(MavenPublication) {
artifact("nexus/DeepJ-$version" + ".jar") { artifact("target/DeepJ-$version" + "-all.jar") {
extension 'jar' extension 'jar'
} }
} }
} }
repositories { repositories {
maven { maven {
name 'gitea' name 'nexus'
url "https://git.nevets.tech/api/packages/5gi/maven/" url "https://repo.nevets.tech/repository/maven-releases/"
credentials.username System.getenv('fivegiUserGit') credentials {
credentials.password System.getenv('fivegiPassGit') username System.getenv('nexusUser')
password System.getenv('nexusPass')
}
} }
} }
} }
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

View File

@ -10,61 +10,39 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
public class Translator { public class Translator {
public static String globalAuthKey = "null"; public static String globalAuthKey = "null";
protected Request request;
public static void setGlobalAuthKey(String key) {
globalAuthKey = key;
}
private Request request;
public Translator() { public Translator() {
if (globalAuthKey == null) { if (globalAuthKey == null) {
System.out.println("\n[DeepJ] You are currently using the Global Auth Key Translator Constructor." +"\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n"); System.out.println("\n[DeepJ] You are currently using the Global Auth Key Translator Constructor." +
"\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." +
"\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
} else { } else {
request = new Request(globalAuthKey); request = new Request(globalAuthKey);
} }
} }
public Translator(String authKey) { public Translator(String authKey) {
if (!Objects.equals(globalAuthKey, "null")) { if (!Objects.equals(globalAuthKey, "null")) {
System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)"); System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" +
"\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)");
} }
request = new Request(authKey); request = new Request(authKey);
} }
public Translator(String authKey, boolean silence) { public Translator(String authKey, boolean silence) {
if (!Objects.equals(globalAuthKey, "null") && !silence) { if (!Objects.equals(globalAuthKey, "null") && !silence) {
System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)"); System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" +
"\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)");
} }
request = new Request(authKey); request = new Request(authKey);
} }
public static void setGlobalAuthKey(String key) {
globalAuthKey = key;
}
public static Translator newTranslator(String authKey) {
return new Translator(authKey);
}
public static Translator newTranslator() {
if (globalAuthKey == null) {
System.out.println("\n[DeepJ] You are currently using the Global Auth Key \".of()\" Translator." +
"\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this method." +
"\n[DeepJ] If you want to define an different authkey every time do: \"Translator.of(String authKey)\"\n");
return new Translator("null");
} else {
return new Translator();
}
}
public void setAuthKey(String key) {
request.setAuthKey(key);
}
public void setAPIKey(String authKey) {
request = new Request(authKey);
}
public String getAPIKey() {
return request.authKey;
}
public void close() {
request = new Request("null");
}
public String translate(Language langToTranslateTo, String sourceMessage) { public String translate(Language langToTranslateTo, String sourceMessage) {
if (request.authKey == "null") {
System.out.println("[DeepJ] This translator is closed! Please re-create!");
return "null";
}
String response = "Error processing request"; String response = "Error processing request";
try { try {
response = request.queryAPI(langToTranslateTo, sourceMessage); response = request.queryAPI(langToTranslateTo, sourceMessage);
@ -82,22 +60,23 @@ public class Translator {
return message; return message;
} }
protected static class Request { protected static class Request {
public String authKey; private final String authKey;
public Request(String authKey) { public Request(String authKey) {
this.authKey = authKey; this.authKey = authKey;
} }
public void setAuthKey(String key) {
authKey = key;
}
public String queryAPI(Language langEnum, String message) throws IOException, InterruptedException { public String queryAPI(Language langEnum, String message) throws IOException, InterruptedException {
String encodedAuthKey = URLEncoder.encode(authKey, StandardCharsets.UTF_8); String encodedAuthKey = URLEncoder.encode(authKey, StandardCharsets.UTF_8);
String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8); String encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8);
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().GET().header("Accept","*/*").header("Content-Type", "application/x-www-form-urlencoded").uri(URI.create("https://api-free.deepl.com/v2/translate?auth_key="+encodedAuthKey+"&target_lang="+langEnum.getApiString()+"&text="+encodedMessage)).build(); HttpRequest request = HttpRequest.newBuilder().GET()
HttpResponse<String> response = client.send(request,HttpResponse.BodyHandlers.ofString()); .header("Accept","*/*")
.header("Content-Type", "application/x-www-form-urlencoded")
.uri(URI.create("https://api-free.deepl.com/v2/translate?auth_key=" + encodedAuthKey + "&target_lang=" + langEnum.getApiString() + "&text=" + encodedMessage)).build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
return response.body(); return response.body();
} }
} }
public enum Language { public enum Language {
Bulgarian("BG"), Bulgarian("BG"),
Czech("CS"), Czech("CS"),