The REST APIs, at their root, are a set of HTTP-based APIs for accessing IMVU. Inside IMVUnity this is hidden behind a clean, strongly-typed API. Aside from the fact that many operations are asynchronous, you don't have to worry about the fact that there are HTTP requests behind the scenes. The REST APIs are accessed through RestModel andRestCollection classes.

RestModel Class

A RestModel is a base class for representing a single data node. It is generic over the type it stores. It contains apopulated member variable, which is a Promise for the data it contains. For instance, UserModel is a subclass ofRestModel<UserInfo>, and its populated member variable will have type Promise<UserInfo, string>.

Each subclass of RestModel will also contain getters for each of the other data nodes related to it. These getters will always return another RestModel.

The set of RestModels that exist right now are: * UserModel - Data about a single user. * FriendModel - A relationship between two users, containing no data of it's own.

RestCollection Class

A RestCollection is a base class for representing a list of data nodes. This looks like:

class RestCollection<T> : RestModel<CollectionInfo<T>> {
	public Promise<CollectionInfo<T>, string> populated;

	public Promise<Unit, string> NextPage();
	public delegate void AddEventHandler(T model);
	public event AddEventHandler add;
}

The CollectionInfo class is as follows:

class CollectionInfo<T> {
    public List<T> items;
    public int totalCount;
}

It's generic over the type of RestModel it stores. Like RestModel, it contains a populated promise. For example, theFriendCollection inherits from RestColletion<FriendModel>, and it's populated promise will have typePromise<CollectionInfo<FriendModel>, string>.

Note that collections are paginated. The totalCount field represents the total size of the collection, which may be larger than the number currently loaded, which is why it needs to be a separate field, instead of just using items.Count. CallingNextPage() will load the next page. The promise it returns will be accepted when the request for the next page is complete and populated into the collection, or rejected if the request fails. There is also the add event, which will be called each time a new element is added to the collection. Currently this only happens during loading. So you can respond to a new page loading either by using the promise returned by NextPage, or one element at a time by using theadd event.

The set of RestCollections that exist right now are:

  • FriendCollection - A collection of FriendModels, obtained by calling UserModel.GetFriends().

UserModel Class

This model represents a user:

class UserModel : RestModel<UserInfo> {
public Promise<UserInfo, string> populated;

// Get the user's friends
public Promise<FriendCollection, string> GetFriends(int limit = 0);
}

The limit argument to GetFriends determines the page size of the resulting FriendCollection. The default value of 0 means to use the server's default page size.

The UserInfo data is as follows:

struct UserInfo {
public string gender;
public string country;
public string state;
public Uri thumbnailUrl;
public bool online;
public string username;
}

FriendCollection Class

This collection represents a user's friend list:

class FriendCollection : RestCollection<FriendModel> {
public Promise<CollectionInfo<FriendModel>, string> populated;
}

FriendModel Class

This model represents a friend:

class FriendModel : RestModel<FriendInfo> {
public promise<FriendInfo, string> populated;

// Get the friend's user
public Promise<UserModel, string> GetUser();
}

The FriendInfo is empty, because the FriendModel exists merely to represent a relationship between two users. It doesn't have any data of it's own.

Imvu Class

The entry point to the whole API is the Imvu class. For the moment, this has one method:

Promise<UserModel, string> Login();

The Login() method will handle the whole login process for you. By the time the Promise it returns is resolved, either the user will be logged in and you'll have their UserModel, or the login process will have failed.