App42_RUBY_SDK 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/App42_RUBY_SDK.gemspec +31 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/lib/App42BadParameterException.rb +31 -0
- data/lib/App42Exception.rb +39 -0
- data/lib/App42LimitException.rb +15 -0
- data/lib/App42NotFoundException.rb +15 -0
- data/lib/App42Response.rb +13 -0
- data/lib/App42ResponseBuilder.rb +64 -0
- data/lib/App42SecurityException.rb +15 -0
- data/lib/App42_RUBY_SDK.rb +236 -0
- data/lib/App42_RUBY_SDK/version.rb +3 -0
- data/lib/ServiceAPI.rb +246 -0
- data/lib/appTab/App.rb +105 -0
- data/lib/appTab/BandwidthUnit.rb +57 -0
- data/lib/appTab/Bill.rb +182 -0
- data/lib/appTab/BillMonth.rb +94 -0
- data/lib/appTab/BillResponseBuilder.rb +242 -0
- data/lib/appTab/BillService.rb +457 -0
- data/lib/appTab/Currency.rb +79 -0
- data/lib/appTab/DiscountResponseBuilder.rb +71 -0
- data/lib/appTab/DiscountService.rb +240 -0
- data/lib/appTab/DiscountType.rb +54 -0
- data/lib/appTab/License.rb +25 -0
- data/lib/appTab/LicenseResponseBuilder.rb +88 -0
- data/lib/appTab/LicenseService.rb +399 -0
- data/lib/appTab/PackageData.rb +83 -0
- data/lib/appTab/PackageResponseBuilder.rb +114 -0
- data/lib/appTab/PackageService.rb +506 -0
- data/lib/appTab/SchemeData.rb +11 -0
- data/lib/appTab/SchemeResponseBuilder.rb +70 -0
- data/lib/appTab/SchemeService.rb +151 -0
- data/lib/appTab/StorageUnit.rb +54 -0
- data/lib/appTab/SubscribeService.rb +180 -0
- data/lib/appTab/Test.rb +41 -0
- data/lib/appTab/TimeUnit.rb +49 -0
- data/lib/appTab/Usage.rb +206 -0
- data/lib/appTab/UsageResponseBuilder.rb +152 -0
- data/lib/appTab/UsageService.rb +1799 -0
- data/lib/connection/RESTConnection.rb +711 -0
- data/lib/email/Email.rb +51 -0
- data/lib/email/EmailMIME.rb +51 -0
- data/lib/email/EmailResponseBuilder.rb +76 -0
- data/lib/email/EmailService.rb +244 -0
- data/lib/gallery/Album.rb +56 -0
- data/lib/gallery/AlbumResponseBuilder.rb +168 -0
- data/lib/gallery/AlbumService.rb +337 -0
- data/lib/gallery/PhotoService.rb +591 -0
- data/lib/game/Game.rb +39 -0
- data/lib/game/GameResponseBuilder.rb +106 -0
- data/lib/game/GameService.rb +268 -0
- data/lib/game/Reward.rb +24 -0
- data/lib/game/RewardResponseBuilder.rb +85 -0
- data/lib/game/RewardService.rb +440 -0
- data/lib/game/ScoreBoardService.rb +433 -0
- data/lib/game/ScoreService.rb +157 -0
- data/lib/geo/Geo.rb +51 -0
- data/lib/geo/GeoPoint.rb +43 -0
- data/lib/geo/GeoResponseBuilder.rb +145 -0
- data/lib/geo/GeoService.rb +506 -0
- data/lib/imageProcessor/Image.rb +42 -0
- data/lib/imageProcessor/ImageProcessorResponseBuilder.rb +40 -0
- data/lib/imageProcessor/ImageProcessorService.rb +1054 -0
- data/lib/log/Log.rb +49 -0
- data/lib/log/LogResponseBuilder.rb +61 -0
- data/lib/log/LogService.rb +920 -0
- data/lib/message/Queue.rb +50 -0
- data/lib/message/QueueResponseBuilder.rb +64 -0
- data/lib/message/QueueService.rb +469 -0
- data/lib/push/DeviceType.rb +56 -0
- data/lib/push/PushNotification.rb +38 -0
- data/lib/push/PushNotificationResposneBuilder.rb +74 -0
- data/lib/push/PushNotificationService.rb +458 -0
- data/lib/recommend/PreferenceData.rb +25 -0
- data/lib/recommend/Recommender.rb +48 -0
- data/lib/recommend/RecommenderResponseBuilder.rb +70 -0
- data/lib/recommend/RecommenderService.rb +1092 -0
- data/lib/recommend/RecommenderSimilarity.rb +52 -0
- data/lib/review/Review.rb +38 -0
- data/lib/review/ReviewResponseBuilder.rb +76 -0
- data/lib/review/ReviewService.rb +590 -0
- data/lib/session/Session.rb +43 -0
- data/lib/session/SessionResponseBuilder.rb +70 -0
- data/lib/session/SessionService.rb +427 -0
- data/lib/shopping/Cart.rb +77 -0
- data/lib/shopping/CartResponseBuilder.rb +118 -0
- data/lib/shopping/CartService.rb +902 -0
- data/lib/shopping/Catalogue.rb +79 -0
- data/lib/shopping/CatalogueResponseBuilder.rb +170 -0
- data/lib/shopping/CatalogueService.rb +649 -0
- data/lib/shopping/ItemData.rb +29 -0
- data/lib/shopping/PaymentStatus.rb +60 -0
- data/lib/social/Social.rb +35 -0
- data/lib/social/SocialResponseBuilder.rb +38 -0
- data/lib/social/SocialService.rb +585 -0
- data/lib/storage/OrderByType.rb +29 -0
- data/lib/storage/Query.rb +39 -0
- data/lib/storage/QueryBuilder.rb +118 -0
- data/lib/storage/Storage.rb +45 -0
- data/lib/storage/StorageResponseBuilder.rb +86 -0
- data/lib/storage/StorageService.rb +775 -0
- data/lib/upload/Upload.rb +40 -0
- data/lib/upload/UploadFileType.rb +83 -0
- data/lib/upload/UploadResponseBuilder.rb +58 -0
- data/lib/upload/UploadService.rb +960 -0
- data/lib/user/User.rb +102 -0
- data/lib/user/UserResponseBuilder.rb +105 -0
- data/lib/user/UserService.rb +1253 -0
- data/lib/util/util.rb +250 -0
- metadata +134 -9
- checksums.yaml +0 -7
data/lib/user/User.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'App42Response.rb'
|
6
|
+
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# This User object is the value object which contains the properties of User
|
10
|
+
# along with the setter & getter for those properties.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
module App42
|
15
|
+
module User
|
16
|
+
class User < App42Response
|
17
|
+
attr_accessor :userName, :password,:email, :profile, :accountLocked, :roleList
|
18
|
+
|
19
|
+
@userName
|
20
|
+
@password
|
21
|
+
@email
|
22
|
+
@profile
|
23
|
+
@roleList = Array.new()
|
24
|
+
@accountLocked = false
|
25
|
+
#
|
26
|
+
# Returns the User Response in JSON format.
|
27
|
+
#
|
28
|
+
# @return the response in JSON format.
|
29
|
+
#
|
30
|
+
#
|
31
|
+
def to_s
|
32
|
+
return strResponse
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# An enum that contains the User Gender either MALE or FEMALE.
|
37
|
+
#
|
38
|
+
#
|
39
|
+
|
40
|
+
class UserGender
|
41
|
+
unless (const_defined?(:MALE))
|
42
|
+
MALE ="Male"
|
43
|
+
end
|
44
|
+
unless (const_defined?(:FEMALE))
|
45
|
+
FEMALE = "Female"
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Sets the value of the UserGender. MALE or FEMALE.
|
50
|
+
#
|
51
|
+
# @param value
|
52
|
+
# - the value of UserGender either MALE or FEMALE.
|
53
|
+
#
|
54
|
+
def enum(string)
|
55
|
+
return UserGender.const_get(string)
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Returns the value of the UserGender. MALE or FEMALE.
|
60
|
+
#
|
61
|
+
# @return the value of UserGender.
|
62
|
+
#
|
63
|
+
#
|
64
|
+
|
65
|
+
def isAvailable(string)
|
66
|
+
if(string == "Male")
|
67
|
+
return "Male"
|
68
|
+
elsif(string == "Female")
|
69
|
+
return "Female";
|
70
|
+
else
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Profile
|
79
|
+
attr_accessor :firstName, :lastName,:mobile,:line1,:line2,:city,:state,:country,:pincode,:homeLandLine,:officeLandLine,:sex,:dateOfBirth
|
80
|
+
@firstName
|
81
|
+
@lastName
|
82
|
+
@mobile
|
83
|
+
@line1
|
84
|
+
@line2
|
85
|
+
@city
|
86
|
+
@state
|
87
|
+
@country
|
88
|
+
@pincode
|
89
|
+
@homeLandLine
|
90
|
+
@officeLandLine
|
91
|
+
@sex
|
92
|
+
@dateOfBirth
|
93
|
+
#
|
94
|
+
# This is a constructor that takes no parameter
|
95
|
+
#
|
96
|
+
def initialize(user)
|
97
|
+
user.profile = (self)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'json/pure'
|
6
|
+
require 'App42ResponseBuilder.rb'
|
7
|
+
require 'user/User.rb'
|
8
|
+
|
9
|
+
module App42
|
10
|
+
module User
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# UserResponseBuilder class converts the JSON response retrieved from the
|
14
|
+
# server to the value object i.e User
|
15
|
+
#
|
16
|
+
#
|
17
|
+
class UserResponseBuilder < App42ResponseBuilder
|
18
|
+
|
19
|
+
#
|
20
|
+
# Converts the response in JSON format to the value object i.e User
|
21
|
+
#
|
22
|
+
# @param json
|
23
|
+
# - response in JSON format
|
24
|
+
#
|
25
|
+
# @return User object filled with json data
|
26
|
+
#
|
27
|
+
def buildResponse(json)
|
28
|
+
usersJSONObj = getServiceJSONObject("users", json)
|
29
|
+
userJSOnObj = usersJSONObj["user"]
|
30
|
+
user = buildUserObject(userJSOnObj);
|
31
|
+
user.strResponse=json
|
32
|
+
user.isResponseSuccess = isResponseSuccess(json)
|
33
|
+
return user
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Converts the User JSON object to the value object i.e User
|
38
|
+
#
|
39
|
+
# @param userJSONObj
|
40
|
+
# - user data as JSONObject
|
41
|
+
#
|
42
|
+
# @return User object filled with json data
|
43
|
+
#
|
44
|
+
#
|
45
|
+
|
46
|
+
def buildUserObject(userJSONObj)
|
47
|
+
user = User.new
|
48
|
+
buildObjectFromJSONTree(user,userJSONObj)
|
49
|
+
|
50
|
+
if userJSONObj.key?('profile')
|
51
|
+
profileJSONObj = userJSONObj["profile"]
|
52
|
+
profile = App42::User::Profile.new(user)
|
53
|
+
buildObjectFromJSONTree(profile, profileJSONObj);
|
54
|
+
end
|
55
|
+
|
56
|
+
if userJSONObj.key?("role")
|
57
|
+
roleList = Array.new
|
58
|
+
if userJSONObj.fetch("role").instance_of?(Array)
|
59
|
+
roleArr = userJSONObj.fetch("role");
|
60
|
+
roleArr.length.times do |i|
|
61
|
+
roleList.push(roleArr.fetch(i))
|
62
|
+
end
|
63
|
+
else
|
64
|
+
roleList.push(userJSONObj.fetch("role"));
|
65
|
+
end
|
66
|
+
user.roleList = roleList
|
67
|
+
end
|
68
|
+
return user;
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Converts the response in JSON format to the list of value objects i.e User
|
73
|
+
#
|
74
|
+
# @param json
|
75
|
+
# - response in JSON format
|
76
|
+
#
|
77
|
+
# @return List of User object filled with json data
|
78
|
+
#
|
79
|
+
|
80
|
+
def buildArrayResponse(json)
|
81
|
+
usersJSONObj = getServiceJSONObject("users", json);
|
82
|
+
userList = Array.new
|
83
|
+
|
84
|
+
if usersJSONObj["user"].instance_of?(Array)
|
85
|
+
userJSONArray = usersJSONObj["user"]
|
86
|
+
userJSONArray.length.times do |i|
|
87
|
+
userJSONObject = userJSONArray[i]
|
88
|
+
user = buildUserObject(userJSONObject);
|
89
|
+
user.strResponse=json
|
90
|
+
user.isResponseSuccess = isResponseSuccess(json)
|
91
|
+
userList.push(user)
|
92
|
+
end
|
93
|
+
else
|
94
|
+
userJSONObject = usersJSONObj["user"]
|
95
|
+
user = buildUserObject(userJSONObject);
|
96
|
+
user.strResponse=json
|
97
|
+
user.isResponseSuccess = isResponseSuccess(json)
|
98
|
+
userList.push(user)
|
99
|
+
end
|
100
|
+
return userList
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,1253 @@
|
|
1
|
+
# -----------------------------------------------------------------------
|
2
|
+
# Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
|
3
|
+
# -----------------------------------------------------------------------
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'connection/RESTConnection.rb'
|
7
|
+
require 'util/util.rb'
|
8
|
+
require 'json/pure'
|
9
|
+
require 'App42Response.rb'
|
10
|
+
require 'user/UserResponseBuilder.rb'
|
11
|
+
require 'user/User.rb'
|
12
|
+
|
13
|
+
module App42
|
14
|
+
module User
|
15
|
+
#
|
16
|
+
# Creates User for the App. App42 Cloud API's provides a complete User
|
17
|
+
# Management for any Mobile or Web App. It supports User registration,
|
18
|
+
# retrieval, state management e.g. lock, delete and Authentication.
|
19
|
+
#
|
20
|
+
# Along with User Management the platform provides API's for persistent
|
21
|
+
# SessionManagement
|
22
|
+
#
|
23
|
+
# @see SessionService
|
24
|
+
# @see User
|
25
|
+
# @see App42Response
|
26
|
+
#
|
27
|
+
class UserService
|
28
|
+
#
|
29
|
+
# this is a constructor that takes
|
30
|
+
#
|
31
|
+
# @param apiKey
|
32
|
+
# @param secretKey
|
33
|
+
# @param baseURL
|
34
|
+
#
|
35
|
+
def initialize(api_key, secret_key, base_url)
|
36
|
+
puts "UserService->initialize"
|
37
|
+
@api_key = api_key
|
38
|
+
@secret_key = secret_key
|
39
|
+
@base_url = base_url
|
40
|
+
@resource = "user"
|
41
|
+
@version = "1.0"
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Create User for the App
|
46
|
+
#
|
47
|
+
# @param uName
|
48
|
+
# - UserName which should be unique for the App
|
49
|
+
# @param pwd
|
50
|
+
# - Password for the User
|
51
|
+
# @param emailAddress
|
52
|
+
# - Email address of the user
|
53
|
+
#
|
54
|
+
# @return The created User Object.
|
55
|
+
#
|
56
|
+
# @raise App42Exception
|
57
|
+
#
|
58
|
+
|
59
|
+
def create_user(uName, pwd, emailAddress)
|
60
|
+
puts "Create User Called "
|
61
|
+
puts "Base url #{@base_url}"
|
62
|
+
response = nil
|
63
|
+
usr = nil
|
64
|
+
usr = User.new
|
65
|
+
util = Util.new
|
66
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
67
|
+
util.throwExceptionIfNullOrBlank(pwd, "Password");
|
68
|
+
util.throwExceptionIfEmailNotValid(emailAddress, "EmailAddress");
|
69
|
+
util.throwExceptionIfNullOrBlank(emailAddress, "EmailAddress");
|
70
|
+
begin
|
71
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
72
|
+
body = {'app42' => {"user"=> {
|
73
|
+
"userName" => uName,
|
74
|
+
"password" => pwd,
|
75
|
+
"email" => emailAddress
|
76
|
+
}}}.to_json
|
77
|
+
puts "Body #{body}"
|
78
|
+
query_params = Hash.new
|
79
|
+
params = {
|
80
|
+
'apiKey'=> @api_key,
|
81
|
+
'version' => @version,
|
82
|
+
'timeStamp' => util.get_timestamp_utc,
|
83
|
+
}
|
84
|
+
query_params = params.clone
|
85
|
+
params.store("body", body)
|
86
|
+
puts params
|
87
|
+
puts query_params
|
88
|
+
signature = util.sign(@secret_key, params)
|
89
|
+
resource_url = "#{@version}/#{@resource}"
|
90
|
+
response = connection.post(signature, resource_url, query_params, body)
|
91
|
+
user = UserResponseBuilder.new()
|
92
|
+
usr = user.buildResponse(response)
|
93
|
+
rescue App42Exception =>e
|
94
|
+
raise e
|
95
|
+
rescue Exception => e
|
96
|
+
raise App42Exception.new(e)
|
97
|
+
end
|
98
|
+
return usr
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Gets user details based on userName
|
103
|
+
#
|
104
|
+
# @param userName
|
105
|
+
# - UserName which should be unique for the App
|
106
|
+
#
|
107
|
+
# @return Returns User Object
|
108
|
+
#
|
109
|
+
# @raise App42Exception
|
110
|
+
#
|
111
|
+
|
112
|
+
def get_user(userName)
|
113
|
+
puts "Get User Called "
|
114
|
+
puts "Base url #{@base_url}"
|
115
|
+
response = nil;
|
116
|
+
usr = nil;
|
117
|
+
usr = User.new
|
118
|
+
util = Util.new
|
119
|
+
util.throwExceptionIfNullOrBlank(userName, "UserName");
|
120
|
+
begin
|
121
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
122
|
+
query_params = Hash.new
|
123
|
+
params = {
|
124
|
+
'apiKey'=> @api_key,
|
125
|
+
'version' => @version,
|
126
|
+
'timeStamp' => util.get_timestamp_utc,
|
127
|
+
}
|
128
|
+
query_params = params.clone
|
129
|
+
params.store("userName", userName)
|
130
|
+
signature = util.sign(@secret_key, params)
|
131
|
+
resource_url = "#{@version}/#{@resource}/#{userName}"
|
132
|
+
response = connection.get(signature, resource_url, query_params)
|
133
|
+
user = UserResponseBuilder.new
|
134
|
+
usr = user.buildResponse(response)
|
135
|
+
rescue App42Exception =>e
|
136
|
+
raise e
|
137
|
+
rescue Exception => e
|
138
|
+
raise App42Exception.new(e)
|
139
|
+
end
|
140
|
+
return usr
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# Gets All users details
|
145
|
+
#
|
146
|
+
# @return Returns the list that contains all User Object
|
147
|
+
#
|
148
|
+
# @raise App42Exception
|
149
|
+
#
|
150
|
+
|
151
|
+
def get_all_users()
|
152
|
+
puts "Get All Users Called"
|
153
|
+
puts "Base url #{@base_url}"
|
154
|
+
response = nil;
|
155
|
+
userList = nil
|
156
|
+
userList = Array.new
|
157
|
+
util = Util.new
|
158
|
+
begin
|
159
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
160
|
+
query_params = Hash.new
|
161
|
+
params = {
|
162
|
+
'apiKey'=> @api_key,
|
163
|
+
'version' => @version,
|
164
|
+
'timeStamp' => util.get_timestamp_utc,
|
165
|
+
}
|
166
|
+
query_params = params.clone
|
167
|
+
signature = util.sign(@secret_key, params)
|
168
|
+
resource_url = "#{@version}/#{@resource}"
|
169
|
+
response = connection.get(signature, resource_url, query_params)
|
170
|
+
user = UserResponseBuilder.new
|
171
|
+
userList = user.buildArrayResponse(response)
|
172
|
+
rescue App42Exception =>e
|
173
|
+
raise e
|
174
|
+
rescue Exception => e
|
175
|
+
raise App42Exception.new(e)
|
176
|
+
end
|
177
|
+
return userList
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Gets user details based on emailId
|
182
|
+
#
|
183
|
+
# @param emailId
|
184
|
+
# - EmailId of the user to be retrieved
|
185
|
+
#
|
186
|
+
# @return Returns User Object
|
187
|
+
#
|
188
|
+
# @raise App42Exception
|
189
|
+
#
|
190
|
+
|
191
|
+
def get_user_by_email_id(emailId)
|
192
|
+
puts "Get All Users Called"
|
193
|
+
puts "Base url #{@base_url}"
|
194
|
+
response = nil;
|
195
|
+
usr = nil;
|
196
|
+
usr = User.new
|
197
|
+
util = Util.new
|
198
|
+
util.throwExceptionIfEmailNotValid(emailId, "EmailId");
|
199
|
+
util.throwExceptionIfNullOrBlank(emailId, "EmailId");
|
200
|
+
begin
|
201
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
202
|
+
query_params = Hash.new
|
203
|
+
params = {
|
204
|
+
'apiKey'=> @api_key,
|
205
|
+
'version' => @version,
|
206
|
+
'timeStamp' => util.get_timestamp_utc,
|
207
|
+
}
|
208
|
+
query_params = params.clone
|
209
|
+
params.store("emailId", emailId)
|
210
|
+
signature = util.sign(@secret_key, params)
|
211
|
+
resource_url = "#{@version}/#{@resource}/email/#{emailId}"
|
212
|
+
response = connection.get(signature, resource_url, query_params)
|
213
|
+
user = UserResponseBuilder.new
|
214
|
+
usr = user.buildResponse(response)
|
215
|
+
rescue App42Exception =>e
|
216
|
+
raise e
|
217
|
+
rescue Exception => e
|
218
|
+
raise App42Exception.new(e)
|
219
|
+
end
|
220
|
+
return usr
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# Deletes a particular user based on userName.
|
225
|
+
#
|
226
|
+
# @param userName
|
227
|
+
# - UserName which should be unique for the App
|
228
|
+
#
|
229
|
+
# @return App42Response Object if user deleted successfully
|
230
|
+
#
|
231
|
+
# @raise App42Exception
|
232
|
+
#
|
233
|
+
|
234
|
+
def delete_user(userName)
|
235
|
+
puts "Delete User Called "
|
236
|
+
puts "Base url #{@base_url}"
|
237
|
+
response = nil;
|
238
|
+
responseObj = App42Response.new();
|
239
|
+
util = Util.new
|
240
|
+
util.throwExceptionIfNullOrBlank(userName, "UserName");
|
241
|
+
begin
|
242
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
243
|
+
query_params = Hash.new
|
244
|
+
params = {
|
245
|
+
'apiKey'=> @api_key,
|
246
|
+
'version' => @version,
|
247
|
+
'timeStamp' => util.get_timestamp_utc,
|
248
|
+
}
|
249
|
+
query_params = params.clone
|
250
|
+
params.store("userName", userName)
|
251
|
+
signature = util.sign(@secret_key, params)
|
252
|
+
resource_url = "#{@version}/#{@resource}/#{userName}"
|
253
|
+
response = connection.delete(signature, resource_url, query_params)
|
254
|
+
responseObj.strResponse=(response)
|
255
|
+
responseObj.isResponseSuccess=(true)
|
256
|
+
rescue App42Exception =>e
|
257
|
+
raise e
|
258
|
+
rescue Exception => e
|
259
|
+
raise App42Exception.new(e)
|
260
|
+
end
|
261
|
+
return responseObj
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# Creates or Updates User Profile. First time the Profile for the user is
|
266
|
+
# created and in future calls user profile will be updated. This will
|
267
|
+
# always update the profile with new value passed in profile object. Call
|
268
|
+
# to this method should have all the values you want to retain in user
|
269
|
+
# profile object, otherwise old values of profile will get updated with
|
270
|
+
# null.
|
271
|
+
#
|
272
|
+
# Method only updates the profile of user, passing email/password in user
|
273
|
+
# object does not have any significance for this method call.
|
274
|
+
#
|
275
|
+
# @param user
|
276
|
+
# - User for which profile has to be updated, this should
|
277
|
+
# contain the userName and profile object in it.
|
278
|
+
#
|
279
|
+
# @return User Object with updated Profile information
|
280
|
+
#
|
281
|
+
# @raise App42Exception
|
282
|
+
#
|
283
|
+
# @see Profile
|
284
|
+
#
|
285
|
+
|
286
|
+
def create_or_update_profile(user)
|
287
|
+
puts "Base url #{@base_url}"
|
288
|
+
response = nil;
|
289
|
+
userResponse = nil;
|
290
|
+
userResponse = User.new
|
291
|
+
util = Util.new
|
292
|
+
util.throwExceptionIfNullOrBlank(user, "User")
|
293
|
+
util.throwExceptionIfNullOrBlank(user.userName, "UserName");
|
294
|
+
util.throwExceptionIfNullOrBlank(user.profile, "Profile Data");
|
295
|
+
begin
|
296
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
297
|
+
profile = user.profile();
|
298
|
+
profileObj = Hash.new
|
299
|
+
profileObj.store("firstName", profile.firstName());
|
300
|
+
profileObj.store("lastName", profile.lastName());
|
301
|
+
profileObj.store("sex", profile.sex());
|
302
|
+
profileObj.store("mobile", profile.mobile());
|
303
|
+
profileObj.store("line1", profile.line1());
|
304
|
+
profileObj.store("line2", profile.line2());
|
305
|
+
profileObj.store("city", profile.city());
|
306
|
+
profileObj.store("state", profile.state());
|
307
|
+
profileObj.store("country", profile.country());
|
308
|
+
profileObj.store("pincode", profile.pincode());
|
309
|
+
profileObj.store("homeLandLine", profile.homeLandLine());
|
310
|
+
profileObj.store("officeLandLine", profile.officeLandLine());
|
311
|
+
if profile.dateOfBirth != nil
|
312
|
+
profileObj.store("dateOfBirth", util.get_timestamp_utc_from_date(profile.dateOfBirth))
|
313
|
+
end
|
314
|
+
body = {
|
315
|
+
'app42'=>{"user"=>{
|
316
|
+
"userName"=>user.userName,
|
317
|
+
"profileData"=>profileObj
|
318
|
+
}
|
319
|
+
}
|
320
|
+
}.to_json
|
321
|
+
puts "Body #{body}"
|
322
|
+
query_params = Hash.new
|
323
|
+
params = {
|
324
|
+
'apiKey'=> @api_key,
|
325
|
+
'version' => @version,
|
326
|
+
'timeStamp' => util.get_timestamp_utc,
|
327
|
+
}
|
328
|
+
query_params = params.clone
|
329
|
+
params.store("body", body)
|
330
|
+
signature = util.sign(@secret_key, params)
|
331
|
+
resource_url = "#{@version}/#{@resource}/profile"
|
332
|
+
response = connection.put(signature, resource_url, query_params, body)
|
333
|
+
user = UserResponseBuilder.new
|
334
|
+
userResponse = user.buildResponse(response)
|
335
|
+
rescue App42Exception =>e
|
336
|
+
raise e
|
337
|
+
rescue Exception => e
|
338
|
+
raise e
|
339
|
+
end
|
340
|
+
return userResponse
|
341
|
+
end
|
342
|
+
|
343
|
+
#
|
344
|
+
# Authenticate user based on userName and password
|
345
|
+
#
|
346
|
+
# @param uName
|
347
|
+
# - UserName which should be unique for the App
|
348
|
+
# @param pwd
|
349
|
+
# - Password for the User
|
350
|
+
#
|
351
|
+
# @return Whether the user is authenticated or not.
|
352
|
+
#
|
353
|
+
# @raise App42Exception
|
354
|
+
# if authentication fails or username/password is blank or null
|
355
|
+
#
|
356
|
+
|
357
|
+
def authenticate(uName, pwd)
|
358
|
+
puts "authenticateUser Called "
|
359
|
+
puts "Base url #{@base_url}"
|
360
|
+
response = nil;
|
361
|
+
usr = nil;
|
362
|
+
usr = User.new
|
363
|
+
util = Util.new
|
364
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
365
|
+
util.throwExceptionIfNullOrBlank(pwd, "Password");
|
366
|
+
begin
|
367
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
368
|
+
body = {'app42' => {"user"=> {
|
369
|
+
"userName" => uName,
|
370
|
+
"password" => pwd
|
371
|
+
}}}.to_json
|
372
|
+
puts "Body #{body}"
|
373
|
+
query_params = Hash.new
|
374
|
+
params = {
|
375
|
+
'apiKey'=> @api_key,
|
376
|
+
'version' => @version,
|
377
|
+
'timeStamp' => util.get_timestamp_utc,
|
378
|
+
}
|
379
|
+
query_params = params.clone
|
380
|
+
params.store("body", body)
|
381
|
+
signature = util.sign(@secret_key, params)
|
382
|
+
resource_url = "#{@version}/#{@resource}/authenticate"
|
383
|
+
response = connection.post(signature, resource_url, query_params, body)
|
384
|
+
user = UserResponseBuilder.new
|
385
|
+
usr = user.buildResponse(response)
|
386
|
+
rescue App42Exception =>e
|
387
|
+
raise e
|
388
|
+
rescue Exception => e
|
389
|
+
raise e
|
390
|
+
end
|
391
|
+
return usr
|
392
|
+
end
|
393
|
+
|
394
|
+
#
|
395
|
+
# Gets All the locked users details
|
396
|
+
#
|
397
|
+
# @return Returns the list that contains locked User Objects
|
398
|
+
#
|
399
|
+
# @raise App42Exception
|
400
|
+
#
|
401
|
+
|
402
|
+
def get_locked_users()
|
403
|
+
puts "Get Locked Users Called"
|
404
|
+
puts "Base url #{@base_url}"
|
405
|
+
response = nil;
|
406
|
+
userList = nil;
|
407
|
+
userList = Array.new
|
408
|
+
util = Util.new
|
409
|
+
begin
|
410
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
411
|
+
query_params = Hash.new
|
412
|
+
params = {
|
413
|
+
'apiKey'=> @api_key,
|
414
|
+
'version' => @version,
|
415
|
+
'timeStamp' => util.get_timestamp_utc,
|
416
|
+
}
|
417
|
+
query_params = params.clone
|
418
|
+
signature = util.sign(@secret_key, params)
|
419
|
+
resource_url = "#{@version}/#{@resource}/locked"
|
420
|
+
response = connection.get(signature, resource_url, query_params)
|
421
|
+
user = UserResponseBuilder.new
|
422
|
+
userList = user.buildArrayResponse(response)
|
423
|
+
rescue App42Exception =>e
|
424
|
+
raise e
|
425
|
+
rescue Exception => e
|
426
|
+
raise App42Exception.new(e)
|
427
|
+
end
|
428
|
+
return userList
|
429
|
+
end
|
430
|
+
|
431
|
+
#
|
432
|
+
# Updates the User based on userName.
|
433
|
+
# Note: Only email can be updated. Username cannot be updated.
|
434
|
+
#
|
435
|
+
# @param uName
|
436
|
+
# - UserName which should be unique for the App
|
437
|
+
# @param emailAddress
|
438
|
+
# - Email address of the user
|
439
|
+
#
|
440
|
+
# @return updated User Object
|
441
|
+
#
|
442
|
+
# @raise App42Exception
|
443
|
+
#
|
444
|
+
|
445
|
+
def update_email(uName, emailAddress)
|
446
|
+
puts "Update User Called "
|
447
|
+
puts "Base url #{@base_url}"
|
448
|
+
response = nil;
|
449
|
+
usr = nil;
|
450
|
+
usr = User.new
|
451
|
+
util = Util.new
|
452
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
453
|
+
util.throwExceptionIfNullOrBlank(emailAddress, "EmailAddress");
|
454
|
+
util.throwExceptionIfNullOrBlank(emailAddress, "Email Address");
|
455
|
+
begin
|
456
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
457
|
+
body = {'app42' => {"user"=> {
|
458
|
+
"userName" => uName,
|
459
|
+
"email" => emailAddress
|
460
|
+
}}}.to_json
|
461
|
+
puts "Body #{body}"
|
462
|
+
query_params = Hash.new
|
463
|
+
params = {
|
464
|
+
'apiKey'=> @api_key,
|
465
|
+
'version' => @version,
|
466
|
+
'timeStamp' => util.get_timestamp_utc,
|
467
|
+
}
|
468
|
+
query_params = params.clone
|
469
|
+
params.store("body", body)
|
470
|
+
puts query_params
|
471
|
+
signature = util.sign(@secret_key, params)
|
472
|
+
resource_url = "#{@version}/#{@resource}"
|
473
|
+
response = connection.put(signature, resource_url, query_params, body)
|
474
|
+
user = UserResponseBuilder.new
|
475
|
+
usr = user.buildResponse(response)
|
476
|
+
rescue App42Exception =>e
|
477
|
+
raise e
|
478
|
+
rescue Exception => e
|
479
|
+
raise App42Exception.new(e)
|
480
|
+
end
|
481
|
+
return usr
|
482
|
+
end
|
483
|
+
|
484
|
+
#
|
485
|
+
# Locks the user based on the userName. Apps can use these feature to lock a user because of reasons specific to their
|
486
|
+
# usercase e.g. If payment not received and the App wants the user to be inactive
|
487
|
+
#
|
488
|
+
# @param uName
|
489
|
+
# - UserName which should be unique for the App
|
490
|
+
#
|
491
|
+
# @return Returns the locked User Object
|
492
|
+
#
|
493
|
+
# @raise App42Exception
|
494
|
+
#
|
495
|
+
|
496
|
+
def lock_user(uName)
|
497
|
+
puts "Lock User Called "
|
498
|
+
puts "Base url #{@base_url}"
|
499
|
+
response = nil;
|
500
|
+
usr = nil;
|
501
|
+
usr = User.new
|
502
|
+
util = Util.new
|
503
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
504
|
+
begin
|
505
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
506
|
+
body = {'app42' => {"user"=> {
|
507
|
+
"userName" => uName
|
508
|
+
}}}.to_json
|
509
|
+
puts "Body #{body}"
|
510
|
+
query_params = Hash.new
|
511
|
+
params = {
|
512
|
+
'apiKey'=> @api_key,
|
513
|
+
'version' => @version,
|
514
|
+
'timeStamp' => util.get_timestamp_utc,
|
515
|
+
}
|
516
|
+
query_params = params.clone
|
517
|
+
params.store("body", body)
|
518
|
+
signature = util.sign(@secret_key, params)
|
519
|
+
resource_url = "#{@version}/#{@resource}/lock"
|
520
|
+
response = connection.put(signature, resource_url, query_params, body)
|
521
|
+
user = UserResponseBuilder.new
|
522
|
+
usr = user.buildResponse(response)
|
523
|
+
rescue App42Exception =>e
|
524
|
+
raise e
|
525
|
+
rescue Exception => e
|
526
|
+
raise App42Exception.new(e)
|
527
|
+
end
|
528
|
+
return usr
|
529
|
+
end
|
530
|
+
|
531
|
+
#
|
532
|
+
# Unlock the user based on the userName. Apps can use these feature to unlock a user because of reasons specific to their
|
533
|
+
# usercase e.g. If payment received and the App wants to the user to be active.
|
534
|
+
#
|
535
|
+
# @param uName
|
536
|
+
# - UserName which should be unique for the App
|
537
|
+
#
|
538
|
+
# @return Returns the unlocked User Object
|
539
|
+
#
|
540
|
+
# @raise App42Exception
|
541
|
+
#
|
542
|
+
|
543
|
+
def unlock_user(uName)
|
544
|
+
puts "unlockUser Called "
|
545
|
+
puts "Base url #{@base_url}"
|
546
|
+
response = nil;
|
547
|
+
usr = nil;
|
548
|
+
usr = User.new
|
549
|
+
util = Util.new
|
550
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
551
|
+
begin
|
552
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
553
|
+
body = {'app42' => {"user"=> {
|
554
|
+
"userName" => uName
|
555
|
+
}}}.to_json
|
556
|
+
puts "Body #{body}"
|
557
|
+
query_params = Hash.new
|
558
|
+
params = {
|
559
|
+
'apiKey'=> @api_key,
|
560
|
+
'version' => @version,
|
561
|
+
'timeStamp' => util.get_timestamp_utc,
|
562
|
+
}
|
563
|
+
query_params = params.clone
|
564
|
+
params.store("body", body)
|
565
|
+
signature = util.sign(@secret_key, params)
|
566
|
+
resource_url = "#{@version}/#{@resource}/unlock"
|
567
|
+
response = connection.put(signature, resource_url, query_params, body)
|
568
|
+
user = UserResponseBuilder.new
|
569
|
+
usr = user.buildResponse(response)
|
570
|
+
rescue App42Exception =>e
|
571
|
+
raise e
|
572
|
+
rescue Exception => e
|
573
|
+
raise App42Exception.new(e)
|
574
|
+
end
|
575
|
+
return usr
|
576
|
+
end
|
577
|
+
|
578
|
+
#
|
579
|
+
# Gets All users By Paging
|
580
|
+
#
|
581
|
+
# @param max
|
582
|
+
# - Maximum number of records to be fetched
|
583
|
+
# @param offset
|
584
|
+
# - From where the records are to be fetched
|
585
|
+
#
|
586
|
+
# @return Returns User Information
|
587
|
+
#
|
588
|
+
# @raise App42Exception
|
589
|
+
#
|
590
|
+
|
591
|
+
def get_all_users_by_paging(max, offset)
|
592
|
+
puts "getAllUsersByPaging Called "
|
593
|
+
puts "Base url #{@base_url}"
|
594
|
+
response = nil;
|
595
|
+
usr = nil;
|
596
|
+
userList = User.new
|
597
|
+
util = Util.new
|
598
|
+
util.validateMax(max);
|
599
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
600
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
601
|
+
begin
|
602
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
603
|
+
query_params = Hash.new
|
604
|
+
params = {
|
605
|
+
'apiKey'=> @api_key,
|
606
|
+
'version' => @version,
|
607
|
+
'timeStamp' => util.get_timestamp_utc,
|
608
|
+
}
|
609
|
+
query_params = params.clone
|
610
|
+
params.store("max", "" + (max.to_i).to_s)
|
611
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
612
|
+
signature = util.sign(@secret_key, params)
|
613
|
+
resource_url = "#{@version}/#{@resource}/paging/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
614
|
+
response = connection.get(signature, resource_url, query_params)
|
615
|
+
user = UserResponseBuilder.new
|
616
|
+
userList = user.buildArrayResponse(response)
|
617
|
+
rescue App42Exception =>e
|
618
|
+
raise e
|
619
|
+
rescue Exception => e
|
620
|
+
raise App42Exception.new(e)
|
621
|
+
end
|
622
|
+
return userList
|
623
|
+
end
|
624
|
+
|
625
|
+
#
|
626
|
+
# Gets All the locked users By paging details
|
627
|
+
#
|
628
|
+
# @param max
|
629
|
+
# - Maximum number of records to be fetched
|
630
|
+
# @param offset
|
631
|
+
# - From where the records are to be fetched
|
632
|
+
#
|
633
|
+
# @return Returns User Information
|
634
|
+
#
|
635
|
+
# @raise App42Exception
|
636
|
+
#
|
637
|
+
|
638
|
+
def get_locked_users_by_paging(max, offset)
|
639
|
+
puts "get_locked_users_by_paging Called "
|
640
|
+
puts "Base url #{@base_url}"
|
641
|
+
response = nil;
|
642
|
+
usr = nil;
|
643
|
+
userList = User.new
|
644
|
+
util = Util.new
|
645
|
+
util.validateMax(max);
|
646
|
+
util.throwExceptionIfNullOrBlank(max, "Max");
|
647
|
+
util.throwExceptionIfNullOrBlank(offset, "Offset");
|
648
|
+
begin
|
649
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
650
|
+
query_params = Hash.new
|
651
|
+
params = {
|
652
|
+
'apiKey'=> @api_key,
|
653
|
+
'version' => @version,
|
654
|
+
'timeStamp' => util.get_timestamp_utc,
|
655
|
+
}
|
656
|
+
query_params = params.clone
|
657
|
+
params.store("max", "" + (max.to_i).to_s)
|
658
|
+
params.store("offset", "" + (offset.to_i).to_s)
|
659
|
+
signature = util.sign(@secret_key, params)
|
660
|
+
resource_url = "#{@version}/#{@resource}/locked/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
|
661
|
+
response = connection.get(signature, resource_url, query_params)
|
662
|
+
user = UserResponseBuilder.new
|
663
|
+
userList = user.buildArrayResponse(response)
|
664
|
+
rescue App42Exception =>e
|
665
|
+
raise e
|
666
|
+
rescue Exception => e
|
667
|
+
raise App42Exception.new(e)
|
668
|
+
end
|
669
|
+
return userList
|
670
|
+
end
|
671
|
+
|
672
|
+
#
|
673
|
+
# Change the password for user based on the userName.
|
674
|
+
#
|
675
|
+
# @param uName
|
676
|
+
# - UserName which should be unique for the App
|
677
|
+
# @param oldPwd
|
678
|
+
# - Old Password for the user for authentication
|
679
|
+
# @param newPwd
|
680
|
+
# - New Password for the user to change
|
681
|
+
#
|
682
|
+
# @return App42Response Object if updated successfully
|
683
|
+
#
|
684
|
+
# @raise App42Exception
|
685
|
+
#
|
686
|
+
|
687
|
+
def change_user_password(uName, oldPwd, newPwd)
|
688
|
+
puts "changeUserPassword Called "
|
689
|
+
puts "Base url #{@base_url}"
|
690
|
+
response = nil;
|
691
|
+
responseObj = App42Response.new();
|
692
|
+
util = Util.new
|
693
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
694
|
+
util.throwExceptionIfNullOrBlank(oldPwd, "Old Password");
|
695
|
+
util.throwExceptionIfNullOrBlank(newPwd, "New Password");
|
696
|
+
responseObj = App42Response.new
|
697
|
+
if(oldPwd == newPwd)
|
698
|
+
raise App42Exception.new("Old password and new password are same")
|
699
|
+
end
|
700
|
+
begin
|
701
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
702
|
+
body = {'app42' => {"user"=> {
|
703
|
+
"userName" => uName,
|
704
|
+
"oldPassword" => oldPwd,
|
705
|
+
"newPassword" => newPwd
|
706
|
+
}}}.to_json
|
707
|
+
query_params = Hash.new
|
708
|
+
params = {
|
709
|
+
'apiKey'=> @api_key,
|
710
|
+
'version' => @version,
|
711
|
+
'timeStamp' => util.get_timestamp_utc,
|
712
|
+
}
|
713
|
+
query_params = params.clone
|
714
|
+
params.store("body", body)
|
715
|
+
signature = util.sign(@secret_key, params)
|
716
|
+
resource_url = "#{@version}/#{@resource}/changeUserPassword"
|
717
|
+
response = connection.put(signature, resource_url, query_params, body)
|
718
|
+
responseObj.strResponse=(response)
|
719
|
+
responseObj.isResponseSuccess=(true)
|
720
|
+
rescue App42Exception =>e
|
721
|
+
raise e
|
722
|
+
rescue Exception => e
|
723
|
+
raise App42Exception.new(e)
|
724
|
+
end
|
725
|
+
return responseObj
|
726
|
+
end
|
727
|
+
|
728
|
+
#
|
729
|
+
# Gets the count of all the users
|
730
|
+
#
|
731
|
+
# @return Returns the count of all User exists
|
732
|
+
#
|
733
|
+
# @raise App42Exception
|
734
|
+
#
|
735
|
+
|
736
|
+
def get_all_users_count()
|
737
|
+
puts "getAllUsersCount Called "
|
738
|
+
puts "Base url #{@base_url}"
|
739
|
+
response = nil;
|
740
|
+
responseObj = App42Response.new();
|
741
|
+
util = Util.new
|
742
|
+
begin
|
743
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
744
|
+
query_params = Hash.new
|
745
|
+
params = {
|
746
|
+
'apiKey'=> @api_key,
|
747
|
+
'version' => @version,
|
748
|
+
'timeStamp' => util.get_timestamp_utc,
|
749
|
+
}
|
750
|
+
query_params = params.clone
|
751
|
+
signature = util.sign(@secret_key, params)
|
752
|
+
resource_url = "#{@version}/#{@resource}/count/all"
|
753
|
+
response = connection.get(signature, resource_url, query_params)
|
754
|
+
responseObj.strResponse=(response)
|
755
|
+
responseObj.isResponseSuccess=(true)
|
756
|
+
responseObj = UserResponseBuilder.new()
|
757
|
+
responseObj.getTotalRecords(response);
|
758
|
+
rescue App42Exception =>e
|
759
|
+
raise e
|
760
|
+
rescue Exception => e
|
761
|
+
raise App42Exception.new(e)
|
762
|
+
end
|
763
|
+
return responseObj
|
764
|
+
end
|
765
|
+
|
766
|
+
#
|
767
|
+
# Gets the count of all the locked users
|
768
|
+
#
|
769
|
+
# @return Returns the count of locked User exists
|
770
|
+
#
|
771
|
+
# @raise App42Exception
|
772
|
+
#
|
773
|
+
|
774
|
+
def get_locked_users_count()
|
775
|
+
puts "getLockedUsersCount Called "
|
776
|
+
puts "Base url #{@base_url}"
|
777
|
+
response = nil;
|
778
|
+
responseObj = App42Response.new();
|
779
|
+
util = Util.new
|
780
|
+
begin
|
781
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
782
|
+
query_params = Hash.new
|
783
|
+
params = {
|
784
|
+
'apiKey'=> @api_key,
|
785
|
+
'version' => @version,
|
786
|
+
'timeStamp' => util.get_timestamp_utc,
|
787
|
+
}
|
788
|
+
query_params = params.clone
|
789
|
+
puts query_params
|
790
|
+
signature = util.sign(@secret_key, params)
|
791
|
+
resource_url = "#{@version}/#{@resource}/count/locked"
|
792
|
+
response = connection.get(signature, resource_url, query_params)
|
793
|
+
responseObj.strResponse=(response)
|
794
|
+
responseObj.isResponseSuccess=(true)
|
795
|
+
responseObj = UserResponseBuilder.new()
|
796
|
+
responseObj.getTotalRecords(response);
|
797
|
+
rescue App42Exception =>e
|
798
|
+
raise e
|
799
|
+
rescue Exception => e
|
800
|
+
raise App42Exception.new(e)
|
801
|
+
end
|
802
|
+
return responseObj
|
803
|
+
end
|
804
|
+
|
805
|
+
#
|
806
|
+
# Create User for the App
|
807
|
+
#
|
808
|
+
# @param uName
|
809
|
+
# - UserName which should be unique for the App
|
810
|
+
# @param pwd
|
811
|
+
# - Password for the User
|
812
|
+
# @param emailAddress
|
813
|
+
# - Email address of the user
|
814
|
+
# @param roleList
|
815
|
+
# - list of roles to be assigned to User
|
816
|
+
#
|
817
|
+
# @return The created User Object.
|
818
|
+
#
|
819
|
+
# @raise App42Exception
|
820
|
+
#
|
821
|
+
|
822
|
+
def create_user_with_role(uName, pwd, emailAddress, roleList)
|
823
|
+
puts "Create User Called "
|
824
|
+
puts "Base url #{@base_url}"
|
825
|
+
response = nil;
|
826
|
+
usr = nil;
|
827
|
+
usr = User.new
|
828
|
+
util = Util.new
|
829
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
830
|
+
util.throwExceptionIfNullOrBlank(pwd, "Password");
|
831
|
+
util.throwExceptionIfEmailNotValid(emailAddress, "EmailAddress");
|
832
|
+
util.throwExceptionIfNullOrBlank(emailAddress, "EmailAddress");
|
833
|
+
util.throwExceptionIfNullOrBlank(roleList, "RoleList");
|
834
|
+
if roleList.size() == 0
|
835
|
+
raise App42Exception.new("RoleList cannot be empty.Please assign at least one role");
|
836
|
+
end
|
837
|
+
begin
|
838
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
839
|
+
roleArray = Array.new
|
840
|
+
for role in roleList do
|
841
|
+
roleArray.push(role)
|
842
|
+
end
|
843
|
+
body = {'app42' => {"user"=> {
|
844
|
+
"email" => emailAddress,
|
845
|
+
"password" => pwd,
|
846
|
+
"userName" => uName, "roles" => {
|
847
|
+
"role" => roleArray
|
848
|
+
}}}}.to_json
|
849
|
+
puts "Body #{body}"
|
850
|
+
query_params = Hash.new
|
851
|
+
params = {
|
852
|
+
'apiKey'=> @api_key,
|
853
|
+
'version' => @version,
|
854
|
+
'timeStamp' => util.get_timestamp_utc,
|
855
|
+
}
|
856
|
+
query_params = params.clone
|
857
|
+
params.store("body", body)
|
858
|
+
puts query_params
|
859
|
+
signature = util.sign(@secret_key, params)
|
860
|
+
resource_url = "#{@version}/#{@resource}/role"
|
861
|
+
response = connection.post(signature, resource_url, query_params, body)
|
862
|
+
user = UserResponseBuilder.new()
|
863
|
+
usr = user.buildResponse(response)
|
864
|
+
rescue App42Exception =>e
|
865
|
+
raise e
|
866
|
+
rescue Exception => e
|
867
|
+
raise App42Exception.new(e)
|
868
|
+
end
|
869
|
+
return usr
|
870
|
+
end
|
871
|
+
|
872
|
+
#
|
873
|
+
# Get Roles based on userName
|
874
|
+
#
|
875
|
+
# @param userName
|
876
|
+
# - UserName which should be unique for the App
|
877
|
+
#
|
878
|
+
# @return Returns User Object
|
879
|
+
#
|
880
|
+
# @raise App42Exception
|
881
|
+
#
|
882
|
+
|
883
|
+
def get_roles_by_user(userName)
|
884
|
+
puts "getRolesByUser Called "
|
885
|
+
puts "Base url #{@base_url}"
|
886
|
+
response = nil;
|
887
|
+
usr = nil;
|
888
|
+
usr = User.new
|
889
|
+
util = Util.new
|
890
|
+
util.throwExceptionIfNullOrBlank(userName, "UserName");
|
891
|
+
begin
|
892
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
893
|
+
query_params = Hash.new
|
894
|
+
params = {
|
895
|
+
'apiKey'=> @api_key,
|
896
|
+
'version' => @version,
|
897
|
+
'timeStamp' => util.get_timestamp_utc,
|
898
|
+
}
|
899
|
+
query_params = params.clone
|
900
|
+
params.store("userName", userName)
|
901
|
+
puts query_params
|
902
|
+
signature = util.sign(@secret_key, params)
|
903
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/roles"
|
904
|
+
response = connection.get(signature, resource_url, query_params)
|
905
|
+
user = UserResponseBuilder.new()
|
906
|
+
usr = user.buildResponse(response)
|
907
|
+
rescue App42Exception =>e
|
908
|
+
raise e
|
909
|
+
rescue Exception => e
|
910
|
+
raise App42Exception.new(e)
|
911
|
+
end
|
912
|
+
return usr
|
913
|
+
end
|
914
|
+
|
915
|
+
#
|
916
|
+
# Get Users based on Role
|
917
|
+
#
|
918
|
+
# @param role
|
919
|
+
# - Role which should be unique for the App
|
920
|
+
#
|
921
|
+
# @return Returns User Object
|
922
|
+
#
|
923
|
+
# @raise App42Exception
|
924
|
+
#
|
925
|
+
|
926
|
+
def get_users_by_role(role)
|
927
|
+
puts "get_users_by_role Called "
|
928
|
+
puts "Base url #{@base_url}"
|
929
|
+
response = nil;
|
930
|
+
usr = nil;
|
931
|
+
userList = Array.new
|
932
|
+
util = Util.new
|
933
|
+
util.throwExceptionIfNullOrBlank(role, "Role");
|
934
|
+
begin
|
935
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
936
|
+
query_params = Hash.new
|
937
|
+
params = {
|
938
|
+
'apiKey'=> @api_key,
|
939
|
+
'version' => @version,
|
940
|
+
'timeStamp' => util.get_timestamp_utc,
|
941
|
+
}
|
942
|
+
query_params = params.clone
|
943
|
+
params.store("role", role)
|
944
|
+
puts query_params
|
945
|
+
signature = util.sign(@secret_key, params)
|
946
|
+
resource_url = "#{@version}/#{@resource}/role/#{role}"
|
947
|
+
response = connection.get(signature, resource_url, query_params)
|
948
|
+
user = UserResponseBuilder.new()
|
949
|
+
userList = user.buildArrayResponse(response)
|
950
|
+
rescue App42Exception =>e
|
951
|
+
raise e
|
952
|
+
rescue Exception => e
|
953
|
+
raise App42Exception.new(e)
|
954
|
+
end
|
955
|
+
return userList
|
956
|
+
end
|
957
|
+
|
958
|
+
#
|
959
|
+
# Revokes the specified role from the user.
|
960
|
+
#
|
961
|
+
# @param userName
|
962
|
+
# - UserName which should be unique for the App
|
963
|
+
#
|
964
|
+
# @return App42Response Object if user deleted successfully
|
965
|
+
#
|
966
|
+
# @raise App42Exception
|
967
|
+
#
|
968
|
+
|
969
|
+
def revoke_role(userName, role)
|
970
|
+
puts "revoke_role Called "
|
971
|
+
puts "Base url #{@base_url}"
|
972
|
+
response = nil;
|
973
|
+
responseObj = App42Response.new();
|
974
|
+
util = Util.new
|
975
|
+
util.throwExceptionIfNullOrBlank(userName, "UserName");
|
976
|
+
util.throwExceptionIfNullOrBlank(role, "Role");
|
977
|
+
begin
|
978
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
979
|
+
query_params = Hash.new
|
980
|
+
params = {
|
981
|
+
'apiKey'=> @api_key,
|
982
|
+
'version' => @version,
|
983
|
+
'timeStamp' => util.get_timestamp_utc,
|
984
|
+
}
|
985
|
+
query_params = params.clone
|
986
|
+
params.store("role", role)
|
987
|
+
params.store("userName", userName)
|
988
|
+
puts query_params
|
989
|
+
signature = util.sign(@secret_key, params)
|
990
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/revoke/#{role}"
|
991
|
+
response = connection.delete(signature, resource_url, query_params)
|
992
|
+
responseObj.strResponse=(response)
|
993
|
+
responseObj.isResponseSuccess=(true)
|
994
|
+
rescue App42Exception =>e
|
995
|
+
raise e
|
996
|
+
rescue Exception => e
|
997
|
+
raise App42Exception.new(e)
|
998
|
+
end
|
999
|
+
return responseObj
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
#
|
1003
|
+
# Revokes the specified role from the user.
|
1004
|
+
#
|
1005
|
+
# @param userName
|
1006
|
+
# - UserName which should be unique for the App
|
1007
|
+
#
|
1008
|
+
# @return App42Response Object if user deleted successfully
|
1009
|
+
#
|
1010
|
+
# @raise App42Exception
|
1011
|
+
#
|
1012
|
+
|
1013
|
+
def revoke_all_roles(userName)
|
1014
|
+
puts "revoke_all_roles Called "
|
1015
|
+
puts "Base url #{@base_url}"
|
1016
|
+
response = nil;
|
1017
|
+
responseObj = App42Response.new();
|
1018
|
+
util = Util.new
|
1019
|
+
util.throwExceptionIfNullOrBlank(userName, "UserName");
|
1020
|
+
begin
|
1021
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
1022
|
+
query_params = Hash.new
|
1023
|
+
params = {
|
1024
|
+
'apiKey'=> @api_key,
|
1025
|
+
'version' => @version,
|
1026
|
+
'timeStamp' => util.get_timestamp_utc,
|
1027
|
+
}
|
1028
|
+
query_params = params.clone
|
1029
|
+
params.store("userName", userName)
|
1030
|
+
puts query_params
|
1031
|
+
signature = util.sign(@secret_key, params)
|
1032
|
+
resource_url = "#{@version}/#{@resource}/#{userName}/revoke"
|
1033
|
+
response = connection.delete(signature, resource_url, query_params)
|
1034
|
+
responseObj.strResponse=(response)
|
1035
|
+
responseObj.isResponseSuccess=(true)
|
1036
|
+
rescue App42Exception =>e
|
1037
|
+
raise e
|
1038
|
+
rescue Exception => e
|
1039
|
+
raise App42Exception.new(e)
|
1040
|
+
end
|
1041
|
+
return responseObj
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
#
|
1045
|
+
# Get Users based on Profile Data
|
1046
|
+
#
|
1047
|
+
# @param profileData
|
1048
|
+
# - Profile Data key/value for which Users need to be retrieved
|
1049
|
+
#
|
1050
|
+
# @return Returns Arraylist of User Object for that particular role
|
1051
|
+
#
|
1052
|
+
# @raise App42Exception
|
1053
|
+
#
|
1054
|
+
|
1055
|
+
def get_users_by_profile_data(profileData)
|
1056
|
+
puts "get_users_by_profile_data Called "
|
1057
|
+
puts "Base url #{@base_url}"
|
1058
|
+
response = nil;
|
1059
|
+
userList = nil;
|
1060
|
+
userList = Array.new
|
1061
|
+
util = Util.new
|
1062
|
+
parameters = "";
|
1063
|
+
parameters = fill_params_with_profile_data(profileData);
|
1064
|
+
begin
|
1065
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
1066
|
+
query_params = Hash.new
|
1067
|
+
params = {
|
1068
|
+
'apiKey'=> @api_key,
|
1069
|
+
'version' => @version,
|
1070
|
+
'timeStamp' => util.get_timestamp_utc,
|
1071
|
+
}
|
1072
|
+
query_params = params.clone
|
1073
|
+
puts query_params
|
1074
|
+
signature = util.sign(@secret_key, params)
|
1075
|
+
resource_url = "#{@version}/#{@resource}/profile/#{parameters}"
|
1076
|
+
response = connection.get(signature, resource_url, query_params)
|
1077
|
+
user = UserResponseBuilder.new()
|
1078
|
+
userList = user.buildArrayResponse(response)
|
1079
|
+
rescue App42Exception =>e
|
1080
|
+
raise e
|
1081
|
+
rescue Exception => e
|
1082
|
+
raise App42Exception.new(e)
|
1083
|
+
end
|
1084
|
+
return userList
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
#
|
1088
|
+
# Updates the User based on userName. Note: Only email can be updated.
|
1089
|
+
# Username cannot be updated.
|
1090
|
+
#
|
1091
|
+
# @param uName
|
1092
|
+
# - UserName which should be unique for the App
|
1093
|
+
# @param emailAddress
|
1094
|
+
# - Email address of the user
|
1095
|
+
#
|
1096
|
+
# @return updated User Object
|
1097
|
+
#
|
1098
|
+
# @raise App42Exception
|
1099
|
+
#
|
1100
|
+
|
1101
|
+
def reset_user_password(uName,password)
|
1102
|
+
puts "resetUserPassword Called "
|
1103
|
+
puts "Base url #{@base_url}"
|
1104
|
+
response = nil;
|
1105
|
+
responseObj = App42Response.new();
|
1106
|
+
util = Util.new
|
1107
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
1108
|
+
util.throwExceptionIfNullOrBlank(password, "password");
|
1109
|
+
begin
|
1110
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
1111
|
+
body = {'app42' => {"user"=> {
|
1112
|
+
"userName" => uName,
|
1113
|
+
"password" => password
|
1114
|
+
}}}.to_json
|
1115
|
+
puts "Body #{body}"
|
1116
|
+
query_params = Hash.new
|
1117
|
+
params = {
|
1118
|
+
'apiKey'=> @api_key,
|
1119
|
+
'version' => @version,
|
1120
|
+
'timeStamp' => util.get_timestamp_utc,
|
1121
|
+
}
|
1122
|
+
query_params = params.clone
|
1123
|
+
params.store("body", body)
|
1124
|
+
puts query_params
|
1125
|
+
signature = util.sign(@secret_key, params)
|
1126
|
+
resource_url = "#{@version}/#{@resource}/resetUserPassword"
|
1127
|
+
response = connection.put(signature, resource_url, query_params, body)
|
1128
|
+
responseObj.strResponse=(response)
|
1129
|
+
responseObj.isResponseSuccess=(true)
|
1130
|
+
rescue App42Exception =>e
|
1131
|
+
raise e
|
1132
|
+
rescue Exception => e
|
1133
|
+
raise App42Exception.new(e)
|
1134
|
+
end
|
1135
|
+
return responseObj
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
#
|
1139
|
+
# Add Role for the App
|
1140
|
+
#
|
1141
|
+
# @param uName
|
1142
|
+
# - UserName which should be unique for the App
|
1143
|
+
# @param roleList
|
1144
|
+
# - list of roles to be added to User
|
1145
|
+
#
|
1146
|
+
# @return The created User Object.
|
1147
|
+
#
|
1148
|
+
# @raise App42Exception
|
1149
|
+
#
|
1150
|
+
|
1151
|
+
def assign_roles(uName, roleList)
|
1152
|
+
puts "assignRoles Called "
|
1153
|
+
puts "Base url #{@base_url}"
|
1154
|
+
response = nil;
|
1155
|
+
usr = nil;
|
1156
|
+
usr = User.new
|
1157
|
+
util = Util.new
|
1158
|
+
util.throwExceptionIfNullOrBlank(uName, "UserName");
|
1159
|
+
util.throwExceptionIfNullOrBlank(roleList, "RoleList");
|
1160
|
+
if roleList.size() == 0
|
1161
|
+
raise App42Exception.new("RoleList cannot be empty.Please assign at least one role");
|
1162
|
+
end
|
1163
|
+
begin
|
1164
|
+
connection = App42::Connection::RESTConnection.new(@base_url)
|
1165
|
+
roleArray = Array.new
|
1166
|
+
for role in roleList do
|
1167
|
+
roleArray.push(role)
|
1168
|
+
end
|
1169
|
+
body = {'app42' => {"user"=> {
|
1170
|
+
"userName" => uName, "roles" => {
|
1171
|
+
"role" => roleArray
|
1172
|
+
}}}}.to_json
|
1173
|
+
puts "Body #{body}"
|
1174
|
+
query_params = Hash.new
|
1175
|
+
params = {
|
1176
|
+
'apiKey'=> @api_key,
|
1177
|
+
'version' => @version,
|
1178
|
+
'timeStamp' => util.get_timestamp_utc,
|
1179
|
+
}
|
1180
|
+
query_params = params.clone
|
1181
|
+
params.store("body", body)
|
1182
|
+
puts query_params
|
1183
|
+
signature = util.sign(@secret_key, params)
|
1184
|
+
resource_url = "#{@version}/#{@resource}/assignrole"
|
1185
|
+
response = connection.post(signature, resource_url, query_params, body)
|
1186
|
+
user = UserResponseBuilder.new()
|
1187
|
+
usr = user.buildResponse(response)
|
1188
|
+
rescue App42Exception =>e
|
1189
|
+
raise e
|
1190
|
+
rescue Exception => e
|
1191
|
+
raise App42Exception.new(e)
|
1192
|
+
end
|
1193
|
+
return usr
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
#
|
1197
|
+
# Builds a Parameter string from the profileData.
|
1198
|
+
#
|
1199
|
+
# @param profileData
|
1200
|
+
# - User.Profile object that contains User's Profile information
|
1201
|
+
#
|
1202
|
+
# @return String Object which contains the parameter string.
|
1203
|
+
#
|
1204
|
+
# @raise App42Exception
|
1205
|
+
#
|
1206
|
+
|
1207
|
+
def fill_params_with_profile_data(profileData)
|
1208
|
+
profileDataCond = "";
|
1209
|
+
if profileData.city != nil && !profileData.city != ""
|
1210
|
+
profileDataCond += "city:"+ profileData.city()+"!";
|
1211
|
+
end
|
1212
|
+
if profileData.country != nil && !profileData.country != ""
|
1213
|
+
profileDataCond += "country:"+ profileData.country()+"!";
|
1214
|
+
end
|
1215
|
+
if profileData.dateOfBirth != nil && !profileData.dateOfBirth != ""
|
1216
|
+
profileDataCond += "date_of_birth:"+ profileData.dateOfBirth()+"!";
|
1217
|
+
end
|
1218
|
+
if profileData.firstName != nil && !profileData.firstName != ""
|
1219
|
+
profileDataCond += "first_name:"+ profileData.firstName()+"!";
|
1220
|
+
end
|
1221
|
+
if profileData.lastName != nil && !profileData.lastName != ""
|
1222
|
+
profileDataCond += "last_name:"+ profileData.lastName()+"!";
|
1223
|
+
end
|
1224
|
+
if profileData.homeLandLine != nil && !profileData.homeLandLine != ""
|
1225
|
+
profileDataCond += "home_land_line:"+ profileData.homeLandLine()+"!";
|
1226
|
+
end
|
1227
|
+
if profileData.line1 != nil && !profileData.line1 != ""
|
1228
|
+
profileDataCond += "line1:"+ profileData.line1()+"!";
|
1229
|
+
end
|
1230
|
+
if profileData.line2() != nil && !profileData.line2 != ""
|
1231
|
+
profileDataCond += "line2:"+ profileData.line2()+"!";
|
1232
|
+
end
|
1233
|
+
if profileData.mobile != nil && !profileData.mobile != ""
|
1234
|
+
profileDataCond += "mobile:"+ profileData.mobile()+"!";
|
1235
|
+
end
|
1236
|
+
if profileData.officeLandLine() != nil && !profileData.officeLandLine.equals("")
|
1237
|
+
profileDataCond += "office_land_line:"+ profileData.officeLandLine()+"!";
|
1238
|
+
end
|
1239
|
+
if profileData.pincode != nil && !profileData.pincode != ""
|
1240
|
+
profileDataCond += "pincode:"+ profileData.pincode()+"!";
|
1241
|
+
end
|
1242
|
+
if profileData.sex != nil && !profileData.sex != ""
|
1243
|
+
profileDataCond += "sex:"+ profileData.sex()+"!";
|
1244
|
+
end
|
1245
|
+
if profileData.state != nil && !profileData.state != ""
|
1246
|
+
profileDataCond += "state:"+ profileData.state()+"!";
|
1247
|
+
end
|
1248
|
+
return profileDataCond;
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
end
|
1252
|
+
end
|
1253
|
+
end
|