Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ enum ContentType {
URLENCODED
}

HttpAPIClient(String url) {
this(url, null);
}

HttpAPIClient(String url, String accessToken) {
this.url = url;
this.accessToken = accessToken;
Expand All @@ -48,7 +52,7 @@ private String getContentHeader(ContentType type) {
case URLENCODED:
return "application/x-www-form-urlencoded; charset=utf-8";
default:
throw new IllegalStateException("Unexpected value: " + type);
throw new IllegalArgumentException("Unexpected value: " + type);
}
}

Expand Down Expand Up @@ -91,7 +95,9 @@ final String exec(String payload, ContentType type) throws IOException {
// 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);
Expand All @@ -102,7 +108,10 @@ final String exec(String payload, ContentType type) throws IOException {
// 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
* 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);
}
Expand Down