You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
831 B
26 lines
831 B
package dev.garrettmills.starship.hyperlink.util;
|
|
|
|
import dev.garrettmills.starship.hyperlink.Hyperlink;
|
|
|
|
public class APIv1 {
|
|
/**
|
|
* Given an API endpoint, resolve the fully qualified URL using the stored server address.
|
|
* Example:
|
|
* resolveEndpoint("/auth/redeem") // => "https://hyperlink.url/api/v1/auth/redeem"
|
|
* @param endpoint un-qualified api endpoint
|
|
* @return The resolved string.
|
|
*/
|
|
public static String resolveEndpoint(String endpoint) {
|
|
if ( !endpoint.startsWith("/") ) {
|
|
endpoint = "/" + endpoint;
|
|
}
|
|
|
|
String server = Hyperlink.preferences.getString(Hyperlink.SERVER_ADDR, "");
|
|
if ( server.endsWith("/") ) {
|
|
server = server.substring(0, server.length() - 1);
|
|
}
|
|
|
|
return server + "/api/v1" + endpoint;
|
|
}
|
|
}
|