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"
QUEUEIT_AJAX_HEADER_KEY =
"x-queueit-ajaxpageurl"
@@userInQueueService =
nil

Class Method Summary collapse

Class Method Details

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



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/queueit_knownuserv3/known_user.rb', line 332

def self.cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey)
  debugEntries = Hash.new
  connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)

  if(connectorDiagnostics.hasError)
    return connectorDiagnostics.validationResult
  end
  begin
    return _cancelRequestByLocalConfig(targetUrl, queueitToken, cancelConfig, customerId, secretKey, debugEntries, connectorDiagnostics.isEnabled)
  rescue Exception => e
    if(connectorDiagnostics.isEnabled)
      debugEntries["Exception"] = e.message
    end
    raise e
  ensure
    setDebugCookie(debugEntries)
  end
end

.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/queueit_knownuserv3/known_user.rb', line 177

def self.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
  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()
  userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, isCookieHttpOnly, isCookieSecure, secretKey)
end

.getRealOriginalUrlObject



351
352
353
354
355
356
# File 'lib/queueit_knownuserv3/known_user.rb', line 351

def self.getRealOriginalUrl()
  return HttpContextProvider.httpContext.url
  # 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

.getRuntimeObject



358
359
360
# File 'lib/queueit_knownuserv3/known_user.rb', line 358

def self.getRuntime()
  return RUBY_VERSION.to_s
end

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



319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/queueit_knownuserv3/known_user.rb', line 319

def self.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, debugEntries, isDebug)
  cancelConfig = CancelEventConfig.new
  cancelConfig.eventId = matchedConfig["EventId"]
  cancelConfig.queueDomain = matchedConfig["QueueDomain"]
  cancelConfig.cookieDomain = matchedConfig["CookieDomain"]
  cancelConfig.isCookieHttpOnly = matchedConfig["IsCookieHttpOnly"] || false
  cancelConfig.isCookieSecure = matchedConfig["IsCookieSecure"] || false
  cancelConfig.version = customerIntegration["Version"]
  cancelConfig.actionName = matchedConfig["Name"]

  return _cancelRequestByLocalConfig(currentUrlWithoutQueueITToken, queueitToken, cancelConfig, customerId, secretKey, debugEntries, isDebug)
end

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



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
# File 'lib/queueit_knownuserv3/known_user.rb', line 293

def self.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration, customerId, secretKey, matchedConfig, debugEntries, isDebug)
  queueConfig = QueueEventConfig.new
  queueConfig.eventId = matchedConfig["EventId"]
  queueConfig.layoutName = matchedConfig["LayoutName"]
  queueConfig.culture = matchedConfig["Culture"]
  queueConfig.queueDomain = matchedConfig["QueueDomain"]
  queueConfig.extendCookieValidity = matchedConfig["ExtendCookieValidity"]
  queueConfig.cookieValidityMinute = matchedConfig["CookieValidityMinute"]
  queueConfig.cookieDomain = matchedConfig["CookieDomain"]
  queueConfig.isCookieHttpOnly = matchedConfig["IsCookieHttpOnly"] || false
  queueConfig.isCookieSecure = matchedConfig["IsCookieSecure"] || false
  queueConfig.version = customerIntegration["Version"]
  queueConfig.actionName = matchedConfig["Name"]

  case matchedConfig["RedirectLogic"]
    when "ForcedTargetUrl"
      targetUrl = matchedConfig["ForcedTargetUrl"]
    when "EventTargetUrl"
      targetUrl = ''
    else
      targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken)
  end

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

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



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/queueit_knownuserv3/known_user.rb', line 195

def self.resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey)
  debugEntries = Hash.new
  connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)

  if(connectorDiagnostics.hasError)
    return connectorDiagnostics.validationResult
  end
  begin
    targetUrl = generateTargetUrl(targetUrl)
    return _resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, debugEntries, connectorDiagnostics.isEnabled)
  rescue Exception => e
    if(connectorDiagnostics.isEnabled)
      debugEntries["Exception"] = e.message
    end
    raise e
  ensure
    setDebugCookie(debugEntries)
  end
end

.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey) ⇒ Object



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
248
249
250
251
252
253
254
255
256
257
258
259
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
# File 'lib/queueit_knownuserv3/known_user.rb', line 215

def self.validateRequestByIntegrationConfig(currentUrlWithoutQueueITToken, queueitToken, integrationConfigJson, customerId, secretKey)
  debugEntries = Hash.new
  customerIntegration = Hash.new
  connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken)

  if(connectorDiagnostics.hasError)
    return connectorDiagnostics.validationResult
  end
  begin
    if(connectorDiagnostics.isEnabled)
      debugEntries["SdkVersion"] = UserInQueueService::SDK_VERSION
      debugEntries["Runtime"] = getRuntime()
      debugEntries["PureUrl"] = currentUrlWithoutQueueITToken
      debugEntries["QueueitToken"] = queueitToken
      debugEntries["OriginalUrl"] = getRealOriginalUrl()
      logMoreRequestDetails(debugEntries)
    end

    customerIntegration = JSON.parse(integrationConfigJson)

    if(connectorDiagnostics.isEnabled)
      if(customerIntegration.length != 0 and customerIntegration["Version"] != nil)
        debugEntries["ConfigVersion"] = customerIntegration["Version"]
      else
        debugEntries["ConfigVersion"] = "NULL"
      end
    end

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

    if(customerIntegration.length == 0 || customerIntegration["Version"] == nil)
      raise KnownUserError, "integrationConfigJson is not valid json."
    end

    integrationEvaluator = IntegrationEvaluator.new
    matchedConfig = integrationEvaluator.getMatchedIntegrationConfig(customerIntegration, currentUrlWithoutQueueITToken, HttpContextProvider.httpContext)

    if(connectorDiagnostics.isEnabled)
      if(matchedConfig == nil)
        debugEntries["MatchedConfig"] = "NULL"
      else
        debugEntries["MatchedConfig"] = matchedConfig["Name"]
      end
    end

    if(matchedConfig == nil)
      return RequestValidationResult.new(nil, nil, nil, nil, nil, nil)
    end

    # unspecified or 'Queue' specified
    if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
      return handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
            customerId, secretKey, matchedConfig, debugEntries, connectorDiagnostics.isEnabled)

    elsif(matchedConfig["ActionType"].eql?(ActionTypes::CANCEL))
      return handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegration,
            customerId, secretKey, matchedConfig, debugEntries, connectorDiagnostics.isEnabled)

    # for all unknown types default to 'Ignore'
    else
      userInQueueService = getUserInQueueService()
      result = userInQueueService.getIgnoreActionResult(matchedConfig["Name"])
      result.isAjaxResult = isQueueAjaxCall()

      return result
    end
  rescue Exception => e
    if(connectorDiagnostics.isEnabled)
      debugEntries["Exception"] = e.message
    end
    raise e
  ensure
    setDebugCookie(debugEntries)
  end
end