Skip to content
Merged
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
26 changes: 26 additions & 0 deletions Parse/src/main/java/com/parse/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -48,6 +50,7 @@ public static final class Builder {
private Context context;
private String applicationId;
private String clientKey;
private String server = "https://api.parse.com/1";
private boolean localDataStoreEnabled;
private List<ParseNetworkInterceptor> interceptors;

Expand Down Expand Up @@ -128,6 +131,20 @@ public Builder clientKey(String clientKey) {
return this;
}

/**
* Set the server URL to be used by Parse.
*
* This method is only required if you intend to use a different API server than the one at
* api.parse.com.
*
* @param server The server URL to set.
* @return The same builder, for easy chaining.
*/
public Builder server(String server) {
this.server = server;
return this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind updating the tests to cover this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/**
* Add a {@link ParseNetworkInterceptor}.
*
Expand Down Expand Up @@ -182,13 +199,15 @@ public Configuration build() {
/* package for tests */ final Context context;
/* package for tests */ final String applicationId;
/* package for tests */ final String clientKey;
/* package for tests */ final String server;
/* package for tests */ final boolean localDataStoreEnabled;
/* package for tests */ final List<ParseNetworkInterceptor> interceptors;

private Configuration(Builder builder) {
this.context = builder.context;
this.applicationId = builder.applicationId;
this.clientKey = builder.clientKey;
this.server = builder.server;
this.localDataStoreEnabled = builder.localDataStoreEnabled;
this.interceptors = builder.interceptors != null ?
Collections.unmodifiableList(new ArrayList<>(builder.interceptors)) :
Expand Down Expand Up @@ -356,6 +375,13 @@ public static void initialize(Configuration configuration) {
isLocalDatastoreEnabled = configuration.localDataStoreEnabled;

ParsePlugins.Android.initialize(configuration.context, configuration.applicationId, configuration.clientKey);

try {
ParseRESTCommand.server = new URL(configuration.server);
} catch (MalformedURLException ex) {
throw new RuntimeException(ex);
}

Context applicationContext = configuration.context.getApplicationContext();

ParseHttpClient.setKeepAlive(true);
Expand Down
1 change: 0 additions & 1 deletion Parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
* existing data to retrieve.
*/
public class ParseObject {
/* package */ static String server = "https://api.parse.com";
private static final String AUTO_CLASS_NAME = "_Automatic";
/* package */ static final String VERSION_NAME = "1.12.1-SNAPSHOT";

Expand Down
15 changes: 14 additions & 1 deletion Parse/src/main/java/com/parse/ParseRESTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -44,6 +46,9 @@
private static final String HEADER_MASTER_KEY = "X-Parse-Master-Key";
private static final String PARAMETER_METHOD_OVERRIDE = "_method";

// Set via Parse.initialize(Configuration)
/* package */ static URL server = null;

private static LocalIdManager getLocalIdManager() {
return ParseCorePlugins.getInstance().getLocalIdManager();
}
Expand Down Expand Up @@ -189,7 +194,15 @@ public static ParseRESTCommand fromJSONObject(JSONObject jsonObject) {
private static String createUrl(String httpPath) {
// We send all parameters for GET/HEAD/DELETE requests in a post body,
// so no need to worry about query parameters here.
return String.format("%s/1/%s", ParseObject.server, httpPath);
if (httpPath == null) {
return server.toString();
}

try {
return new URL(server, httpPath).toString();
} catch (MalformedURLException ex) {
throw new RuntimeException(ex);
}
}

protected void addAdditionalHeaders(ParseHttpRequest.Builder requestBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -63,7 +65,7 @@ public static List<Task<JSONObject>> executeBatch(
for (ParseRESTObjectCommand command : commands) {
JSONObject requestParameters = new JSONObject();
requestParameters.put("method", command.method.toString());
requestParameters.put("path", String.format("/1/%s", command.httpPath));
requestParameters.put("path", new URL(server, command.httpPath).getPath());
JSONObject body = command.jsonParameters;
if (body != null) {
requestParameters.put("body", body);
Expand All @@ -73,6 +75,8 @@ public static List<Task<JSONObject>> executeBatch(
parameters.put("requests", requests);
} catch (JSONException e) {
throw new RuntimeException(e);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}

ParseRESTCommand command = new ParseRESTObjectBatchCommand(
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/NetworkObjectControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import java.io.ByteArrayInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,6 +40,16 @@
@Config(constants = BuildConfig.class, sdk = 21)
public class NetworkObjectControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

//region testFetchAsync

@Test
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/NetworkQueryControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import bolts.Task;
Expand All @@ -23,6 +27,16 @@

public class NetworkQueryControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

//region testConvertFindResponse

@Test
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/NetworkSessionControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

import static org.junit.Assert.assertEquals;
Expand All @@ -26,6 +30,16 @@
@Config(constants = BuildConfig.class, sdk = 21)
public class NetworkSessionControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

//region testGetSessionAsync

@Test
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/NetworkUserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -27,6 +31,16 @@
@Config(constants = BuildConfig.class, sdk = 21)
public class NetworkUserControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

//region testSignUpAsync

@Test
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/ParseAnalyticsControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
package com.parse;

import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -35,6 +39,16 @@
@Config(constants = BuildConfig.class, sdk = 21)
public class ParseAnalyticsControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

//region testConstructor

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public void testBuilder() {
Parse.Configuration.Builder builder = new Parse.Configuration.Builder(null);
builder.applicationId("foo");
builder.clientKey("bar");
builder.server("some.server");
builder.enableLocalDataStore();
Parse.Configuration configuration = builder.build();

assertNull(configuration.context);
assertEquals(configuration.applicationId, "foo");
assertEquals(configuration.clientKey, "bar");
assertEquals(configuration.server, "some.server");
assertEquals(configuration.localDataStoreEnabled, true);
}

Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/ParseCloudCodeControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;

Expand All @@ -36,6 +40,16 @@

public class ParseCloudCodeControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

//region testConstructor

@Test
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/ParseConfigControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
import com.parse.http.ParseHttpResponse;

import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -42,6 +46,16 @@

public class ParseConfigControllerTest {

@Before
public void setUp() throws MalformedURLException {
ParseRESTCommand.server = new URL("https://api.parse.com/1");
}

@After
public void tearDown() {
ParseRESTCommand.server = null;
}

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

Expand Down
Loading