@Override public Task<Void> requestPasswordResetAsync(String email) { ParseRESTCommand command = ParseRESTUserCommand.resetPasswordResetCommand(email); return command.executeAsync(client).makeVoid(); } }
Task<JSONObject> saveAsync( ParseHttpClient client, final ParseOperationSet operationSet, String sessionToken) { final ParseRESTCommand command = currentSaveEventuallyCommand(operationSet, PointerEncoder.get(), sessionToken); return command.executeAsync(client); }
@Override public Task<ParseUser.State> getUserAsync(String sessionToken) { ParseRESTCommand command = ParseRESTUserCommand.getCurrentUserCommand(sessionToken); return command.executeAsync(client).onSuccess(new Continuation<JSONObject, ParseUser.State>() { @Override public ParseUser.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); return coder.decode(new ParseUser.State.Builder(), result, ParseDecoder.get()) .isComplete(true) .build(); } }); }
public Task<Void> sendInBackground(ParsePush.State state, String sessionToken) { return buildRESTSendPushCommand(state, sessionToken).executeAsync(restClient).makeVoid(); }
public <T> Task<T> callFunctionInBackground(final String name, final Map<String, ?> params, String sessionToken) { ParseRESTCommand command = ParseRESTCloudCommand.callFunctionCommand( name, params, sessionToken); return command.executeAsync(restClient).onSuccess(new Continuation<JSONObject, T>() { @Override public T then(Task<JSONObject> task) { @SuppressWarnings("unchecked") T result = (T) convertCloudResponse(task.getResult()); return result; } }); }
@Override public Task<ParseUser.State> logInAsync( String username, String password) { ParseRESTCommand command = ParseRESTUserCommand.logInUserCommand( username, password, revocableSession); return command.executeAsync(client).onSuccess(new Continuation<JSONObject, ParseUser.State>() { @Override public ParseUser.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); return coder.decode(new ParseUser.State.Builder(), result, ParseDecoder.get()) .isComplete(true) .build(); } }); }
public Task<ParseConfig> getAsync(String sessionToken) { final ParseRESTCommand command = ParseRESTConfigCommand.fetchConfigCommand(sessionToken); return command.executeAsync(restClient).onSuccessTask(new Continuation<JSONObject, Task<ParseConfig>>() { @Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } }); } }
return command.executeAsync(restClient, ct).onSuccess(new Continuation<JSONObject, List<T>>() { @Override public List<T> then(Task<JSONObject> task) throws Exception {
"batch", ParseHttpRequest.Method.POST, parameters, sessionToken); command.executeAsync(client).continueWith(new Continuation<JSONObject, Void>() { @Override public Void then(Task<JSONObject> task) throws Exception {
@Override public Task<ParseUser.State> signUpAsync( final ParseObject.State state, ParseOperationSet operations, String sessionToken) { JSONObject objectJSON = coder.encode(state, operations, PointerEncoder.get()); ParseRESTCommand command = ParseRESTUserCommand.signUpUserCommand( objectJSON, sessionToken, revocableSession); return command.executeAsync(client).onSuccess(new Continuation<JSONObject, ParseUser.State>() { @Override public ParseUser.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); return coder.decode(new ParseUser.State.Builder(), result, ParseDecoder.get()) .isComplete(false) .isNew(true) .build(); } }); }
@Override public Task<ParseObject.State> fetchAsync( final ParseObject.State state, String sessionToken, final ParseDecoder decoder) { final ParseRESTCommand command = ParseRESTObjectCommand.getObjectCommand( state.objectId(), state.className(), sessionToken); return command.executeAsync(client).onSuccess(new Continuation<JSONObject, ParseObject.State>() { @Override public ParseObject.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); // Copy and clear to create an new empty instance of the same type as `state` ParseObject.State.Init<?> builder = state.newBuilder().clear(); return coder.decode(builder, result, decoder) .isComplete(true) .build(); } }); }
/* package */ <T extends ParseObject> Task<Integer> countAsync( final ParseQuery.State<T> state, String sessionToken, Task<Void> ct) { final ParseRESTCommand command = ParseRESTQueryCommand.countCommand(state, sessionToken); return command.executeAsync(restClient, ct).onSuccessTask(new Continuation<JSONObject, Task<JSONObject>>() { @Override public Task<JSONObject> then(Task<JSONObject> task) { // Cache the results, unless we are ignoring the cache ParseQuery.CachePolicy policy = state.cachePolicy(); if (policy != null && policy != ParseQuery.CachePolicy.IGNORE_CACHE) { JSONObject result = task.getResult(); ParseKeyValueCache.saveToKeyValueCache(command.getCacheKey(), result.toString()); } return task; } }, Task.BACKGROUND_EXECUTOR).onSuccess(new Continuation<JSONObject, Integer>() { @Override public Integer then(Task<JSONObject> task) { // Convert response return task.getResult().optInt("count"); } }); }
@Test public void testPermanentFailures() throws Exception { JSONObject json = new JSONObject(); json.put("code", 1337); json.put("error", "mock error"); ParseHttpResponse response = newMockParseHttpResponse(400, json); ParseHttpClient client = mock(ParseHttpClient.class); when(client.execute(any(ParseHttpRequest.class))).thenReturn(response); ParseRESTCommand command = new ParseRESTCommand.Builder() .method(ParseHttpRequest.Method.GET) .installationId("fake_installation_id") .build(); Task<JSONObject> task = command.executeAsync(client); task.waitForCompletion(); verify(client, times(1)).execute(any(ParseHttpRequest.class)); assertTrue(task.isFaulted()); assertEquals(1337, ((ParseException) task.getError()).getCode()); assertEquals("mock error", task.getError().getMessage()); }
/** * Test to verify that handle 401 unauthorized */ @Test public void test401Unauthorized() throws Exception { JSONObject json = new JSONObject(); json.put("error", "unauthorized"); ParseHttpResponse response = newMockParseHttpResponse(401, json); ParseHttpClient client = mock(ParseHttpClient.class); when(client.execute(any(ParseHttpRequest.class))).thenReturn(response); ParseRESTCommand command = new ParseRESTCommand.Builder() .method(ParseHttpRequest.Method.GET) .installationId("fake_installation_id") .build(); Task<JSONObject> task = command.executeAsync(client); task.waitForCompletion(); verify(client, times(1)).execute(any(ParseHttpRequest.class)); assertTrue(task.isFaulted()); assertEquals(0, ((ParseException) task.getError()).getCode()); assertEquals("unauthorized", task.getError().getMessage()); }
commandTask = command.executeAsync(httpClient).continueWithTask(new Continuation<JSONObject, Task<JSONObject>>() { @Override public Task<JSONObject> then(Task<JSONObject> task) {
@Test public void testTemporaryFailures() throws Exception { JSONObject json = new JSONObject(); json.put("code", 1337); json.put("error", "mock error"); ParseHttpResponse response1 = newMockParseHttpResponse(500, json); ParseHttpResponse response2 = newMockParseHttpResponse(500, json); ParseHttpResponse response3 = newMockParseHttpResponse(500, json); ParseHttpResponse response4 = newMockParseHttpResponse(500, json); ParseHttpResponse response5 = newMockParseHttpResponse(500, json); ParseHttpClient client = mock(ParseHttpClient.class); when(client.execute(any(ParseHttpRequest.class))).thenReturn( response1, response2, response3, response4, response5 ); ParseRESTCommand command = new ParseRESTCommand.Builder() .method(ParseHttpRequest.Method.GET) .installationId("fake_installation_id") .build(); Task<JSONObject> task = command.executeAsync(client); task.waitForCompletion(); verify(client, times(5)).execute(any(ParseHttpRequest.class)); assertTrue(task.isFaulted()); assertEquals(1337, ((ParseException) task.getError()).getCode()); assertEquals("mock error", task.getError().getMessage()); }
notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED); } else { executeTask = command.executeAsync(httpClient);
.build(); return command.executeAsync( restClient, uploadProgressCallback,
.build(); return command.executeAsync( restClient, uploadProgressCallback,