Class: QueueIt::UserInQueueService

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

Constant Summary collapse

SDK_VERSION =
"3.4.0"

Instance Method Summary collapse

Constructor Details

#initialize(userInQueueStateRepository) ⇒ UserInQueueService

Returns a new instance of UserInQueueService.



8
9
10
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 8

def initialize(userInQueueStateRepository)
  @userInQueueStateRepository = userInQueueStateRepository
end

Instance Method Details

#extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey) ⇒ Object



112
113
114
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 112

def extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey) 
  @userInQueueStateRepository.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey)
end

#getIgnoreActionResultObject



116
117
118
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 116

def getIgnoreActionResult()
  return RequestValidationResult.new(ActionTypes::IGNORE, nil, nil, nil)
end

#getInQueueRedirectResult(targetUrl, config, customerId) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 89

def getInQueueRedirectResult(targetUrl, config, customerId) 
  redirectUrl = "https://" + config.queueDomain + 
    "?" + getQueryString(customerId, config.eventId, config.version, config.culture, config.layoutName) + 
    (!Utils::isNilOrEmpty(targetUrl) ? "&t=" +  
    CGI.escape( targetUrl) : "")
  return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl)        
end

#getQueryString(customerId, eventId, configVersion, culture, layoutName) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 97

def getQueryString(customerId, eventId, configVersion, culture, layoutName) 
  queryStringList = Array.new 
  queryStringList.push("c=" + CGI.escape(customerId))
  queryStringList.push("e=" + CGI.escape(eventId))
  queryStringList.push("ver=v3-ruby-" + SDK_VERSION) 
  queryStringList.push("cver=" + (!configVersion.nil? ? configVersion.to_s : '-1'))
  if (!Utils::isNilOrEmpty(culture)) 
    queryStringList.push("cid=" + CGI.escape(culture))
  end
  if (!Utils::isNilOrEmpty(layoutName)) 
    queryStringList.push("l=" + CGI.escape(layoutName))
  end
  return queryStringList.join("&")
end

#getQueueITTokenValidationResult(targetUrl, eventId, config, queueParams, customerId, secretKey) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 54

def getQueueITTokenValidationResult(targetUrl, eventId, config, queueParams,customerId, secretKey) 
  calculatedHash = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueParams.queueITTokenWithoutHash) 
  if (calculatedHash.upcase() != queueParams.hashCode.upcase()) 
    return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "hash")
  end
  if (queueParams.eventId.upcase() != eventId.upcase()) 
    return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "eventid")
  end
  if (queueParams.timeStamp < Time.now.getutc.tv_sec) 
    return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "timestamp")
  end

  @userInQueueStateRepository.store(
    config.eventId,
    queueParams.queueId,
    queueParams.extendableCookie,
    !(queueParams.cookieValidityMinute.nil?) ? queueParams.cookieValidityMinute : config.cookieValidityMinute,
    !Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
    secretKey)
  return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, queueParams.queueId, nil)
end

#getVaidationErrorResult(customerId, targetUrl, config, qParams, errorCode) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 76

def getVaidationErrorResult(customerId, targetUrl, config, qParams, errorCode) 
  query = getQueryString(customerId, config.eventId, config.version, config.culture, config.layoutName) +
    "&queueittoken=" + qParams.queueITToken +
    "&ts=" + Time.now.getutc.tv_sec.to_s +
    (!Utils::isNilOrEmpty(targetUrl) ? ("&t=" +  CGI.escape(targetUrl)) : "")
  domainAlias = config.queueDomain
  if (!domainAlias.end_with?("/") )
    domainAlias = domainAlias + "/"
  end
  redirectUrl = "https://" + domainAlias + "error/" + errorCode + "/?"  + query
  return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, nil, redirectUrl)        
end

#validateCancelRequest(targetUrl, config, customerId, secretKey) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 35

def validateCancelRequest(targetUrl, config, customerId, secretKey)
  state = @userInQueueStateRepository.getState(config.eventId, secretKey)
  if (state.isValid)
    @userInQueueStateRepository.cancelQueueCookie(config.eventId, config.cookieDomain)

    query = getQueryString(customerId, config.eventId, config.version, nil, nil) + ( !Utils::isNilOrEmpty(targetUrl) ? ("&r=" +  CGI.escape(targetUrl)) : "" )
  
    domainAlias = config.queueDomain
    if (!domainAlias.end_with?("/") )
      domainAlias = domainAlias + "/"
    end
  
    redirectUrl = "https://" + domainAlias + "cancel/" + customerId + "/" + config.eventId + "/?" + query;
    return RequestValidationResult.new(ActionTypes::CANCEL, config.eventId, state.queueId, redirectUrl)     
  else
    return RequestValidationResult.new(ActionTypes::CANCEL, config.eventId, nil, nil)     
  end
end

#validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/queueit_knownuserv3/user_in_queue_service.rb', line 12

def validateQueueRequest(targetUrl, queueitToken, config, customerId, secretKey)
  state = @userInQueueStateRepository.getState(config.eventId, secretKey)
  if (state.isValid)
    if (state.isStateExtendable && config.extendCookieValidity) 
      @userInQueueStateRepository.store(
        config.eventId,
        state.queueId,
        true,
        config.cookieValidityMinute,
        !Utils::isNilOrEmpty(config.cookieDomain) ? config.cookieDomain : '',
        secretKey)
    end
    return RequestValidationResult.new(ActionTypes::QUEUE, config.eventId, state.queueId, nil)                  
  end
      
  queueParams = QueueUrlParams::extractQueueParams(queueitToken)
  if(!queueParams.nil?) 
    return getQueueITTokenValidationResult(targetUrl, config.eventId, config, queueParams, customerId, secretKey)
  else 
    return getInQueueRedirectResult(targetUrl, config, customerId)
  end
end