Android SDK Samples - Users Operations
ZCRMSDKUtil.getCurrentUserFromServer(object: DataCallback<APIResponse,ZCRMUser>
{
override fun completed(response: APIResponse, user: ZCRMUser)
{
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException)
{
println("Throws Exception : $exception")
}
})
//$companyInfo object is of ZCRMCompanyInfo
//call getUsers() using $companyInfo object
$companyInfo.getUsers(object : DataCallback<BulkAPIResponse, List<ZCRMUser>>
{
override fun completed(response: BulkAPIResponse, users: List<ZCRMUser>)
{
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException)
{
println("Throws Exception : $exception")
}
})
//$companyInfo object is of ZCRMCompanyInfo
val role = $companyInfo.getRoleDelegate( 3712204000000026005,"CEO") //pass the id and name of the role as parameters
val profile = $companyInfo.getProfileDelegate(3712204000000026011,"Administrator")//pass the id and name of the profile as parameters.
val orguser = $companyInfo.newUser("shawn@zylker.com",role, profile) //pass the email id of the user,role and profile as parameters
$orguser.lastName = "Shawn"
$orguser.add(object : DataCallback<APIResponse,ZCRMUser>{
override fun completed(response: APIResponse, user: ZCRMUser) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$companyInfo object is of ZCRMCompanyInfo
//call getUser() using $companyInfo object by passing the id as a parameter
//id - Id whose user is to be returned
$companyInfo.getUser(3712204000001392001, object : DataCallback<APIResponse, ZCRMUser>{
override fun completed(response: APIResponse, user: ZCRMUser) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$user is the object of ZCRMUser
//define the user data using $user object
$user.firstName = "Benjamin"
$user.alias = "Benny"
$user.website = "www.zylker.com"
$user.country = "USA"
//call update() using $user object
$user.update(object : DataCallback<APIResponse,ZCRMUser>{
override fun completed(response: APIResponse, zcrmentity: ZCRMUser) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$user is the object of ZCRMUser
//call delete() using $user object
$user.delete(object : ResponseCallback<APIResponse>{
override fun completed(response: APIResponse) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$user is the object of ZCRMUser
//call uploadProfilePhoto() using $user object
//pass fileRequestRefId, urisource and photoViewPermission as parameters
//fileRequestRefId - reference id which is used as a tag to this api request
//uri - URI of the resource to be uploaded
//photoViewPermission - PhotoViewPermission (NONE, ZOHO_USERS, ORG_USERS, PUBLIC, CONTACTS)
$user.uploadProfilePhoto("123456789", uriSource, CommonUtil.PhotoViewPermission.ORG_USERS, object : FileTransferTask<APIResponse>
{
override fun onCompletion(response: APIResponse) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception")
}
override fun onProgressUpdate(bytesWritten: Long,contentLength: Long,percentage: Double) {
println("$bytesWritten, $contentLength, $percentage")
}
})
//$user is the object of ZCRMUser
//call uploadProfilePhoto() using $user object
//pass fileRequestRefId, filePath and photoViewPermission as parameters
//fileRequestRefId - reference id which is used as a tag to this api request
//filePath - Path of the photo to be uploaded
//photoViewPermission - PhotoViewPermission (NONE, ZOHO_USERS, ORG_USERS, PUBLIC, CONTACTS)
$user.uploadProfilePhoto("123456789", File(filename).absolutePath,CommonUtil.PhotoViewPermission.ORG_USERS,object : FileTransferTask<APIResponse>
{
override fun onCompletion(response: APIResponse) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception")
}
override fun onProgressUpdate(
bytesWritten: Long, contentLength: Long,percentage: Double) {
println("$bytesWritten, $contentLength, $percentage")
}
})
//$user is the object of ZCRMUser
//call downloadProfilePhoto() using $user object by passing the photoSize as a parameter
//photoSize - PhotoSize (STAMP, THUMB, ORIGINAL, MEDIUM)
$user.downloadProfilePhoto(CommonUtil.PhotoSize.ORIGINAL, object : DataCallback<FileAPIResponse?,InputStream>
{
override fun completed(response: FileAPIResponse?,zcrmentity: InputStream) {
println("${response?.responseJSON}")
}
override fun failed(exception: ZCRMException)
{
println("Throws Exception : $exception")
}
})
//$user is the object of ZCRMUser
//call downloadProfilePhotoFromServer() using $user object by passing the fileRequestRefId, filePath, fileName and photoSize as parameters
//fileRequestRefId - reference id which is used as a tag to this api request
//filePath - path where the file should be downloaded
//fileName - name of the file should be downloaded
//photoSize - PhotoSize (STAMP, THUMB, ORIGINAL, MEDIUM)
$user.downloadProfilePhotoFromServer("123456731", File(filename).absolutePath, "profilePic12.jpg", CommonUtil.PhotoSize.ORIGINAL,object: FileWithDataTransferTask<FileAPIResponse,String>{
override fun onCompletion(response: FileAPIResponse, zcrmEntity: String) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception")
}
override fun onProgressUpdate(bytesWritten: Long,contentLength: Long,percentage: Double) {
println("$bytesWritten, $contentLength, $percentage")
}
})