Module: User

User

User Provider
Author:
  • Marco Lehmann <marco.lehmann (at) kiwigrid.com>
Source:

Classes

ketaUser
UserInstance
UserProvider

Methods

<inner> $create() → {promise}

Creates a remote UserInstance from local one the method is called on.

Source:
Returns:
promise promise
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {

        var user = ketaUser.create({
            userId: 'userId'
        });

        user.$create()
            .then(function(reply) {
                // success handler
                // ...
            }, function(reply) {
                // error handler
                // ...
            });

    });

<inner> $delete() → {promise}

Deletes a remote UserInstance from local one the method is called on.

Source:
Returns:
promise promise
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {

        var user = ketaUser.create({
            userId: 'userId'
        });

        user.$delete()
            .then(function(reply) {
                // success handler
                // ...
            }, function(reply) {
                // error handler
                // ...
            });

    });

<inner> $reset() → {undefined}

Resets a UserInstance to it's $pristine state.

Source:
Returns:
undefined nothing
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {

        var user = ketaUser.create({
            userId: 'john.doe',
            channel: 'channel',
            givenName: 'John',
            familyName: 'Doe',
            email: 'john.doe@test.com',
            address: {
                street: 'Main Street',
                number: '100 E',
                city: 'Phoenix',
                country: 'USA',
                zip: '85123'
            },
            properties: {
                position: 'left'
            }
        });

        user.email = 'john.doe@kiwigrid.com';
        delete user.properties.position;

        user.$update()
            .then(function(reply) {
                // success handler
                // ...
            }, function(reply) {
                // error handler
                user.$reset();
            });

    });

<inner> $update() → {promise}

Updates a remote UserInstance from local one the method is called on.

Source:
Returns:
promise promise
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {

        var user = ketaUser.create({
            userId: 'john.doe',
            channel: 'channel',
            givenName: 'John',
            familyName: 'Doe',
            email: 'john.doe@test.com',
            address: {
                street: 'Main Street',
                number: '100 E',
                city: 'Phoenix',
                country: 'USA',
                zip: '85123'
            },
            properties: {
                position: 'left'
            }
        });

        user.email = 'john.doe@kiwigrid.com';
        delete user.properties.position;

        user.$update()
            .then(function(reply) {
                // success handler
                // ...
            }, function(reply) {
                // error handler
                // ...
            });

    });

<inner> create(eventBus, properties) → {UserInstance}

Creates a UserInstance with given EventBus instance and properties.

Parameters:
Name Type Description
eventBus EventBus EventBus instance to use for communication
properties Object Properties to set upon UserInstance creation
Source:
Returns:
UserInstance created UserInstance
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {
        var user = ketaUser.create(eventBus, {
            userId: 'john.doe',
            channel: 'channel',
            givenName: 'John',
            familyName: 'Doe',
            email: 'john.doe@test.com',
            address: {
                street: 'Main Street',
                number: '100 E',
                city: 'Phoenix',
                country: 'USA',
                zip: '85123'
            }
        });
    });

<inner> getChannel(eventBus, channelId) → {String}

Returns the channel name for given channel id.

Parameters:
Name Type Description
eventBus EventBus EventBus instance to use for communication
channelId String Channel id to retrieve.
Source:
Returns:
String channel name
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {
        ketaUser.getChannel(eventBus, 'channel-1')
            .then(function(reply) {
                // reply is channel name
            });
    });

<inner> getCurrent(eventBus) → {UserInstance}

Returns the currently logged-in user.

Parameters:
Name Type Description
eventBus EventBus EventBus instance to use for communication
Source:
Returns:
UserInstance current logged-in user
Example
angular.module('exampleApp', ['keta.services.User'])
    .controller('ExampleController', function(ketaUser) {
        ketaUser.getCurrentUser(eventBus)
            .then(function(reply) {
                // reply is current UserInstance
            });
    });