If you think the Android project matrix-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2014 OpenMarket Ltd//www.java2s.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package org.matrix.androidsdk.rest.client;
import org.matrix.androidsdk.RestClient;
import org.matrix.androidsdk.rest.api.ProfileApi;
import org.matrix.androidsdk.rest.callback.ApiCallback;
import org.matrix.androidsdk.rest.callback.RestAdapterCallback;
import org.matrix.androidsdk.rest.model.User;
import org.matrix.androidsdk.rest.model.login.Credentials;
import retrofit.RestAdapter;
import retrofit.client.Response;
/**
* Class used to make requests to the profile API.
*/publicclass ProfileRestClient extends RestClient {
private ProfileApi mApi;
/**
* {@inheritDoc}
*/public ProfileRestClient(Credentials credentials) {
super(credentials);
}
@Override
protectedvoid initApi(RestAdapter restAdapter) {
mApi = restAdapter.create(ProfileApi.class);
}
/**
* Protected setter for injection by unit tests.
* @param api the api object
*/protectedvoid setApi(ProfileApi api) {
mApi = api;
}
/**
* Get the user's display name.
* @param userId the user id
* @param callback the callback to return the name on success
*/publicvoid displayname(String userId, final ApiCallback<String> callback) {
mApi.displayname(userId, new RestAdapterCallback<User>(callback) {
@Override
publicvoid success(User user, Response response) {
callback.onSuccess(user.displayname);
}
});
}
/**
* Update this user's own display name.
* @param newName the new name
* @param callback the callback if the call succeeds
*/publicvoid updateDisplayname(String newName, final ApiCallback<Void> callback) {
User user = new User();
user.displayname = newName;
mApi.displayname(mCredentials.userId, user, new RestAdapterCallback<Void>(callback));
}
/**
* Get the user's avatar URL.
* @param userId the user id
* @param callback the callback to return the URL on success
*/publicvoid avatarUrl(String userId, final ApiCallback<String> callback) {
mApi.avatarUrl(userId, new RestAdapterCallback<User>(callback) {
@Override
publicvoid success(User user, Response response) {
callback.onSuccess(user.avatarUrl);
}
});
}
/**
* Update this user's own avatar URL.
* @param newUrl the new name
* @param callback the callback if the call succeeds
*/publicvoid updateAvatarUrl(String newUrl, final ApiCallback<Void> callback) {
User user = new User();
user.avatarUrl = newUrl;
mApi.avatarUrl(mCredentials.userId, user, new RestAdapterCallback<Void>(callback));
}
}