App42 Cloud API

Ruby Cloud SDK

User

Creates User for the App. App42 Cloud API's provides a complete User Management for any Mobile or Web App. It supports User registration, retrieval, state management e.g. lock, delete and Authentication.

Along with User management the platform provides API's for persistent SessionManagement

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

api = App42::ServiceAPI.new("<API_KEY>","<SECRET_KEY>")

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of UserService, buildUserService() method needs to be called.

	userService = api.buildUserService();

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like User in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have also provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

uName = "Nick";
pwd = "********";
emailId = "nick@shephertz.com";

user = userService.create_user(uName, pwd, emailId); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
jsonResponse = user.to_s(); /* returns the response in JSON format. */

The functions available under User API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is creating a user with username which is already in database, the function will throw the App42Exception (as shown below) with message as "Bad Request" and the appErrorCode as "2001" and the details as "User by the name '<userName>' does not exist.".

uName = "Nick";
pwd = "********";
emailId = "nick@shephertz.com";
						
begin
   user = userService.create_user(uName, pwd, emailId);
rescue App42Exception => ex
  appErrorCode = ex.app_error_code;
  httpErrorCode = ex.http_error_code;

  if(appErrorCode == 2001)
    # Handle here for Bad Request (User by the name '<userName>' does not exist.)

  elsif(appErrorCode  == 2005)
    # Handle here for Bad Request (The request parameters are invalid. User with emailId '<emailId>' already exists. )

  elsif(appErrorCode == 1401)
    # handle here for Client is not authorized

  else(appErrorCode == 1500)
    # handle here for Internal Server Error
  end

  jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
end 
{
    "app42Fault": {
        "httpErrorCode": 400,
        "appErrorCode": 2001,
        "message": "Bad Request",
        "details": "The Request parameters are invalid. Username 'Nick' already Exists"
    }
}

Below are the HTTP Error Codes and their description, the function under the User API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again	
*/

Below are the Application Error Codes and their description, the function under the User API can throw.

/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
2001 - BAD REQUEST - The request parameters are invalid. Username '<userName>' already exists. 
2002 - NOT FOUND - UserName/Password did not match. Authentication Failed.
2003 - BAD REQUEST - Old Password is not matching for user '<userName>'.  
2004 - NOT FOUND - User with the emailId '<emailId>' does not exist.
2005 - BAD REQUEST - The request parameters are invalid. User with emailId '<emailId>' already exists.
2006 - NOT FOUND - Users do not exist.	
2007 - NOT FOUND - The number of users are less than the specified offset : '<offset>'.
2008 - NOT FOUND - The number of locked users are less than the specified offset : '<offset>'.
2009 - NOT FOUND - Users with the role '<role>' do not exist.
2010 - NOT FOUND - No role found for the user '<userName>'.
2011 - NOT FOUND - Role '<role>' for the user '<userName>' does not exist.
2012 - NOT FOUND - Roles for the user '<userName>' do not exist.
*/

Various functions available under User API has been explained below.

def create_user(uName, pwd, emailId)

Create user for the App.

Parameters:

uName - UserName which should be unique for the App
pwd - Password for the User
emailId - Email address of the user

Returns:

The created User Object.

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2001 - BAD REQUEST - The request parameters are invalid. Username '<userName>' already exists.
2005 - BAD REQUEST - TThe request parameters are invalid. User with emailId '<emailid>' already exists.
*/
For more details click Exception
uName = "Nick";
pwd = "********";
emailId = "nick@shephertz.com";
						
user = userService.create_user(uName, pwd, emailId); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "email": "nick@shephertz.com"
                }
            }
        }
    }
}
def create_user_with_role(uName, pwd, emailId, roleList)

Create User for the App.

Parameters:

uName - UserName which should be unique for the App
pwd - Password for the User
emailId - Email address of the user
roleList - List of roles to be assigned to User

Returns:

The created User Object.

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2001 - BAD REQUEST - The request parameters are invalid. Username '<userName>' already exists.
2005 - BAD REQUEST - The request parameters are invalid. User with emailId '<emailid>' already exists.
*/
For more details click Exception
uName = "Nick";
pwd = "********";
emailId = "nick@shephertz.com";
roleList = Array.new();
roleList.push("Admin");
roleList.push("Manager");
roleList.push("Programmer");
roleList.push("Tester");
					
user = userService.create_user_with_role(uName,pwd,emailId,roleList); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
userRoleList  = user.roleList();
for roles in userRoleList do
  puts "role is #{roles}";
end
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "email": "nick@shephertz.com",
                    "role": [
                        "Admin",
                        "Manager",
                        "Programmer",
                        "Tester"
                    ]
                }
            }
        }
    }
}
def assign_roles(uName, roleList)

Assign Roles for the App

Parameters:

uName - UserName which should be unique for the App
roleList - list of roles to be assigned to User

Returns:

The created User Object.

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
uName = "Nick";
roleList = Array.new();
roleList.push("Admin");
roleList.push("Manager");
roleList.push("Programmer");
roleList.push("Tester");

user = userService.assign_roles(uName,roleList); /* returns the User object. */
puts "userName is #{user.userName}";
userRoleList = user.roleList();
for roles in userRoleList do
  puts "role is #{roles}";
end
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below) */
		
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "role": [
                        "Admin",
                        "Manager",
                        "Programmer",
                        "Tester"
                    ]
                }
            }
        }
    }
}
def get_roles_by_user(userName)

Get Roles based on userName

Parameters:

userName - UserName which should be unique for the App

Returns:

User Object

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
2010 - NOT FOUND - No role found for the user '<userName>'.
*/
For more details click Exception
userName = "Nick";
						
user = userService.get_roles_by_user(userName); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";  
userRoleList = user.roleList(); 
puts "firstName is #{user.profile.firstName}";  
jsonResponse = user.to_s();  /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "email": "nick@shephertz.com",
                    "role": [
                        "Admin",
                        "Manager",
                        "Programmer",
                        "Tester"
                    ],
                    "accountLocked": false,
                    "profile": {
                        "firstName": "Nick",
                        "lastName": "Gill",
                        "sex": "Male",
                        "dateOfBirth": "2012-12-11T18:30:00.000Z",
                        "mobile": "+1-1111-111-111",
                        "officeLandLine": "+2-2222-222-222",
                        "homeLandLine": "+3-3333-333-333",
                        "line1":"Line1",
                        "line2":"Line2",
                        "city": "Tulsa",
                        "state":"Oklahoma",
                        "pincode":"74193",
                        "country":"USA"
                    }
                }
            }
        }
    }
}
def get_users_by_role(role)

Get Users based on Role

Parameters:

role - Role which should be unique for the App

Returns:

List of User Object for that particular role

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2009 - NOT FOUND - Users with the role '<role>' do not exist.
*/
For more details click Exception
role = "Admin";
   
userList = userService.get_users_by_role(role); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
puts "firstName #{user.profile.firstName}";
userRoleList = user.roleList(); 
jsonResponse = user.to_s();  /* returns the response in JSON format. (as shown below)*/
  		
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": [
                    {
                        "userName": "Nick",
                        "email": "nick@shephertz.com",
                        "role": "Admin",
                        "accountLocked": false,
                        "profile": {
                            "firstName": "Nick",
                            "lastName": "Gill",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+1-1111-111-111",
                            "officeLandLine": "+2-2222-222-222",
                            "homeLandLine": "+3-3333-333-333",
                            "line1": "300 Oxford Street",
                            "line2": "W1A 1EX ",
                            "city": "Tulsa",
                            "state": "Oklahoma",
                            "pincode": "74193",
                            "country": "USA"
                        }
                    },
                    {
                        "userName": "Allen Hill",
                        "email": "allenHill@shephertz.com",
                        "role": "Admin",
                        "accountLocked": false,
                        "profile": {
                            "firstName": "Allen",
                            "lastName": "Hill",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+4-4444-444-444",
							"officeLandLine": "+5-5555-555-555",
							"homeLandLine": "+6-6666-666-666",
                            "line1": "300 Oxford Street2",
                            "line2": "W1A 1EX 2",
                            "city": "Tulsa",
                            "state": "Oklahoma",
                            "pincode": "74193",
                            "country": "USA"
                        }
                    }
                ]
            }
        }
    }
}
def get_user(userName)

Gets user details based on userName.

Parameters:

userName - UserName which should be unique for the App

Returns:

User Object

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
userName = "Nick";	
					
user = userService.get_user(userName); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
puts "firstName #{user.profile.firstName}";
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "email": "nick@gmail.com",
                    "accountLocked": false,
                    "profile": {
                        "firstName": "Nick",
                        "lastName": "Gill",
                        "sex": "Male",
                        "dateOfBirth": "2012-12-11T18:30:00.000Z",
                        "mobile": "+1-1111-111-111",
                        "officeLandLine": "+2-2222-222-222",
                        "homeLandLine": "+3-3333-333-333",
                        "line1": "300 Oxford Street",
                        "line2": "W1A 1EX ",
                        "city": "Tulsa",
                        "state": "Oklahoma",
                        "pincode": "74193",
                        "country": "USA"
                    }
                }
            }
        }
    }
}
def get_all_users()

Gets All users details.

Parameters:

N/A

Returns:

The List that contains all User Object

Response: ArrayList<User> Object

Exception:

The method throws the following exception with the error code
/*
2006 - NOT FOUND - Users do not exist.
*/
For more details click Exception
userList = userService.get_all_users(); /* returns the list of User objects. */
for user in userList do
  puts "userName is #{user.userName}";
  puts "email is #{user.email}";
  puts "firstName #{user.profile.firstName}";
end
jsonResponse = userList.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": [
                    {
                        "userName": "Nick",
                        "email": "nick@shephertz.com",
                        "accountLocked": false,
                        "profile": {
                            "firstName": "Nick",
                            "lastName": "Gill",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+1-1111-111-111",
							"officeLandLine": "+2-2222-222-222",
							"homeLandLine": "+3-3333-333-333",
                            "line1": "300 Oxford Street",
                            "line2": "W1A 1EX ",
                            "city": "Tulsa",
                            "state": "Oklahoma",
                            "pincode": "74193",
                            "country": "USA"
                        }
                    },
                    {
                        "userName": "Alfred",
                        "email": "Alfred@shephertz.com",
                        "accountLocked": false,
                        "profile": {
                            "firstName": "Alfred",
                            "lastName": "Manistra",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+4-4444-444-444",
							"officeLandLine": "+5-5555-555-555",
							"homeLandLine": "+6-6666-666-666",
                            "line1": "300 Oxford Street2",
                            "line2": "W1A 1EX 2",
                            "city": "London",
                            "state": "State",
                            "pincode": "120981",
                            "country": "London"
                        }
                    }
                ]
            }
        }
    }
}
def get_all_users_count()

Gets the count of all the users

Parameters:

N/A

Returns:

The count of all User exists

Response: App42Response Object

For more details click Exception
response = userService.get_all_users_count(); /* returns the App42Response objects. */  
success = response.isResponseSuccess();  
totalRecords = response.totalRecords();  
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
  
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
def get_all_users_by_paging(max, offset)

Gets All users By Paging

Parameters:

max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

The List that contains all User Object

Response: ArrayList<User> Object

Exception:

The method throws the following exception with the error code
/*
2007 - NOT FOUND - The number of users are less than the specified offset : '<offset>'.
*/
For more details click Exception
max = 1;
offset = 0 ;
						
userList = Array.new();
userList = userService.get_all_users_by_paging(max, offset); /* returns the list of User objects. */
for user in userList do
  puts "userName is #{user.userName}";
  puts "email is #{user.email}";
  puts "firstName #{user.profile.firstName}";
end
jsonResponse = userList.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick ",
                    "email": "nick@gmail.com",
                    "accountLocked": false,
                    "profile": {
                        "firstName": "Nick",
                        "lastName": "Gill",
                        "sex": "Male",
                        "dateOfBirth": "2012-12-11T18:30:00.000Z",
                        "mobile": "+1-1111-111-111",
                        "officeLandLine": "+2-2222-222-222",
                        "homeLandLine": "+3-3333-333-333",
                        "line1": "300 Oxford Street",
                        "line2": "W1A 1EX ",
                        "city": "Tulsa",
                        "state": "Oklahoma",
                        "pincode": "74193",
                        "country": "USA"
                    }
                }
            }
        }
    }
}
def get_user_by_email_id(emailId)

Gets user details based on Email Id.

Parameters:

emailId - EmailId of the user to be retrieved

Returns:

User Object

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2004 - NOT FOUND - User with the emailId '<emailId>' does not exist.
*/
For more details click Exception
emailId = "nick@shephertz.com";	
					
user = userService.get_user_by_email_id(emailId); /* returns the User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
puts "firstName #{user.profile.firstName}";
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "email": "nick@gmail.com",
                    "accountLocked": false,
                    "profile": {
                        "firstName": "Nick",
                        "lastName": "Gill",
                        "sex": "Male",
                        "dateOfBirth": "2012-12-11T18:30:00.000Z",
                        "mobile": "+1-1111-111-111",
                        "officeLandLine": "+2-2222-222-222",
                        "homeLandLine": "+3-3333-333-333",
                        "line1": "300 Oxford Street2",
                        "line2": "W1A 1EX 2",
                        "city": "London",
                        "state": "State",
                        "pincode": "120981",
                        "country": "London"
                    }
                }
            }
        }
    }
}
def get_locked_users()

Gets All the locked users details.

Parameters:

N/A

Returns:

The List that contains locked User Objects

Response: ArrayList<User> Object

Exception:

The method throws the following exception with the error code
/*
2006 - NOT FOUND - Users do not exist.
*/
For more details click Exception
userList = Array.new();
userList = userService.get_locked_users(); /* returns the list of locked User objects. */
for user in userList do
  puts "userName is #{user.userName}";
  puts "email is #{user.email}";
  puts "firstName #{user.profile.firstName}";
end
jsonResponse = userList.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": [
                    {
                        "userName": "Nick ",
                        "email": "nick@gmail.com",
                        "accountLocked": true,
                        "profile": {
                            "firstName": "Nick ",
                            "lastName": "Gill",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+1-1111-111-111",
							"officeLandLine": "+2-2222-222-222",
							"homeLandLine": "+3-3333-333-333",
                            "line1": "300 Oxford Street",
                            "line2": "W1A 1EX ",
                            "city": "Tulsa",
                            "state": "Oklahoma",
                            "pincode": "74193",
                            "country": "USA"
                        }
                    },
                    {
                        "userName": "Billy",
                        "email": "billy@gmail.com",
                        "accountLocked": true,
                        "profile": {
                            "firstName": "Billy",
                            "lastName": "Bouden",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+4-4444-444-444",
							"officeLandLine": "+5-5555-555-555",
							"homeLandLine": "+6-6666-666-666",
                            "line1": "300 Oxford Street2",
                            "line2": "W1A 1EX 2",
                            "city": "London",
                            "state": "State",
                            "pincode": "120981",
                            "country": "London"
                        }
                    }
                ]
            }
        }
    }
}
def get_locked_users_count()

Gets the count of all the locked users

Parameters:

N/A

Returns:

The count of locked User exists

Response: App42Response Object

For more details click Exception
response = userService.get_locked_users_count(); /* returns the App42Response objects. */  
success = response.isResponseSuccess();  
totalRecords = response.totalRecords();  
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
def get_locked_users_by_paging(max, offset)

Gets All the locked users By paging details

Parameters:

max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

The List that contains locked User Objects

Response: ArrayList<User> Object

Exception:

The method throws the following exception with the error code
/*
2008 - NOT FOUND - The number of locked users are less than the specified offset : '<offset>'.
*/ 	          
For more details click Exception
max = 1;
offset = 0;	
					
userList = Array.new();
userList = userService.get_locked_users_by_paging(max, offset); /* returns the list of locked User objects. */
for user in userList do
  puts "userName is #{user.userName}";
  puts "email is #{user.email}";
  puts "firstName #{user.profile.firstName}";
end
jsonResponse = userList.to_s(); /* returns the response in JSON format. (as shown below)*/
	
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick ",
                    "email": "nick@gmail.com",
                    "accountLocked": true,
                    "profile": {
                        "firstName": "Nick ",
                        "lastName": "Gill",
                        "sex": "Male",
                        "dateOfBirth": "2012-12-11T18:30:00.000Z",
                        "mobile": "+95890123457",
                        "officeLandLine": "+1-1800-111-999",
                        "homeLandLine": "+1-1800-877-453",
                        "line1": "300 Oxford Street",
                        "line2": "W1A 1EX ",
                        "city": "Tulsa",
                        "state": "Oklahoma",
                        "pincode": "74193",
                        "country": "USA"
                    }
                }
            }
        }
    }
}
def get_user_by_profile_data($profileData)

Get Users based on Profile Data.

Parameters:

profileData - Profile Data key/value for which Users need to be retrieved.

Returns:

List of User Object for the specified profile data.

Response: User Object

Exception:

The method throws the following exception with the error code

/*
2006 - NOT FOUND - Users do not exist.
*/
For more details click Exception
userName = "Nick";						
pwd = "********";
emailId = "nick@shephertz.com";
profileData = App42::User::User::Profile.new();
profileData.firstName = "Nick";
profileData.lastName = "Gill";

userList = userService.get_user_by_profile_data(profileData); /* returns the list of User objects. */
for user in userList do
  puts "UserName is #{user.userName}";
  puts "EmailId is #{user.email}";
end
jsonResponse = userList.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": [
                    {
                        "userName": "Nick",
                        "email": "nick@shephertz.com",
                        "accountLocked": false,
                        "profile": {
                            "firstName": "Nick",
                            "lastName": "Gill",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
							"mobile": "+1-1111-111-111",
							"officeLandLine": "+2-2222-222-222",
							"homeLandLine": "+3-3333-333-333",
							"line1": "300 Oxford Street",
							"line2": "W1A 1EX ",
							"city": "Tulsa",
							"state": "Oklahoma",
							"pincode": "74193",
							"country": "USA"
                        }
                    },
                    {
                        "userName": "Billy",
                        "email": "billy@shephertz.com",
                        "accountLocked": false,
                        "profile": {
                            "firstName": "Billy",
                            "lastName": "Bouden",
                            "sex": "Male",
                            "dateOfBirth": "2012-12-11T18:30:00.000Z",
                            "mobile": "+4-4444-444-444",
							"officeLandLine": "+5-5555-555-555",
							"homeLandLine": "+6-6666-666-666",
                            "line1": "300 Oxford Street2",
                            "line2": "W1A 1EX 2",
                            "city": "London",
                            "state": "State",
                            "pincode": "120981",
                            "country": "London"
                        }
                    }
                ]
            }
        }
    }
}
def reset_user_password(userName,pwd)

Updates the User password based on userName.Username cannot be updated.

Parameters:

userName - UserName which should be unique for the App.
password - new password reset by user.

Returns:

App42Response Object

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
userName = "Nick";
pwd = "******";	

response = userService.reset_user_password(userName,pwd); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "password": "xxxxx"
                }
            }
        }
    }
}
def revoke_role(userName, role)

Revokes the specified role from the user.

Parameters:

userName - UserName which should be unique for the App
role - Role for which User needs to be retrieved

Returns:

App42Response Object if user deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
2011 - NOT FOUND - Role '<role>' for the user '<userName>' does not exist.
*/
For more details click Exception
userName = "Nick";
role = "admin";	

response = userService.revoke_role(userName,role); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "role": "Admin"
                }
            }
        }
    }
}
def revoke_all_roles(userName)

Revokes the specified role from the user.

Parameters:

userName - UserName which should be unique for the App
role - Role for which User needs to be retrieved

Returns:

App42Response Object if user deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
2012 - Not Found - Roles for the user '<userName>' do not exist.
*/
For more details click Exception
userName = "Nick";

response = userService.revoke_all_roles(userName); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "role": [
                        {
                            "role": "Admin"
                        },
                        {
                            "role": "Manager"
                        },
                        {
                            "role": "Programmer"
                        },
                        {
                            "role": "Tester"
                        }
                    ]
                }
            }
        }
    }
}
def update_email(uName,emailId)

Updates the User based on userName.
Note: Only email can be updated. Username cannot be updated.

Parameters:

uName - UserName which should be unique for the App
emailId- Email address of the user

Returns:

Updated User Object

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
uName = "Nick";	
emailId = "almighty@gmail.com";	
					
user = userService.update_email(uName, emailId); /* returns the updated User object. */
puts "userName is #{user.userName}";
puts "email is #{user.email}";
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "email": "almighty@gmail.com"
                }
            }
        }
    }
}
def delete_user(userName)

Delete a particular user based on userName.

Parameters:

userName - UserName which should be unique for the App

Returns:

App42Response Object if user deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
userName = "Nick";
							
response = userService.delete_user(userName); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick"
                }
            }
        }
    }
}
def create_or_update_profile(user)

Creates or Updates User Profile.
Note: First time when the Profile for the user is created. In future calls user information will be updated.

Parameters:

user - User for which profile has to be updated

Returns:

User Object with updated Profile information

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
userName = "Nick";
email = "nick@shephertz.com";

user = userService.createUser(userName, "ssss", email);
profileObj = App42::User::User::Profile.new();
profileObj.officeLandLine = ("+1-1800-111-999");
profileObj.firstName = "Nick";
profileObj.dateOfBirth = "03-11-2012";
profileObj.country = ("USA");
profileObj.city = ("Houston");
profileObj.lastName = ("Gill");
profileObj.mobile = ("+958901234571");
profileObj.pincode = ("74193");
profileObj.sex = App42::User::User::UserGender.new.enum("MALE");
profileObj.homeLandLine = ("+1-1800-877-453");
profileObj.state = ("Texas");
user.profile= profileObj;

userObj = userService.createOrUpdateProfile(user);
puts "userName is #{userObj.userName}";
puts "email is #{userObj.email}";
puts "firstName #{userObj.profile.firstName}";
jsonResponse = userObj.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick ",
                    "email": "nick@shephertz.com",
                    "accountLocked": false,
                    "profile": {
                        "firstName": "Nick ",
                        "lastName": "Gill",
                        "sex": "Male",
                        "dateOfBirth": "2012-12-11T18:30:00.000Z",
                        "city": "Houston",
                        "state": "Texas",
                        "pincode": "74193",
                        "country": "USA",
                        "mobile": "+1-1111-111-111",
                        "officeLandLine": "+2-2222-222-222",
                        "homeLandLine": "+3-3333-333-333",
                    }
                }
            }
        }
    }
}
def authenticate_user(uName, pwd)

Authenticate user based on userName and password.

Parameters:

uName - UserName which should be unique for the App
pwd - Password for the User

Returns:

App42Response Object if authenticated successfully.

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
2002 - NOT FOUND - UserName/Password did not match. Authentication Failed. 
*/
For more details click Exception
userName = "Nick";
pwd = "*******";
						
response = userService.authenticate_user(uName, pwd); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "accountLocked": false
                }
            }
        }
    }
}
def unlock_user(uName)

Unlock the user based on the userName. Apps can use these feature to unlock a user because of reasons specific to their usercase e.g. If payment received and the App wants to the user to be active.

Parameters:

uName - UserName which should be unique for the App

Returns:

The unlocked User Object

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
uName = "Nick";

user = userService.unlock_user(uName); /* returns the unlocked User object. */
userName = user.userName();
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "accountLocked": false
                }
            }
        }
    }
}
def lock_user(uName)

Locks the user based on the userName. Apps can use these feature to lock a user because of reasons specific to their usercase e.g. If payment not received and the App wants the user to be inactive.

Parameters:

uName - UserName which should be unique for the App

Returns:

The locked User Object

Response: User Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
*/
For more details click Exception
uName = "Nick";

user = userService.lock_user(uName); /* returns the unlocked User object. */
userName = user.userName();
jsonResponse = user.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick",
                    "accountLocked": true
                }
            }
        }
    }
}
def change_user_password(uName,oldPwd,newPwd)

Change the password for user based on the userName. If the old password is valid.

Parameters:

uName - UserName which should be unique for the App
oldPwd - Old Password for the user for authentication
newPwd - New Password for the user to change

Returns:

App42Response Object if updated successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
2000 - NOT FOUND - User by the name '<userName>' does not exist.
2003 - BAD REQUEST - Old Password is not matching for user ''.  
*/
For more details click Exception
uName = "Nick";
oldPwd = "*******";
newPwd = "*******";
						
response = userService.change_user_password(uName, oldPwd, newPwd); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "users": {
                "user": {
                    "userName": "Nick"
                }
            }
        }
    }
}