Class: QueueIt::UserInQueueService
- Inherits:
-
Object
- Object
- QueueIt::UserInQueueService
- Defined in:
- lib/queueit_knownuserv3/user_in_queue_service.rb
Defined Under Namespace
Classes: TokenValidationResult
Constant Summary collapse
- SDK_VERSION_NO =
"3.7.1"- SDK_VERSION =
"v3-ruby-" + SDK_VERSION_NO
Instance Method Summary collapse
- #extendQueueCookie(eventId, cookieValidityMinutes, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey) ⇒ Object
- #generateRedirectUrl(queueDomain, uriPath, query) ⇒ Object
- #getErrorResult(customerId, targetUrl, config, qParams, errorCode) ⇒ Object
- #getIgnoreActionResult(actionName) ⇒ Object
- #getQueryString(customerId, eventId, configVersion, actionName, culture, layoutName) ⇒ Object
- #getQueueResult(targetUrl, config, customerId) ⇒ Object
- #getValidTokenResult(config, queueParams, secretKey) ⇒ Object
-
#initialize(userInQueueStateRepository) ⇒ UserInQueueService
constructor
A new instance of UserInQueueService.
- #validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey) ⇒ Object
- #validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey) ⇒ Object
- #validateToken(config, queueParams, secretKey) ⇒ Object
Constructor Details
#initialize(userInQueueStateRepository) ⇒ UserInQueueService
Returns a new instance of UserInQueueService.
9 10 11 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 9 def initialize(userInQueueStateRepository) @userInQueueStateRepository = userInQueueStateRepository end |
Instance Method Details
#extendQueueCookie(eventId, cookieValidityMinutes, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey) ⇒ Object
135 136 137 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 135 def extendQueueCookie(eventId, , , isCookieHttpOnly, isCookieSecure, secretKey) @userInQueueStateRepository.reissueQueueCookie(eventId, , , isCookieHttpOnly, isCookieSecure, secretKey) end |
#generateRedirectUrl(queueDomain, uriPath, query) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 128 def generateRedirectUrl(queueDomain, uriPath, query) if (!queueDomain.end_with?("/") ) queueDomain = queueDomain + "/" end return "https://" + queueDomain + uriPath + "?" + query end |
#getErrorResult(customerId, targetUrl, config, qParams, errorCode) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 91 def getErrorResult(customerId, targetUrl, config, qParams, errorCode) query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) + "&queueittoken=" + qParams.queueITToken + "&ts=" + Time.now.getutc.tv_sec.to_s + (!Utils::isNilOrEmpty(targetUrl) ? ("&t=" + Utils.urlEncode(targetUrl)) : "") redirectUrl = generateRedirectUrl(config.queueDomain, "error/" + errorCode + "/", query) return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName) end |
#getIgnoreActionResult(actionName) ⇒ Object
139 140 141 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 139 def getIgnoreActionResult(actionName) return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil, nil, actionName) end |
#getQueryString(customerId, eventId, configVersion, actionName, culture, layoutName) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 111 def getQueryString(customerId, eventId, configVersion, actionName, culture, layoutName) queryStringList = Array.new queryStringList.push("c=" + Utils.urlEncode(customerId)) queryStringList.push("e=" + Utils.urlEncode(eventId)) queryStringList.push("ver=" + SDK_VERSION) queryStringList.push("cver=" + (!configVersion.nil? ? configVersion.to_s : '-1')) queryStringList.push("man=" + Utils.urlEncode(actionName)) if (!Utils::isNilOrEmpty(culture)) queryStringList.push("cid=" + Utils.urlEncode(culture)) end if (!Utils::isNilOrEmpty(layoutName)) queryStringList.push("l=" + Utils.urlEncode(layoutName)) end return queryStringList.join("&") end |
#getQueueResult(targetUrl, config, customerId) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 102 def getQueueResult(targetUrl, config, customerId) query = getQueryString(customerId, config.eventId, config.version, config.actionName, config.culture, config.layoutName) + (!Utils::isNilOrEmpty(targetUrl) ? "&t=" + Utils.urlEncode( targetUrl) : "") redirectUrl = generateRedirectUrl(config.queueDomain, "", query) return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl, nil, config.actionName) end |
#getValidTokenResult(config, queueParams, secretKey) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 77 def getValidTokenResult(config, queueParams, secretKey) @userInQueueStateRepository.store( config.eventId, queueParams.queueId, queueParams., !Utils::isNilOrEmpty(config.) ? config. : '', config.isCookieHttpOnly, config.isCookieSecure, queueParams.redirectType, secretKey) return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil, queueParams.redirectType, config.actionName) end |
#validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 55 def validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey) state = @userInQueueStateRepository.getState(cancelConfig.eventId, -1, secretKey, false) if (state.isValid) @userInQueueStateRepository.cancelQueueCookie(cancelConfig.eventId, cancelConfig., cancelConfig.isCookieHttpOnly, cancelConfig.isCookieSecure) query = getQueryString(customerId, cancelConfig.eventId, cancelConfig.version, cancelConfig.actionName, nil, nil) + (!Utils::isNilOrEmpty(targetUrl) ? ("&r=" + Utils.urlEncode(targetUrl)) : "" ) uriPath = "cancel/" + customerId + "/" + cancelConfig.eventId if(!Utils::isNilOrEmpty(state.queueId)) uriPath = uriPath + "/" + state.queueId end redirectUrl = generateRedirectUrl(cancelConfig.queueDomain, uriPath, query) return RequestValidationResult.new(ActionTypes::CANCEL, cancelConfig.eventId, state.queueId, redirectUrl, state.redirectType, cancelConfig.actionName) else return RequestValidationResult.new(ActionTypes::CANCEL, cancelConfig.eventId, nil, nil, nil, cancelConfig.actionName) end end |
#validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 13 def validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey) state = @userInQueueStateRepository.getState(config.eventId, config., secretKey, true) if (state.isValid) if (state.isStateExtendable && config.extendCookieValidity) @userInQueueStateRepository.store( config.eventId, state.queueId, nil, !Utils::isNilOrEmpty(config.) ? config. : '', config.isCookieHttpOnly, config.isCookieSecure, state.redirectType, secretKey) end return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, state.queueId, nil, state.redirectType, config.actionName) end queueParams = QueueUrlParams::extractQueueParams(queueitToken) requestValidationResult = nil isTokenValid = false if (!queueParams.nil?) tokenValidationResult = validateToken(config, queueParams, secretKey) isTokenValid = tokenValidationResult.isValid if (isTokenValid) requestValidationResult = getValidTokenResult(config, queueParams, secretKey) else requestValidationResult = getErrorResult(customerId, targetUrl, config, queueParams, tokenValidationResult.errorCode) end else requestValidationResult = getQueueResult(targetUrl, config, customerId) end if (state.isFound && !isTokenValid) @userInQueueStateRepository.cancelQueueCookie(config.eventId, config., config.isCookieHttpOnly, config.isCookieSecure); end return requestValidationResult; end |
#validateToken(config, queueParams, secretKey) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 143 def validateToken(config, queueParams, secretKey) calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash) if (calculatedHash.upcase() != queueParams.hashCode.upcase()) return TokenValidationResult.new(false, "hash") end if (queueParams.eventId.upcase() != config.eventId.upcase()) return TokenValidationResult.new(false, "eventid") end if (queueParams.timeStamp < Time.now.getutc.tv_sec) return TokenValidationResult.new(false, "timestamp") end return TokenValidationResult.new(true, nil) end |