. . .

Basics Module


Standard module which is added to every app automatically. It contains the user class, which is a representation for a user of your app.

Configuration

configuration key

description

Users can see each other

TRUE if all user of an application can see a list of other user (e.g. to send messages to them) or FALSE if not.

Role necessary for creating new Users

Role name which is needed to create a new user. Possible values are Guest, User, and AppAdmin. Guest is default.

Usage

Every user of your app should be represented by a corresponding User object. Using this is not only a nice and easy way to store and view your user without creating a own class, but is also necessary for authorization. Most requests on the server (especially those which require the client to be the owner) need the credentials of a valid user to make authorization work. So the first initial step in your app will be the creation and authentication of your user:

Android

Android
// Create your user
final User user = new User();
user.setUserName("johnDoe");
user.setPassword("123456");
 
// Configure the Datastore, a static class doing all the network stuff,
// before doing the first request
Datastore.configureWithCredentials(user);
 
// Now check if the user already exists and in case he doesn't: create the user
user.loadMeAsync(new AOMEmptyCallback() {
@Override
public void isDone(boolean wasLoadedFromStorage, ApiomatRequestException exception) {
if (exception != null) {
// if the member is not found on the server just create it
user.saveAsync(new AOMEmptyCallback() {
@Override
public void isDone(boolean wasLoadedFromStorage, ApiomatRequestException exception) {
// ...
}
});
}
}
});

Objective-C

Objective-C
// Create your user
AOMUser *u = [[AOMUser alloc] init];
[u setUserName:@"johnDoe" ];
[u setPassword:@"123456" ];
// Configure the Datastore,
// a static class doing all the network stuff,
// before doing the first request
[DataStore configureWithCredentialsWithUser:u configuration: nil];
 
// now you can try to load the users data from the server
[u loadMe:^(NSError * error) {
// if the user exists, we should now have a valid href
if([u href] == NULL || error)
{
// if not, let us create the user initally
[u saveObjCWithLoadAfterwards:true completion:^(NSError * error) {
 
}];
}
}];

Swift

Swift
// Create your user
var u = AOMUser()
u.userName = "johnDoe"
u.password = "123456"
// Configure the Datastore,
// a static class doing all the network stuff,
// before doing the first request
DataStore.configureWithCredentials(user)
 
// now you can try to load the users data from the server
u.loadMe { (error) in
// if the user exists, we should now have a valid href
if u.href == nil || error {
// if not, let us create the user initally
u.save { (error) in
}
}
}

JavaScript

JavaScript
// Create a new member/user of your app
var myUser = new Apiomat.User();
myUser.setUserName("johnDoe");
myUser.setPassword("1,618");
 
// configure datastore with user credentials
Apiomat.Datastore.configureWithCredentials(myUser);
 
var saveCB = {
onOk : function() {
console.log("saved");
//Now you can create objects of your class with this new user..
},
onError : function(error) {
console.log("Some error occured: (" + error.statusCode + ")" + error.message);
}
};
 
// Try to load user or create new one if not exists
myUser.loadMe({
onOk : function() {
//Now you can do sth with loaded object
},
onError : function(error) {
// and save it
myUser.save(saveCB);
}
});

TypeScript

TypeScript
// Create a new member/user of your app
const myUser = User();
myUser.userName = "johnDoe";
myuser.password = "1,618";
 
Datastore.configureAsUser(myUser);
 
// Try to load user or create new one if not exists
try {
await myUser.loadMe();
} catch(e) {
await myUser.save();
}

As you have seen, the Datastore plays an important role: All requests are done using it. But that’s only FYI, all calls are encapsulated in SDK generated methods. Usually you should operate only with your generated classes.