Class: App42::User::UserService
- Inherits:
-
Object
- Object
- App42::User::UserService
- Defined in:
- lib/user/UserService.rb
Overview
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
Instance Method Summary collapse
-
#assign_roles(uName, roleList) ⇒ Object
Add Role for the App.
-
#authenticate(uName, pwd) ⇒ Object
Authenticate user based on userName and password.
-
#change_user_password(uName, oldPwd, newPwd) ⇒ Object
Change the password for user based on the userName.
-
#create_or_update_profile(user) ⇒ Object
Creates or Updates User Profile.
-
#create_user(uName, pwd, emailAddress) ⇒ Object
Create User for the App.
-
#create_user_with_role(uName, pwd, emailAddress, roleList) ⇒ Object
Create User for the App.
-
#delete_user(userName) ⇒ Object
Deletes a particular user based on userName.
-
#fill_params_with_profile_data(profileData) ⇒ Object
Builds a Parameter string from the profileData.
-
#get_all_users ⇒ Object
Gets All users details.
-
#get_all_users_by_paging(max, offset) ⇒ Object
Gets All users By Paging.
-
#get_all_users_count ⇒ Object
Gets the count of all the users.
-
#get_locked_users ⇒ Object
Gets All the locked users details.
-
#get_locked_users_by_paging(max, offset) ⇒ Object
Gets All the locked users By paging details.
-
#get_locked_users_count ⇒ Object
Gets the count of all the locked users.
-
#get_roles_by_user(userName) ⇒ Object
Get Roles based on userName.
-
#get_user(userName) ⇒ Object
Gets user details based on userName.
-
#get_user_by_email_id(emailId) ⇒ Object
Gets user details based on emailId.
-
#get_users_by_profile_data(profileData) ⇒ Object
Get Users based on Profile Data.
-
#get_users_by_role(role) ⇒ Object
Get Users based on Role.
-
#initialize(api_key, secret_key, base_url) ⇒ UserService
constructor
this is a constructor that takes.
-
#lock_user(uName) ⇒ Object
Locks the user based on the userName.
-
#reset_user_password(uName, password) ⇒ Object
Updates the User based on userName.
-
#revoke_all_roles(userName) ⇒ Object
Revokes the specified role from the user.
-
#revoke_role(userName, role) ⇒ Object
Revokes the specified role from the user.
-
#unlock_user(uName) ⇒ Object
Unlock the user based on the userName.
-
#update_email(uName, emailAddress) ⇒ Object
Updates the User based on userName.
Constructor Details
#initialize(api_key, secret_key, base_url) ⇒ UserService
this is a constructor that takes
35 36 37 38 39 40 41 42 |
# File 'lib/user/UserService.rb', line 35 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 |
Instance Method Details
#assign_roles(uName, roleList) ⇒ Object
Add Role for the App
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 |
# File 'lib/user/UserService.rb', line 1151 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., } 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 |
#authenticate(uName, pwd) ⇒ Object
Authenticate user based on userName and password
if authentication fails or username/password is blank or null
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/user/UserService.rb', line 357 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., } 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 |
#change_user_password(uName, oldPwd, newPwd) ⇒ Object
Change the password for user based on the userName.
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/user/UserService.rb', line 687 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., } 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 |
#create_or_update_profile(user) ⇒ Object
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.
contain the userName and profile object in it.
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/user/UserService.rb', line 286 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.(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., } 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 |
#create_user(uName, pwd, emailAddress) ⇒ Object
Create User for the App
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/user/UserService.rb', line 59 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., } 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 |
#create_user_with_role(uName, pwd, emailAddress, roleList) ⇒ Object
Create User for the App
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/user/UserService.rb', line 822 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., } 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 |
#delete_user(userName) ⇒ Object
Deletes a particular user based on userName.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/user/UserService.rb', line 234 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., } 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 |
#fill_params_with_profile_data(profileData) ⇒ Object
Builds a Parameter string from the profileData.
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/user/UserService.rb', line 1207 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 |
#get_all_users ⇒ Object
Gets All users details
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/user/UserService.rb', line 151 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., } 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 |
#get_all_users_by_paging(max, offset) ⇒ Object
Gets All users By Paging
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/user/UserService.rb', line 591 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., } 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 |
#get_all_users_count ⇒ Object
Gets the count of all the users
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/user/UserService.rb', line 736 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., } 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 |
#get_locked_users ⇒ Object
Gets All the locked users details
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/user/UserService.rb', line 402 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., } 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 |
#get_locked_users_by_paging(max, offset) ⇒ Object
Gets All the locked users By paging details
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'lib/user/UserService.rb', line 638 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., } 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 |
#get_locked_users_count ⇒ Object
Gets the count of all the locked users
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 |
# File 'lib/user/UserService.rb', line 774 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., } 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 |
#get_roles_by_user(userName) ⇒ Object
Get Roles based on userName
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
# File 'lib/user/UserService.rb', line 883 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., } 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_user(userName) ⇒ Object
Gets user details based on userName
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/user/UserService.rb', line 112 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., } 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 |
#get_user_by_email_id(emailId) ⇒ Object
Gets user details based on emailId
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/user/UserService.rb', line 191 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., } 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 |
#get_users_by_profile_data(profileData) ⇒ Object
Get Users based on Profile Data
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'lib/user/UserService.rb', line 1055 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., } 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 |
#get_users_by_role(role) ⇒ Object
Get Users based on Role
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
# File 'lib/user/UserService.rb', line 926 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., } 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 |
#lock_user(uName) ⇒ Object
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
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/user/UserService.rb', line 496 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., } 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 |
#reset_user_password(uName, password) ⇒ Object
Updates the User based on userName. Note: Only email can be updated. Username cannot be updated.
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
# File 'lib/user/UserService.rb', line 1101 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., } 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 |
#revoke_all_roles(userName) ⇒ Object
Revokes the specified role from the user.
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'lib/user/UserService.rb', line 1013 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., } 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 |
#revoke_role(userName, role) ⇒ Object
Revokes the specified role from the user.
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 |
# File 'lib/user/UserService.rb', line 969 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., } 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 |
#unlock_user(uName) ⇒ Object
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.
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/user/UserService.rb', line 543 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., } 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 |
#update_email(uName, emailAddress) ⇒ Object
Updates the User based on userName. Note: Only email can be updated. Username cannot be updated.
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/user/UserService.rb', line 445 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., } 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 |