Method: App42::User::UserService#create_user_with_role
- Defined in:
- lib/user/UserService.rb
#create_user_with_role(user_name, pwd, email_address, role_list) ⇒ Object
Create User for the App
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'lib/user/UserService.rb', line 799 def create_user_with_role(user_name, pwd, email_address, role_list) puts "Create User Called " puts "Base url #{@base_url}" response, usr = nil usr, util = User.new, Util.new util.throwExceptionIfNullOrBlank(user_name, "UserName") util.throwExceptionIfNullOrBlank(pwd, "Password") util.throwExceptionIfEmailNotValid(email_address, "EmailAddress") util.throwExceptionIfNullOrBlank(email_address, "EmailAddress") util.throwExceptionIfNullOrBlank(role_list, "RoleList") raise App42Exception.new("RoleList cannot be empty.Please assign at least one role") if role_list.size == 0 begin connection = App42::Connection::RESTConnection.new(@base_url) role_array = [] for role in role_list do role_array.push(role) end body = {'app42' => {"user"=> { "email" => email_address, "password" => pwd, "userName" => user_name, "roles" => { "role" => role_array }}}}.to_json puts "Body #{body}" query_params = {} params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., } 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 |