Class: App42::Session::SessionService
- Inherits:
-
Object
- Object
- App42::Session::SessionService
- Defined in:
- lib/session/SessionService.rb
Overview
The Session Manager manages user sessions on the server side. It is a persistent Session Manager. It allows to save attributes in the session and retrieve them. This Session Manager is especially useful for Mobile/Device Apps which want to do session management.
Instance Method Summary collapse
-
#get_all_attribute(sessionId) ⇒ Object
Gets all the attributes for a given session id.
-
#get_attribute(sessionId, attributeName) ⇒ Object
Gets the attribute value in a session whose session id is provided.
-
#get_session(uName) ⇒ Object
Create Session for the User.
-
#get_session_boolean(uName, isCreate) ⇒ Object
Create User Session based on the isCreate boolean parameter.
-
#initialize(api_key, secret_key, base_url) ⇒ SessionService
constructor
this is a constructor that takes.
-
#invalidate(sessionId) ⇒ Object
Invalidate a session based on the session id.
-
#remove_all_attribute(sessionId) ⇒ Object
Removes all the attributes for a given session id.
-
#remove_attribute(sessionId, attributeName) ⇒ Object
Removes the attribute from a session whose session id is provided.
-
#set_attribute(sessionId, attributeName, attributeValue) ⇒ Object
Sets attribute in a session whose session id is provided.
Constructor Details
#initialize(api_key, secret_key, base_url) ⇒ SessionService
this is a constructor that takes
32 33 34 35 36 37 38 39 |
# File 'lib/session/SessionService.rb', line 32 def initialize(api_key, secret_key, base_url) puts "Session Service->initialize" @api_key = api_key @secret_key = secret_key @base_url = base_url @resource = "session" @version = "1.0" end |
Instance Method Details
#get_all_attribute(sessionId) ⇒ Object
Gets all the attributes for a given session id
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 |
# File 'lib/session/SessionService.rb', line 305 def get_all_attribute(sessionId) puts "Get All Attributes Called " puts "Base url #{@base_url}" response = nil sessionObj = nil sessionObj = Session.new() util = Util.new util.throwExceptionIfNullOrBlank(sessionId,"Session Id") 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("sessionId", sessionId); puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/id/#{sessionId}" response = connection.get(signature, resource_url, query_params) session = SessionResponseBuilder.new sessionObj = session.buildSessionResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return sessionObj end |
#get_attribute(sessionId, attributeName) ⇒ Object
Gets the attribute value in a session whose session id is provided.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/session/SessionService.rb', line 260 def get_attribute(sessionId,attributeName) puts "Get Attribute Called " puts "Base url #{@base_url}" response = nil sessionObj = nil sessionObj = Session.new() util = Util.new util.throwExceptionIfNullOrBlank(sessionId, "Session Id"); util.throwExceptionIfNullOrBlank(attributeName, "Attribute Name"); 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("sessionId", sessionId); params.store("name", attributeName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/id/#{sessionId}/#{attributeName}" response = connection.get(signature, resource_url, query_params) session = SessionResponseBuilder.new sessionObj = session.buildSessionResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return sessionObj end |
#get_session(uName) ⇒ Object
Create Session for the User. If the session does not exist it will create a new session
retrieving attributes.
53 54 55 56 57 58 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 |
# File 'lib/session/SessionService.rb', line 53 def get_session(uName) puts "Get Session Called " puts "Base url #{@base_url}" response = nil sessionObj = nil sessionObj = Session.new() util = Util.new util.throwExceptionIfNullOrBlank(uName, "User Name"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"session"=> { "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) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}" response = connection.post(signature, resource_url, query_params, body) session = SessionResponseBuilder.new sessionObj = session.buildSessionResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return sessionObj end |
#get_session_boolean(uName, isCreate) ⇒ Object
Create User Session based on the isCreate boolean parameter. If isCreate is true and there is an existing session for the user, the existing session is returned. If there is no existing session for the user a new one is created. If isCreate is false and there is an existing session, the existing session is returned if there is no existing session new one is not created
a new one is to be created or not.
retrieving attributes.
108 109 110 111 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 142 143 |
# File 'lib/session/SessionService.rb', line 108 def get_session_boolean(uName, isCreate) puts "Get Session Boolean Called " puts "Base url #{@base_url}" response = nil sessionObj = nil sessionObj = Session.new() util = Util.new util.throwExceptionIfNullOrBlank(uName, "User Name"); util.throwExceptionIfNullOrBlank(isCreate, "Is Create"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"session"=> { "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) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/#{isCreate}" response = connection.post(signature, resource_url, query_params, body) session = SessionResponseBuilder.new sessionObj = session.buildSessionResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return sessionObj end |
#invalidate(sessionId) ⇒ Object
Invalidate a session based on the session id. All the attributes store in the session will be lost.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/session/SessionService.rb', line 156 def invalidate(sessionId) puts "In Validate Called " puts "Base url #{@base_url}" response = nil sessionObj = nil sessionObj = Session.new() util = Util.new util.throwExceptionIfNullOrBlank(sessionId, "Session Id"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"session"=> { "id" => sessionId }}}.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) session = SessionResponseBuilder.new sessionObj = session.buildSessionResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return sessionObj end |
#remove_all_attribute(sessionId) ⇒ Object
Removes all the attributes for a given session id
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/session/SessionService.rb', line 394 def remove_all_attribute(sessionId) puts "Remove All Attributes Called " puts "Base url #{@base_url}" response = nil responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(sessionId, "Session Id"); 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("sessionId", sessionId) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/id/#{sessionId}" 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 |
#remove_attribute(sessionId, attributeName) ⇒ Object
Removes the attribute from a session whose session id is provided.
350 351 352 353 354 355 356 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 |
# File 'lib/session/SessionService.rb', line 350 def remove_attribute(sessionId,attributeName) puts "Remove Attribute Called " puts "Base url #{@base_url}" response = nil responseObj = App42Response.new(); util = Util.new util.throwExceptionIfNullOrBlank(sessionId, "Session Id"); util.throwExceptionIfNullOrBlank(attributeName, "Attribute Name"); 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("sessionId", sessionId) params.store("name", attributeName) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/id/#{sessionId}/#{attributeName}" 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 |
#set_attribute(sessionId, attributeName, attributeValue) ⇒ Object
Sets attribute in a session whose session id is provided. Attributes are stored in a key value pair.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/session/SessionService.rb', line 207 def set_attribute(sessionId,attributeName,attributeValue) puts "Set Attribute Called " puts "Base url #{@base_url}" response = nil sessionObj = nil sessionObj = Session.new() util = Util.new util.throwExceptionIfNullOrBlank(sessionId, "Session Id"); util.throwExceptionIfNullOrBlank(attributeName, "Attribute Name"); util.throwExceptionIfNullOrBlank(attributeValue, "Attribute Value"); begin connection = App42::Connection::RESTConnection.new(@base_url) body = {'app42' => {"session"=> { "name" => attributeName, "value" => attributeValue }}}.to_json puts "Body #{body}" query_params = Hash.new params = { 'apiKey'=> @api_key, 'version' => @version, 'timeStamp' => util., 'sessionId'=> sessionId } query_params = params.clone params.store("body", body) puts query_params signature = util.sign(@secret_key, params) resource_url = "#{@version}/#{@resource}/id/#{sessionId}" response = connection.post(signature, resource_url, query_params, body) session = SessionResponseBuilder.new sessionObj = session.buildSessionResponse(response) rescue App42Exception =>e raise e rescue Exception => e raise App42Exception.new(e) end return sessionObj end |