Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL concatenation #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.3
## Fixed
* URL concatenation on the different versions of the JDK and upstream projects' dependencies

# 0.4.2
## Fixed
* GRANT_TYPE_TOKEN_REFRESH now has the correct value
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ and https://issues.apache.org/jira/browse/SUREFIRE-1588 -->

<groupId>com.patreon</groupId>
<artifactId>patreon</artifactId>
<version>0.4.2</version>
<version>0.4.3</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Interact with the Patreon API via OAuth</description>
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/patreon/resources/RequestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import static com.patreon.PatreonAPI.BASE_URI;
Expand All @@ -13,8 +14,7 @@
public class RequestUtil {

public InputStream request(String pathSuffix, String accessToken) throws IOException {
String prefix = BASE_URI + "/api/oauth2/api/";
URL url = new URL(prefix.concat(pathSuffix));
URL url = buildUrl(pathSuffix);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Bearer ".concat(accessToken));
connection.setRequestProperty("User-Agent",
Expand All @@ -26,6 +26,16 @@ public InputStream request(String pathSuffix, String accessToken) throws IOExcep
return connection.getInputStream();
}

private URL buildUrl(String pathSuffix) throws MalformedURLException {
if (pathSuffix.startsWith("/")) {
pathSuffix = pathSuffix.substring(1, pathSuffix.length());
}

String prefix = BASE_URI + "/api/oauth2/api/";
URL url = new URL(prefix.concat(pathSuffix));
return url;
}

private String getVersion() throws IOException {
InputStream resourceAsStream = this.getClass().getResourceAsStream("/version.properties");
java.util.Properties prop = new java.util.Properties();
Expand Down