iOS SDK Samples - Users Operations
Get All Users
//company is the object of getCompanyInfoDelegate()
$company.getUsers { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Users with type
//company is the object of getCompanyInfoDelegate()
$company.getUsers( ofType : .activeUsers ) { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Users with type and params
var params = ZCRMQuery.getRequestParams
params.page = 1
params.perPage = 200
/*- Parameters:
- ofType : Type of users to be fetched*/
//company is the object of getCompanyInfoDelegate()
$company.getUsers( ofType : .adminUsers, withParams: params) { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Users with params
var params = ZCRMQuery.getRequestParams
params.page = 1
params.perPage = 200
//company is the object of getCompanyInfoDelegate()
$company.getUsers(withParams: params) { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Users with headers and params
var params = ZCRMQuery.getRequestParams
params.page = 1
params.perPage = 200
//company is the object of getCompanyInfoDelegate()
$company.getUsers(withParams: params, requestHeaders : [ "X_CRM_ORG" : "1234567" ]) { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Users with headers, type, and params
var params = ZCRMQuery.getRequestParams
params.page = 1
params.perPage = 200
/*- Parameters:
- ofType : Type of users to be fetched*/
//company is the object of getCompanyInfoDelegate()
$company.getUsers(ofType : .adminUsers, withParams: params, requestHeaders : [ "X_CRM_ORG" : "1234567" ]) { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Current User
ZCRMSDKUtil.getCurrentUser { ( result ) in
switch result
{
case .success( let user, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get Current User from the Server
ZCRMSDKUtil.getCurrentUserFromServer { ( result ) in
switch result
{
case .success( let user, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Get a User
//company is the object of getCompanyInfoDelegate()
$company.getUser(id: 123456789) { ( result ) in
switch result
{
case .success( let users, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Add a User
let roles : ZCRMRoleDelegate = ZCRMSDKUtil.getCompanyInfoDelegate().getRoleDelegate(id: 3712204000000026005, name: "CEO")
let profiles : ZCRMProfileDelegate = ZCRMSDKUtil.getCompanyInfoDelegate().getProfileDelegate(id: 3712204000000026011, name: "Administrator")
let user = ZCRMSDKUtil.getCompanyInfoDelegate().newUser ( lastName : "Shawn", email: "boyle@abc.com", role : roles, profile : profiles)
user.create { ( result ) in
switch result
{
case .success( let data, let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Update a User
// user is the object of getUser()
$user.firstName = "Patricia"
$user.alias = "Boyle"
$user.website = "www.zylker.com"
$user.country = "USA"
$user.update { ( result ) in
switch result
{
case .success(let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Delete a User
// user is the object of getUser()
$user.delete { ( result ) in
switch result
{
case .success(let response ) :
print("ResponseJSON : \( response.responseJSON )")
case .failure( let error ) :
print("Throws exception : \(error)")
}
}
Upload the User's Profile Photo Using completion with filePath
guard let filePath = testBundle.path(forResource: "photos/UserProfilePhoto", ofType: "JPG", inDirectory: "resources") else
{
print("Error : Resource Not Found")
return
}
/*- Parameters:
- filePath : path where the file should be uploaded*/
// user is the object of ZCRMUser()
$user.uploadPhoto(filePath: filePath, completion: { ( result ) in
switch result
{
case .success(let response) :
print("User photo updated successfully", response.getMessage())
case .failure(let error) :
print( "UserAPIsTests update operation failed, Error : \(error)" )
}
})
Upload the User's Profile Photo Using completion with fileData
guard let filePath = testBundle.path(forResource: "photos/UserProfilePhoto", ofType: "JPG", inDirectory: "resources") else
{
print("Error : Resource Not Available")
return
}
let data = tryData(contentsOf: URL(fileURLWithPath: filePath))
// user is the object of ZCRMUser()
/*- Parameters:
- fileData : Data object of the image to be uploaded*/
$user.uploadPhoto( fileData: data ) { ( result ) in
switch result
{
case .success(let response) :
print("User photo updated successfully", response.getMessage())
case .failure(let error) :
print( "UserAPIsTests update operation failed, Error : \(error)" )
}
}
Upload the User's Profile Photo Using delegate with filePath
guard let filePath = testBundle.path(forResource: "photos/UserProfilePhoto", ofType: "JPG", inDirectory: "resources") else
{
print("Error : Resource Not Available")
return
}
// user is the object of ZCRMUser()
/*- Parameters:
- fileRefId : reference id which is used as a tag to this api request.
- filePath : path where the file should be downloaded.
- fileUploadDelegate : FileUploadDelegate object which helps to track the progress, completion and error of an upload request*/
$user.uploadPhoto(fileRefId : "Profile Photo With Path Progress", filePath: filePath, fileUploadDelegate: self)
Upload the User's Profile Photo Using delegate with fileData
guard let filePath = testBundle.path(forResource: "photos/UserProfilePhoto", ofType: "JPG", inDirectory: "resources") else
{
print("Error : Resource Not Available")
return
}
guard let data = UIImage( contentsOfFile: filePath)!.jpegData(compressionQuality: 1) else
{
print("Error : Failed to get fileData")
return
}
// user is the object of ZCRMUser()
/*- Parameters:
- fileRefId : reference id which is used as a tag to this api request.
- fileData : Data object of the file to be uploaded
- fileUploadDelegate : FileUploadDelegate object which helps to track the progress, completion and error of an upload request*/
$user.uploadPhoto(fileRefId : "Profile Photo With Data Progress", fileData: data, fileUploadDelegate: self)
Download the User's Profile Photo using completion
// userDel is the object of getUserDelegate()
$userDel.downloadProfilePhoto(completion: { ( result ) in
switch result
{
case .success(let response) :
if let fileData = response.getFileData()
{
print( "File data size : \( fileData.count )" )
}
else
{
print("Failed to get the file data")
}
case .failure(let error) :
print( "UserAPIsTests download operation failed, Error : \(error)" )
}
})
Download the User's Profile Photo using delegate
// userDel is the object of getUserDelegate()
try userDel.downloadProfilePhoto(size : PhotoSize.stamp , fileDownloadDelegate: self)