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



253
254
255
256
257
258
259
260
# File 'lib/queueit_knownuserv3/known_user.rb', line 253

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



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/queueit_knownuserv3/known_user.rb', line 152

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

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



170
171
172
173
174
175
176
177
# File 'lib/queueit_knownuserv3/known_user.rb', line 170

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



179
180
181
182
183
184
185
186
187
188
189
190
191
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
248
249
250
251
# File 'lib/queueit_knownuserv3/known_user.rb', line 179

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"] = request.original_url
    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
  
    if(!matchedConfig.key?("ActionType") || Utils.isNilOrEmpty(matchedConfig["ActionType"]) || matchedConfig["ActionType"].eql?(ActionTypes::QUEUE))
      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)     
  
    else # cancel action      

      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
  rescue StandardError => stdErr
    raise KnownUserError, "integrationConfiguration text was not valid: " + stdErr.message
  ensure
    setDebugCookie(debugEntries, request.cookie_jar)
  end
end