# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'rubygems' require 'connection/RESTConnection.rb' require 'util/util.rb' require 'json/pure' require 'App42Response.rb' require 'user/UserResponseBuilder.rb' require 'user/User.rb' module App42 module 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 # # @see SessionService # @see User # @see App42Response # class UserService # # this is a constructor that takes # # @param apiKey # @param secretKey # @param baseURL # def initialize(api_key, secret_key, base_url) puts "UserService->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "user" @version = "1.0" end # # Create User for the App # # @param uName # - UserName which should be unique for the App # @param pwd # - Password for the User # @param emailAddress # - Email address of the user # # @return The created User Object. # # @raise App42Exception # def create_user(uName, pwd, emailAddress) puts "Create User Called " puts "Base url #{@base_url}" response = nil usr = nil usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(pwd, "Password"); util.throwExceptionIfEmailNotValid(emailAddress, "EmailAddress"); util.throwExceptionIfNullOrBlank(emailAddress, "EmailAddress"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName, "password" => pwd, "email" => emailAddress }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) puts params puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.post(signature, resource_url, query_params, body) user = UserResponseBuilder.new() usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Gets user details based on userName # # @param userName # - UserName which should be unique for the App # # @return Returns User Object # # @raise App42Exception # def get_user(userName) puts "Get User Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("userName", userName) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Gets All users details # # @return Returns the list that contains all User Object # # @raise App42Exception # def get_all_users() puts "Get All Users Called" puts "Base url #{@base_url}" response = nil; userList = nil userList = Array.new util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new userList = user.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return userList end # # Gets user details based on emailId # # @param emailId # - EmailId of the user to be retrieved # # @return Returns User Object # # @raise App42Exception # def get_user_by_email_id(emailId) puts "Get All Users Called" puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfEmailNotValid(emailId, "EmailId"); util.throwExceptionIfNullOrBlank(emailId, "EmailId"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("emailId", emailId) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/email/#{emailId}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Deletes a particular user based on userName. # # @param userName # - UserName which should be unique for the App # # @return App42Response Object if user deleted successfully # # @raise App42Exception # def delete_user(userName) puts "Delete User Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("userName", userName) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}" response = connection.delete(signature, resource_url, query_params) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Creates or Updates User Profile. First time the Profile for the user is # created and in future calls user profile will be updated. This will # always update the profile with new value passed in profile object. Call # to this method should have all the values you want to retain in user # profile object, otherwise old values of profile will get updated with # null. # # Method only updates the profile of user, passing email/password in user # object does not have any significance for this method call. # # @param user # - User for which profile has to be updated, this should # contain the userName and profile object in it. # # @return User Object with updated Profile information # # @raise App42Exception # # @see Profile # def create_or_update_profile(user) puts "Base url #{@base_url}" response = nil; userResponse = nil; userResponse = User.new util = Util.new util.throwExceptionIfNullOrBlank(user, "User") util.throwExceptionIfNullOrBlank(user.userName, "UserName"); util.throwExceptionIfNullOrBlank(user.profile, "Profile Data"); begin connection = App42::Connection::RESTConnection.new(@base_url) profile = user.profile(); profileObj = Hash.new profileObj.store("firstName", profile.firstName()); profileObj.store("lastName", profile.lastName()); profileObj.store("sex", profile.sex()); profileObj.store("mobile", profile.mobile()); profileObj.store("line1", profile.line1()); profileObj.store("line2", profile.line2()); profileObj.store("city", profile.city()); profileObj.store("state", profile.state()); profileObj.store("country", profile.country()); profileObj.store("pincode", profile.pincode()); profileObj.store("homeLandLine", profile.homeLandLine()); profileObj.store("officeLandLine", profile.officeLandLine()); if profile.dateOfBirth != nil profileObj.store("dateOfBirth", util.get_timestamp_utc_from_date(profile.dateOfBirth)) end body = { 'app42'=>{"user"=>{ "userName"=>user.userName, "profileData"=>profileObj } } }.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/profile" response = connection.put(signature, resource_url, query_params, body) user = UserResponseBuilder.new userResponse = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise e end return userResponse end # # Authenticate user based on userName and password # # @param uName # - UserName which should be unique for the App # @param pwd # - Password for the User # # @return Whether the user is authenticated or not. # # @raise App42Exception # if authentication fails or username/password is blank or null # def authenticate(uName, pwd) puts "authenticateUser Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(pwd, "Password"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName, "password" => pwd }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/authenticate" response = connection.post(signature, resource_url, query_params, body) user = UserResponseBuilder.new usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise e end return usr end # # Gets All the locked users details # # @return Returns the list that contains locked User Objects # # @raise App42Exception # def get_locked_users() puts "Get Locked Users Called" puts "Base url #{@base_url}" response = nil; userList = nil; userList = Array.new util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/locked" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new userList = user.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return userList end # # Updates the User based on userName. # Note: Only email can be updated. Username cannot be updated. # # @param uName # - UserName which should be unique for the App # @param emailAddress # - Email address of the user # # @return updated User Object # # @raise App42Exception # def update_email(uName, emailAddress) puts "Update User Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(emailAddress, "EmailAddress"); util.throwExceptionIfNullOrBlank(emailAddress, "Email Address"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName, "email" => emailAddress }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.put(signature, resource_url, query_params, body) user = UserResponseBuilder.new usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # 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 # # @param uName # - UserName which should be unique for the App # # @return Returns the locked User Object # # @raise App42Exception # def lock_user(uName) puts "Lock User Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/lock" response = connection.put(signature, resource_url, query_params, body) user = UserResponseBuilder.new usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # 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. # # @param uName # - UserName which should be unique for the App # # @return Returns the unlocked User Object # # @raise App42Exception # def unlock_user(uName) puts "unlockUser Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/unlock" response = connection.put(signature, resource_url, query_params, body) user = UserResponseBuilder.new usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Gets All users By Paging # # @param max # - Maximum number of records to be fetched # @param offset # - From where the records are to be fetched # # @return Returns User Information # # @raise App42Exception # def get_all_users_by_paging(max, offset) puts "getAllUsersByPaging Called " puts "Base url #{@base_url}" response = nil; usr = nil; userList = User.new util = Util.new util.validateMax(max); util.throwExceptionIfNullOrBlank(max, "Max"); util.throwExceptionIfNullOrBlank(offset, "Offset"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("max", "" + (max.to_i).to_s) params.store("offset", "" + (offset.to_i).to_s) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new userList = user.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return userList end # # Gets All the locked users By paging details # # @param max # - Maximum number of records to be fetched # @param offset # - From where the records are to be fetched # # @return Returns User Information # # @raise App42Exception # def get_locked_users_by_paging(max, offset) puts "get_locked_users_by_paging Called " puts "Base url #{@base_url}" response = nil; usr = nil; userList = User.new util = Util.new util.validateMax(max); util.throwExceptionIfNullOrBlank(max, "Max"); util.throwExceptionIfNullOrBlank(offset, "Offset"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("max", "" + (max.to_i).to_s) params.store("offset", "" + (offset.to_i).to_s) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/locked/#{(max.to_i).to_s}/#{(offset.to_i).to_s}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new userList = user.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return userList end # # Change the password for user based on the userName. # # @param uName # - UserName which should be unique for the App # @param oldPwd # - Old Password for the user for authentication # @param newPwd # - New Password for the user to change # # @return App42Response Object if updated successfully # # @raise App42Exception # def change_user_password(uName, oldPwd, newPwd) puts "changeUserPassword Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(oldPwd, "Old Password"); util.throwExceptionIfNullOrBlank(newPwd, "New Password"); responseObj = App42Response.new if(oldPwd == newPwd) raise App42Exception.new("Old password and new password are same") end begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName, "oldPassword" => oldPwd, "newPassword" => newPwd }}}.to_json query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/changeUserPassword" response = connection.put(signature, resource_url, query_params, body) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Gets the count of all the users # # @return Returns the count of all User exists # # @raise App42Exception # def get_all_users_count() puts "getAllUsersCount Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/count/all" response = connection.get(signature, resource_url, query_params) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) responseObj = UserResponseBuilder.new() responseObj.getTotalRecords(response); rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Gets the count of all the locked users # # @return Returns the count of locked User exists # # @raise App42Exception # def get_locked_users_count() puts "getLockedUsersCount Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/count/locked" response = connection.get(signature, resource_url, query_params) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) responseObj = UserResponseBuilder.new() responseObj.getTotalRecords(response); rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Create User for the App # # @param uName # - UserName which should be unique for the App # @param pwd # - Password for the User # @param emailAddress # - Email address of the user # @param roleList # - list of roles to be assigned to User # # @return The created User Object. # # @raise App42Exception # def create_user_with_role(uName, pwd, emailAddress, roleList) puts "Create User Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(pwd, "Password"); util.throwExceptionIfEmailNotValid(emailAddress, "EmailAddress"); util.throwExceptionIfNullOrBlank(emailAddress, "EmailAddress"); util.throwExceptionIfNullOrBlank(roleList, "RoleList"); if roleList.size() == 0 raise App42Exception.new("RoleList cannot be empty.Please assign at least one role"); end begin connection = App42::Connection::RESTConnection.new(@base_url) roleArray = Array.new for role in roleList do roleArray.push(role) end body = {'app42' => {"user"=> { "email" => emailAddress, "password" => pwd, "userName" => uName, "roles" => { "role" => roleArray }}}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/role" response = connection.post(signature, resource_url, query_params, body) user = UserResponseBuilder.new() usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Get Roles based on userName # # @param userName # - UserName which should be unique for the App # # @return Returns User Object # # @raise App42Exception # def get_roles_by_user(userName) puts "getRolesByUser Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("userName", userName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}/roles" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new() usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Get Users based on Role # # @param role # - Role which should be unique for the App # # @return Returns User Object # # @raise App42Exception # def get_users_by_role(role) puts "get_users_by_role Called " puts "Base url #{@base_url}" response = nil; usr = nil; userList = Array.new util = Util.new util.throwExceptionIfNullOrBlank(role, "Role"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("role", role) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/role/#{role}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new() userList = user.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return userList end # # Revokes the specified role from the user. # # @param userName # - UserName which should be unique for the App # # @return App42Response Object if user deleted successfully # # @raise App42Exception # def revoke_role(userName, role) puts "revoke_role Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); util.throwExceptionIfNullOrBlank(role, "Role"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("role", role) params.store("userName", userName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}/revoke/#{role}" response = connection.delete(signature, resource_url, query_params) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Revokes the specified role from the user. # # @param userName # - UserName which should be unique for the App # # @return App42Response Object if user deleted successfully # # @raise App42Exception # def revoke_all_roles(userName) puts "revoke_all_roles Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(userName, "UserName"); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("userName", userName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{userName}/revoke" response = connection.delete(signature, resource_url, query_params) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Get Users based on Profile Data # # @param profileData # - Profile Data key/value for which Users need to be retrieved # # @return Returns Arraylist of User Object for that particular role # # @raise App42Exception # def get_users_by_profile_data(profileData) puts "get_users_by_profile_data Called " puts "Base url #{@base_url}" response = nil; userList = nil; userList = Array.new util = Util.new parameters = ""; parameters = fill_params_with_profile_data(profileData); begin connection = App42::Connection::RESTConnection.new(@base_url) query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/profile/#{parameters}" response = connection.get(signature, resource_url, query_params) user = UserResponseBuilder.new() userList = user.buildArrayResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return userList end # # Updates the User based on userName. Note: Only email can be updated. # Username cannot be updated. # # @param uName # - UserName which should be unique for the App # @param emailAddress # - Email address of the user # # @return updated User Object # # @raise App42Exception # def reset_user_password(uName,password) puts "resetUserPassword Called " puts "Base url #{@base_url}" response = nil; responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(password, "password"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"user"=> { "userName" => uName, "password" => password }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/resetUserPassword" response = connection.put(signature, resource_url, query_params, body) responseObj.strResponse=(response) responseObj.isResponseSuccess=(true) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return responseObj end # # Add Role for the App # # @param uName # - UserName which should be unique for the App # @param roleList # - list of roles to be added to User # # @return The created User Object. # # @raise App42Exception # def assign_roles(uName, roleList) puts "assignRoles Called " puts "Base url #{@base_url}" response = nil; usr = nil; usr = User.new util = Util.new util.throwExceptionIfNullOrBlank(uName, "UserName"); util.throwExceptionIfNullOrBlank(roleList, "RoleList"); if roleList.size() == 0 raise App42Exception.new("RoleList cannot be empty.Please assign at least one role"); end begin connection = App42::Connection::RESTConnection.new(@base_url) roleArray = Array.new for role in roleList do roleArray.push(role) end body = {'app42' => {"user"=> { "userName" => uName, "roles" => { "role" => roleArray }}}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util.get_timestamp_utc, } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/assignrole" response = connection.post(signature, resource_url, query_params, body) user = UserResponseBuilder.new() usr = user.buildResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return usr end # # Builds a Parameter string from the profileData. # # @param profileData # - User.Profile object that contains User's Profile information # # @return String Object which contains the parameter string. # # @raise App42Exception # def fill_params_with_profile_data(profileData) profileDataCond = ""; if profileData.city != nil && !profileData.city != "" profileDataCond += "city:"+ profileData.city()+"!"; end if profileData.country != nil && !profileData.country != "" profileDataCond += "country:"+ profileData.country()+"!"; end if profileData.dateOfBirth != nil && !profileData.dateOfBirth != "" profileDataCond += "date_of_birth:"+ profileData.dateOfBirth()+"!"; end if profileData.firstName != nil && !profileData.firstName != "" profileDataCond += "first_name:"+ profileData.firstName()+"!"; end if profileData.lastName != nil && !profileData.lastName != "" profileDataCond += "last_name:"+ profileData.lastName()+"!"; end if profileData.homeLandLine != nil && !profileData.homeLandLine != "" profileDataCond += "home_land_line:"+ profileData.homeLandLine()+"!"; end if profileData.line1 != nil && !profileData.line1 != "" profileDataCond += "line1:"+ profileData.line1()+"!"; end if profileData.line2() != nil && !profileData.line2 != "" profileDataCond += "line2:"+ profileData.line2()+"!"; end if profileData.mobile != nil && !profileData.mobile != "" profileDataCond += "mobile:"+ profileData.mobile()+"!"; end if profileData.officeLandLine() != nil && !profileData.officeLandLine.equals("") profileDataCond += "office_land_line:"+ profileData.officeLandLine()+"!"; end if profileData.pincode != nil && !profileData.pincode != "" profileDataCond += "pincode:"+ profileData.pincode()+"!"; end if profileData.sex != nil && !profileData.sex != "" profileDataCond += "sex:"+ profileData.sex()+"!"; end if profileData.state != nil && !profileData.state != "" profileDataCond += "state:"+ profileData.state()+"!"; end return profileDataCond; end end end end