Skip to content

Add update server url #985

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

Merged
merged 2 commits into from
Nov 13, 2019
Merged
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
57 changes: 47 additions & 10 deletions parse/src/main/java/com/parse/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.util.Log;

import java.io.File;
Expand Down Expand Up @@ -191,10 +193,52 @@ public Void then(Task<Void> task) {
}
}

//region Server URL

/**
* Sets the server URL. This can be used to update the server URL after this client has been
* initialized, without having to {@link Parse#destroy()} this client.
* @param server The server URL to set.
*/
public static void setServer(@NonNull String server) {
try {
ParseRESTCommand.server = new URL(validateServerUrl(server));
} catch (MalformedURLException ex) {
throw new RuntimeException(ex);
}
}

/**
* Returns the current server URL.
*/
public static @Nullable String getServer() {
URL server = ParseRESTCommand.server;
return server == null ? null : server.toString();
}

/**
* Validates the server URL.
* @param server The server URL to validate.
* @return The validated server URL.
*/
private static @Nullable String validateServerUrl(@Nullable String server) {

// Add an extra trailing slash so that Parse REST commands include
// the path as part of the server URL (i.e. http://api.myhost.com/parse)
if (server != null && !server.endsWith("/")) {
server = server + "/";
}

return server;
}

//endregion

/**
* Destroys this client and erases its local data store.
* Calling this after {@code Parse.initialize} allows you to re-initialize this client
* with a new configuration.
* Calling this after {@link Parse#initialize} allows you to re-initialize this client with a
* new configuration. Calling this while server requests are in progress can cause undefined
* behavior.
*/
public static void destroy() {
ParseObject.unregisterParseSubclasses();
Expand Down Expand Up @@ -577,14 +621,7 @@ public Builder clientKey(String clientKey) {
* @return The same builder, for easy chaining.
*/
public Builder server(String server) {

// Add an extra trailing slash so that Parse REST commands include
// the path as part of the server URL (i.e. http://api.myhost.com/parse)
if (server != null && !server.endsWith("/")) {
server = server + "/";
}

this.server = server;
this.server = validateServerUrl(server);
return this;
}

Expand Down