mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-05 18:29:34 +01:00
Cleanup webpaste code (#2411)
This commit is contained in:
parent
d35363b10c
commit
75855826e7
@ -16,7 +16,9 @@ class BitlyURLShortener extends URLShortener {
|
||||
|
||||
BitlyURLShortener() {
|
||||
super(BITLY_POST_REQUEST, ACCESS_TOKEN);
|
||||
if (ACCESS_TOKEN.endsWith("access-token")) throw new UnsupportedOperationException();
|
||||
if (ACCESS_TOKEN.endsWith("access-token")) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,9 @@ class GitHubPasteService extends PasteService {
|
||||
GitHubPasteService(boolean isPrivate) {
|
||||
super(GITHUB_POST_REQUEST, ACCESS_TOKEN);
|
||||
this.isPrivate = isPrivate;
|
||||
if (ACCESS_TOKEN.endsWith("access-token")) throw new UnsupportedOperationException();
|
||||
if (ACCESS_TOKEN.endsWith("access-token")) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ class HastebinPasteService extends PasteService {
|
||||
private static final String HASTEBIN_POST_REQUEST = "https://hastebin.com/documents";
|
||||
|
||||
HastebinPasteService() {
|
||||
super(HASTEBIN_POST_REQUEST, null);
|
||||
super(HASTEBIN_POST_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,10 @@ abstract class HttpAPIClient {
|
||||
URLENCODED
|
||||
}
|
||||
|
||||
HttpAPIClient(String url) {
|
||||
this(url, null);
|
||||
}
|
||||
|
||||
HttpAPIClient(String url, String accessToken) {
|
||||
this.url = url;
|
||||
this.accessToken = accessToken;
|
||||
@ -48,7 +52,7 @@ abstract class HttpAPIClient {
|
||||
case URLENCODED:
|
||||
return "application/x-www-form-urlencoded; charset=utf-8";
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + type);
|
||||
throw new IllegalArgumentException("Unexpected value: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +95,9 @@ abstract class HttpAPIClient {
|
||||
// this isn't required, but is technically correct
|
||||
conn.addRequestProperty("Content-Type", getContentHeader(type));
|
||||
// only some API requests require an access token
|
||||
if (this.accessToken != null) conn.addRequestProperty("Authorization", this.accessToken);
|
||||
if (this.accessToken != null) {
|
||||
conn.addRequestProperty("Authorization", this.accessToken);
|
||||
}
|
||||
|
||||
wr = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8.newEncoder());
|
||||
wr.write(payload);
|
||||
@ -102,7 +108,10 @@ abstract class HttpAPIClient {
|
||||
// this has to be initialized AFTER the data has been flushed!
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
|
||||
while ((line = rd.readLine()) != null) responseString.append(line);
|
||||
while ((line = rd.readLine()) != null) {
|
||||
responseString.append(line);
|
||||
}
|
||||
|
||||
return responseString.toString();
|
||||
} finally {
|
||||
if (wr != null) {
|
||||
|
@ -17,7 +17,7 @@ class PasteGGPasteService extends PasteService {
|
||||
private static final String PASTEGG_POST_REQUEST = "https://api.paste.gg/v1/pastes";
|
||||
|
||||
PasteGGPasteService(boolean isPrivate) {
|
||||
super(PASTEGG_POST_REQUEST, null);
|
||||
super(PASTEGG_POST_REQUEST);
|
||||
this.isPrivate = isPrivate;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,10 @@ import java.util.Map;
|
||||
* instance is submitting; an example of this is the PastebinPasteService class.
|
||||
*/
|
||||
public abstract class PasteService extends HttpAPIClient {
|
||||
PasteService(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
PasteService(String url, String accessToken) {
|
||||
super(url, accessToken);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class PastebinPasteService extends PasteService {
|
||||
private static final String PASTEBIN_POST_REQUEST = "https://pastebin.com/api/api_post.php";
|
||||
|
||||
PastebinPasteService(boolean isPrivate) {
|
||||
super(PASTEBIN_POST_REQUEST, null);
|
||||
super(PASTEBIN_POST_REQUEST);
|
||||
this.isPrivate = isPrivate;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,10 @@ package com.onarandombox.MultiverseCore.utils.webpaste;
|
||||
* An example of this, is the BitlyURLShortener.
|
||||
*/
|
||||
public abstract class URLShortener extends HttpAPIClient {
|
||||
URLShortener(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
URLShortener(String url, String accessToken) {
|
||||
super(url, accessToken);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user