Class: QueueIt::KnownUser

Inherits:
Object
  • Object
show all
Defined in:
lib/queueit_knownuserv3/known_user.rb

Constant Summary collapse

QUEUEIT_TOKEN_KEY =
"queueittoken"
QUEUEIT_DEBUG_KEY =
"queueitdebug"
@@userInQueueService =
nil

Class Method Summary collapse

Class Method Details

.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request) ⇒ Object



282
283
284
285
286
287
288
289
# File 'lib/queueit_knownuserv3/known_user.rb', line 282

def self.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request)
  debugEntries = Hash.new
  begin
    return _cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries)
  ensure
    setDebugCookie(debugEntries, request.cookie_jar)
  end
end

.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey, request) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/queueit_knownuserv3/known_user.rb', line 165

def self.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey, request)
  if(Utils.isNilOrEmpty(eventId))
    raise KnownUserError, "eventId can not be nil or empty."
  end

  if(Utils.isNilOrEmpty(secretKey))
    raise KnownUserError, "secretKey can not be nil or empty."
  end

  minutes = convertToInt(cookieValidityMinute)
  if(minutes <= 0)
    raise KnownUserError, "cookieValidityMinute should be integer greater than 0."  
  end

  userInQueueService = getUserInQueueService(request.cookie_jar)
  userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey)
end

.getRealOriginalUrl(request) ⇒ Object



291
292
293
294
295
# File 'lib/queueit_knownuserv3/known_user.rb', line 291

def self.getRealOriginalUrl(request)
  # RoR could modify request.original_url if request contains x-forwarded-host/proto http headers.  

  # Therefore we need this method to be able to access the 'real' original url.

  return request.env["rack.url_scheme"] + "://" + request.env["HTTP_HOST"] + request.original_fullpath
end

.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries) ⇒ Object



272
273
274
275
276
277
278
279
280
# File 'lib/queueit_knownuserv3/known_user.rb', line 272

def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
  cancelConfig = CancelEventConfig.new;
  cancelConfig.eventId = matchedConfig["EventId"]
  cancelConfig.queueDomain = matchedConfig["QueueDomain"]
  cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
  cancelConfig.version = customerIntegration["Version"]
          
  return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, request, debugEntries);
end

.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/queueit_knownuserv3/known_user.rb', line 249

def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
  queueConfig = QueueEventConfig.new
  queueConfig.eventId = matchedConfig["EventId"]
  queueConfig.queueDomain = matchedConfig["QueueDomain"]
  queueConfig.layoutName = matchedConfig["LayoutName"]
  queueConfig.culture = matchedConfig["Culture"]
  queueConfig.cookieDomain = matchedConfig["CookieDomain"]
  queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
  queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
  queueConfig.version = customerIntegration["Version"]
  
  case matchedConfig["RedirectLogic"]
    when "ForcedTargetUrl"
      targetUrl = matchedConfig["ForcedTargetUrl"]         
    when "EventTargetUrl"
      targetUrl = ''
    else
      targetUrl = currentUrlWithoutQueueITToken
  end

  return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)   
end

.resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/queueit_knownuserv3/known_user.rb', line 183

def self.resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request)
  debugEntries = Hash.new
  begin
    return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, request, debugEntries)
  ensure
    setDebugCookie(debugEntries, request.cookie_jar)
  end
end

.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationsConfigString, customerId, secretKey, request) ⇒ Object



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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/queueit_knownuserv3/known_user.rb', line 192

def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationsConfigString, customerId, secretKey, request)
  if(Utils.isNilOrEmpty(currentUrlWithoutQueueITToken))
    raise KnownUserError, "currentUrlWithoutQueueITToken can not be nil or empty."
  end

  if(Utils.isNilOrEmpty(integrationsConfigString))
    raise KnownUserError, "integrationsConfigString can not be nil or empty."
  end

  begin
    customerIntegration = JSON.parse(integrationsConfigString)
  
    debugEntries = Hash.new   
    isDebug = getIsDebug(queueitToken, secretKey)
    if(isDebug)
      debugEntries["ConfigVersion"] = customerIntegration["Version"]
      debugEntries["PureUrl"] = currentUrlWithoutQueueITToken
      debugEntries["QueueitToken"] = queueitToken
      debugEntries["OriginalUrl"] = getRealOriginalUrl(request)
      logMoreRequestDetails(debugEntries, request)
    end
  
    integrationEvaluator = IntegrationEvaluator.new
    matchedConfig = integrationEvaluator.getMatchedIntegrationConfig(customerIntegration, currentUrlWithoutQueueITToken, request)

    if(isDebug)
      if(matchedConfig == nil)
        debugEntries["MatchedConfig"] = "NULL"
      else
        debugEntries["MatchedConfig"] = matchedConfig["Name"]
      end
    end

    if(matchedConfig == nil)
      return RequestValidationResult.new(nil, nil, nil, nil)
    end
  
    # unspecified or 'Queue' specified

    if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
      handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
    
    elsif(matchedConfig["ActionType"].eql?(ActionTypes::CANCEL))
      handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, request, debugEntries)
      
    # for all unknown types default to 'Ignore'

    else
      userInQueueService = getUserInQueueService(request.cookie_jar)
      userInQueueService.getIgnoreActionResult()
    end

  rescue StandardError => stdErr
    raise KnownUserError, "integrationConfiguration text was not valid: " + stdErr.message
  ensure
    setDebugCookie(debugEntries, request.cookie_jar)
  end
end