Search in sources :

Example 1 with BackendlessUserAdaptingPolicy

use of com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy in project Android-SDK by Backendless.

the class UserService method register.

public BackendlessUser register(BackendlessUser user) throws BackendlessException {
    checkUserToBeProper(user);
    BackendlessSerializer.serializeUserProperties(user);
    String password = user.getPassword();
    BackendlessUser userToReturn = Invoker.invokeSync(USER_MANAGER_SERVER_ALIAS, "register", new Object[] { user.getProperties() }, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
    user.clearProperties();
    userToReturn.setPassword(password);
    user.putProperties(userToReturn.getProperties());
    return userToReturn;
}
Also used : AdaptingResponder(com.backendless.core.responder.AdaptingResponder) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy)

Example 2 with BackendlessUserAdaptingPolicy

use of com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy in project Android-SDK by Backendless.

the class UserService method register.

public void register(final BackendlessUser user, final AsyncCallback<BackendlessUser> responder) {
    try {
        checkUserToBeProper(user);
        BackendlessSerializer.serializeUserProperties(user);
        Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "register", new Object[] { user.getProperties() }, new AsyncCallback<BackendlessUser>() {

            @Override
            public void handleResponse(BackendlessUser response) {
                response.setPassword(user.getPassword());
                user.clearProperties();
                user.putProperties(response.getProperties());
                if (responder != null)
                    responder.handleResponse(response);
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                if (responder != null)
                    responder.handleFault(fault);
            }
        }, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
    } catch (BackendlessException e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessException(com.backendless.exceptions.BackendlessException) AdaptingResponder(com.backendless.core.responder.AdaptingResponder) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 3 with BackendlessUserAdaptingPolicy

use of com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy in project Android-SDK by Backendless.

the class UserServiceAndroidExtra method getBackendlessUser.

private void getBackendlessUser(final AccessToken accessToken, final Map<String, String> facebookFieldsMappings, final AsyncCallback<BackendlessUser> responder) {
    GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {

        @Override
        public void onCompleted(JSONObject object, GraphResponse response) {
            FacebookBundle facebookBundle = new FacebookBundle(response, accessToken);
            Object[] requestData = new Object[] { null, facebookBundle.accessToken, null, null, facebookFieldsMappings };
            Invoker.invokeAsync(UserService.USER_MANAGER_SERVER_ALIAS, "loginWithFacebook", requestData, responder, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link");
    request.setParameters(parameters);
    request.executeAsync();
}
Also used : AdaptingResponder(com.backendless.core.responder.AdaptingResponder) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy)

Example 4 with BackendlessUserAdaptingPolicy

use of com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy in project Android-SDK by Backendless.

the class UserService method update.

public void update(final BackendlessUser user, final AsyncCallback<BackendlessUser> responder) {
    try {
        checkUserToBeProperForUpdate(user);
        BackendlessSerializer.serializeUserProperties(user);
        if (user.getUserId() != null && user.getUserId().equals(""))
            throw new IllegalArgumentException(ExceptionMessage.WRONG_USER_ID);
        Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "update", new Object[] { user.getProperties() }, new AsyncCallback<BackendlessUser>() {

            @Override
            public void handleResponse(BackendlessUser response) {
                user.clearProperties();
                user.putProperties(response.getProperties());
                if (responder != null)
                    responder.handleResponse(response);
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                if (responder != null)
                    responder.handleFault(fault);
            }
        }, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : AdaptingResponder(com.backendless.core.responder.AdaptingResponder) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 5 with BackendlessUserAdaptingPolicy

use of com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy in project Android-SDK by Backendless.

the class UserService method update.

public BackendlessUser update(final BackendlessUser user) throws BackendlessException {
    checkUserToBeProperForUpdate(user);
    BackendlessSerializer.serializeUserProperties(user);
    if (user.getUserId() != null && user.getUserId().equals(""))
        throw new IllegalArgumentException(ExceptionMessage.WRONG_USER_ID);
    BackendlessUser userToReturn = Invoker.invokeSync(USER_MANAGER_SERVER_ALIAS, "update", new Object[] { user.getProperties() }, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
    user.clearProperties();
    user.putProperties(userToReturn.getProperties());
    return userToReturn;
}
Also used : AdaptingResponder(com.backendless.core.responder.AdaptingResponder) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy)

Aggregations

AdaptingResponder (com.backendless.core.responder.AdaptingResponder)5 BackendlessUserAdaptingPolicy (com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy)5 BackendlessFault (com.backendless.exceptions.BackendlessFault)2 Bundle (android.os.Bundle)1 BackendlessException (com.backendless.exceptions.BackendlessException)1 JSONObject (org.json.JSONObject)1