Skip to content

Commit

Permalink
Fix URL concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLamoureux committed Jul 18, 2021
1 parent 669104b commit 856c03f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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

0 comments on commit 856c03f

Please sign in to comment.