Skip to content

Commit

Permalink
Added ServerUrls.buildEndpoint helper method to build new endpoints u…
Browse files Browse the repository at this point in the history
…sing the configured key server and protocol
  • Loading branch information
OrangeAndGreen committed Dec 4, 2024
1 parent a8bcc43 commit 445ec10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 1 addition & 8 deletions app/src/org/commcare/connect/network/ApiConnectId.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,7 @@ public static AuthInfo.TokenAuth retrieveHqTokenApi(Context context, String hqUs
params.put("username", hqUsername + "@" + HiddenPreferences.getUserDomain());
params.put("password", connectToken);

String host;
try {
host = (new URL(ServerUrls.getKeyServer())).getHost();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}

String url = "https://" + host + "/oauth/token/";
String url = ServerUrls.buildEndpoint("oauth/token/");

ConnectNetworkHelper.PostResult postResult = ConnectNetworkHelper.postSync(context, url,
API_VERSION_NONE, new AuthInfo.NoAuth(), params, true, false);
Expand Down
12 changes: 12 additions & 0 deletions app/src/org/commcare/preferences/ServerUrls.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.commcare.CommCareApplication;
import org.commcare.dalvik.R;

import java.net.MalformedURLException;
import java.net.URL;

/**
* Created by amstone326 on 11/14/17.
*/
Expand All @@ -31,6 +34,15 @@ public static String getDataServerKey() {
.getString(R.string.ota_restore_url)) ;
}

public static String buildEndpoint(String path) {
try {
URL originalUrl = new URL(getKeyServer());
return new URL(originalUrl, path).toString();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

public static String getKeyServer() {
return CommCareApplication.instance().getCurrentApp().getAppPreferences()
.getString(PREFS_KEY_SERVER_KEY, null);
Expand Down

0 comments on commit 445ec10

Please sign in to comment.