improve javadocs, also, no need to make implementations public

This commit is contained in:
Kermina Awad 2020-06-10 00:05:22 -04:00
parent b4a4519876
commit 707eae92a8
8 changed files with 63 additions and 25 deletions

View File

@ -8,13 +8,13 @@ import java.io.IOException;
import java.util.Map;
/**
* An {@link URLShortener} using {@code bit.ly}.
* A {@link URLShortener} using {@code bit.ly}. Requires an access token.
*/
class BitlyURLShortener extends URLShortener {
private static final String ACCESS_TOKEN = "Bearer bitly-access-token";
private static final String BITLY_POST_REQUEST = "https://api-ssl.bitly.com/v4/shorten";
public BitlyURLShortener() {
BitlyURLShortener() {
super(BITLY_POST_REQUEST, ACCESS_TOKEN);
if (ACCESS_TOKEN.endsWith("access-token")) throw new UnsupportedOperationException();
}

View File

@ -8,18 +8,24 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class GitHubPasteService extends PasteService {
/**
* Pastes to {@code gist.github.com}. Requires an access token with the {@code gist} scope.
*/
class GitHubPasteService extends PasteService {
private final boolean isPrivate;
// this access token must have the "gist" OAuth scope
// this access token must have the "gist" scope
private static final String ACCESS_TOKEN = "token github-access-token";
private static final String GITHUB_POST_REQUEST = "https://api.github.com/gists";
public GitHubPasteService(boolean isPrivate) {
GitHubPasteService(boolean isPrivate) {
super(GITHUB_POST_REQUEST, ACCESS_TOKEN);
this.isPrivate = isPrivate;
if (ACCESS_TOKEN.endsWith("access-token")) throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*/
@Override
String encodeData(String data) {
Map<String, String> mapData = new HashMap<String, String>();
@ -27,6 +33,9 @@ public class GitHubPasteService extends PasteService {
return this.encodeData(mapData);
}
/**
* {@inheritDoc}
*/
@Override
String encodeData(Map<String, String> files) {
JSONObject root = new JSONObject();
@ -43,6 +52,9 @@ public class GitHubPasteService extends PasteService {
return root.toJSONString();
}
/**
* {@inheritDoc}
*/
@Override
public String postData(String data) throws PasteFailedException {
try {
@ -53,6 +65,9 @@ public class GitHubPasteService extends PasteService {
}
}
/**
* {@inheritDoc}
*/
@Override
public String postData(Map<String, String> data) throws PasteFailedException {
try {
@ -63,6 +78,9 @@ public class GitHubPasteService extends PasteService {
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean supportsMultiFile() {
return true;

View File

@ -13,7 +13,7 @@ import java.util.Map;
class HastebinPasteService extends PasteService {
private static final String HASTEBIN_POST_REQUEST = "https://hastebin.com/documents";
public HastebinPasteService() {
HastebinPasteService() {
super(HASTEBIN_POST_REQUEST, null);
}
@ -33,6 +33,9 @@ class HastebinPasteService extends PasteService {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*/
@Override
public String postData(String data) throws PasteFailedException {
try {
@ -43,6 +46,9 @@ class HastebinPasteService extends PasteService {
}
}
/**
* {@inheritDoc}
*/
@Override
public String postData(Map<String, String> data) throws PasteFailedException {
try {
@ -53,6 +59,9 @@ class HastebinPasteService extends PasteService {
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean supportsMultiFile() {
return false;

View File

@ -12,7 +12,7 @@ import java.util.Map;
/**
* HTTP API-client.
*/
public abstract class HttpAPIClient {
abstract class HttpAPIClient {
/**
* The URL for this API-request, and if necessary, the access token.
* If an access token is not necessary, it should be set to null.
@ -29,11 +29,16 @@ public abstract class HttpAPIClient {
URLENCODED
}
public HttpAPIClient(String url, String accessToken) {
HttpAPIClient(String url, String accessToken) {
this.url = url;
this.accessToken = accessToken;
}
/**
* Returns the HTTP Content-Type header that corresponds with each ContentType.
* @param type The type of data.
* @return The HTTP Content-Type header that corresponds with the type of data.
*/
private String getContentHeader(ContentType type) {
switch (type) {
case JSON:

View File

@ -1,7 +1,7 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
/**
* Thrown when pasting failed.
* Thrown when pasting fails.
*/
public class PasteFailedException extends Exception {
public PasteFailedException() {

View File

@ -3,27 +3,25 @@ package com.onarandombox.MultiverseCore.utils.webpaste;
import java.util.Map;
/**
* An interface to a web-based text-pasting service. Classes implementing this
* interface should implement its methods to send data to an online text-sharing
* service, such as pastebin.com. Conventionally, a paste is accomplished by (given
* some PasteService instance ps):
* An interface to a web-based text-pasting service. Classes extending this
* should implement its methods to send data to an online text-sharing service,
* such as pastebin.com. Given some PasteService instance ps, a paste is accomplished by:
*
* {@code ps.postData(ps.encodeData(someString), ps.getPostURL());}
* {@code ps.postData(someString);}
*
* Services that provide a distinction between "public" and "private" pastes
* should implement a custom constructor that specifies which kind the PasteService
* should implement a constructor that specifies which kind the PasteService
* instance is submitting; an example of this is the PastebinPasteService class.
*/
public abstract class PasteService extends HttpAPIClient {
public PasteService(String url, String accessToken) {
PasteService(String url, String accessToken) {
super(url, accessToken);
}
/**
* Post data to the Web.
*
* @param data A URL-encoded String containing the full request to post to
* the given URL. Can be the result of calling #encodeData().
* @param data A String to post to the web.
* @throws PasteFailedException When pasting/posting the data failed.
* @return The URL at which the new paste is visible.
*/
@ -32,8 +30,7 @@ public abstract class PasteService extends HttpAPIClient {
/**
* Post data to the Web.
*
* @param data A URL-encoded Map containing the full request to post to
* the given URL. Can be the result of calling #encodeData().
* @param data A Map to post to the web.
* @throws PasteFailedException When pasting/posting the data failed.
* @return The URL at which the new paste is visible.
*/
@ -42,8 +39,8 @@ public abstract class PasteService extends HttpAPIClient {
/**
* Does this service support uploading multiple files.
*
* Newer services like gist support multi-file which allows us to upload configs
* in addition to the standard logs.
* Newer services like GitHub's Gist support multi-file pastes,
* which allows us to upload configs in addition to the standard logs.
*
* @return True if this service supports multiple file upload.
*/

View File

@ -12,7 +12,7 @@ class PastebinPasteService extends PasteService {
private final boolean isPrivate;
private static final String PASTEBIN_POST_REQUEST = "https://pastebin.com/api/api_post.php";
public PastebinPasteService(boolean isPrivate) {
PastebinPasteService(boolean isPrivate) {
super(PASTEBIN_POST_REQUEST, null);
this.isPrivate = isPrivate;
}
@ -66,6 +66,9 @@ class PastebinPasteService extends PasteService {
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean supportsMultiFile() {
return false;

View File

@ -1,10 +1,16 @@
package com.onarandombox.MultiverseCore.utils.webpaste;
/**
* URL-Shortener.
* An interface to a web-based URL Shortener. Classes extending this should
* implement its methods to shorten links using the service. Given some
* URLShortener instance us, a URL is shortened by:
*
* {@code us.shorten(longUrl);}
*
* An example of this, is the BitlyURLShortener.
*/
public abstract class URLShortener extends HttpAPIClient {
public URLShortener(String url, String accessToken) {
URLShortener(String url, String accessToken) {
super(url, accessToken);
}