Skip to content

Commit dcf8534

Browse files
committed
Release KnownUser 3.7.0
1 parent 212acb7 commit dcf8534

12 files changed

Lines changed: 1570 additions & 1151 deletions

README.md

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ the following example of a controller is all that is needed to validate that a u
2424
class ResourceController < ApplicationController
2525
def index
2626
begin
27-
27+
2828
configJson = File.read('integrationconfig.json')
2929
customerId = "" # Your Queue-it customer ID
3030
secretKey = "" # Your 72 char secret key as specified in Go Queue-it self-service platform
31-
31+
3232
requestUrl = request.original_url
3333
pattern = Regexp.new("([\\?&])(" + QueueIt::KnownUser::QUEUEIT_TOKEN_KEY + "=[^&]*)", Regexp::IGNORECASE)
3434
requestUrlWithoutToken = requestUrl.gsub(pattern, '')
@@ -39,39 +39,43 @@ class ResourceController < ApplicationController
3939
#requestUriNoToken = URI.parse(requestUrlWithoutToken)
4040
#requestUriNoToken.host = "INSERT-REPLACEMENT-HOST-HERE"
4141
#requestUrlWithoutToken = requestUriNoToken.to_s
42-
42+
4343
queueitToken = request.query_parameters[QueueIt::KnownUser::QUEUEIT_TOKEN_KEY.to_sym]
4444

45+
# Initialize the SDK with the rails http context (must be done before calling validateRequestByIntegrationConfig)
46+
QueueIt::HttpContextProvider::setHttpContext(QueueIt::RailsHttpContext.new(request))
47+
4548
# Verify if the user has been through the queue
4649
validationResult = QueueIt::KnownUser.validateRequestByIntegrationConfig(
47-
requestUrlWithoutToken,
48-
queueitToken,
49-
configJson,
50-
customerId,
51-
secretKey,
52-
request)
50+
requestUrlWithoutToken,
51+
queueitToken,
52+
configJson,
53+
customerId,
54+
secretKey)
5355

5456
if(validationResult.doRedirect)
5557
#Adding no cache headers to prevent browsers to cache requests
5658
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
5759
response.headers["Pragma"] = "no-cache"
5860
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
5961
#end
60-
62+
6163
if(!validationResult.isAjaxResult)
62-
# Send the user to the queue - either becuase hash was missing or becuase is was invalid
63-
redirect_to validationResult.redirectUrl
64+
# Send the user to the queue - either becuase hash was missing or becuase is was invalid
65+
redirect_to validationResult.redirectUrl
6466
else
65-
head :ok
66-
response.headers[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult.getAjaxRedirectUrl()
67-
end
67+
head :ok
68+
ajaxQueueRedirectHeaderName = validationResult.getAjaxQueueRedirectHeaderKey()
69+
response.headers[ajaxQueueRedirectHeaderName] = validationResult.getAjaxRedirectUrl()
70+
response.headers["Access-Control-Expose-Headers"] = ajaxQueueRedirectHeaderName
71+
end
6872
else
6973
# Request can continue, we remove queueittoken from url to avoid sharing of user specific token
70-
if(requestUrl != requestUrlWithoutToken && validationResult.actionType == "Queue")
74+
if(requestUrl != requestUrlWithoutToken && validationResult.actionType == "Queue")
7175
redirect_to requestUrlWithoutToken
72-
end
76+
end
7377
end
74-
78+
7579
rescue StandardError => stdErr
7680
# There was an error validating the request
7781
# Use your own logging framework to log the error
@@ -93,7 +97,7 @@ The following is an example of how to specify the configuration in code:
9397
class ResourceController < ApplicationController
9498
def index
9599
begin
96-
100+
97101
customerId = "" # Your Queue-it customer ID
98102
secretKey = "" # Your 72 char secret key as specified in Go Queue-it self-service platform
99103
eventConfig = QueueIt::QueueEventConfig.new
@@ -104,41 +108,46 @@ class ResourceController < ApplicationController
104108
eventConfig.extendCookieValidity = true # Should the Queue-it session cookie validity time be extended each time the validation runs?
105109
# eventConfig.culture = "da-DK" # Optional - Culture of the queue layout in the format specified here: https:#msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx. If unspecified then settings from Event will be used.
106110
# eventConfig.layoutName = "NameOfYourCustomLayout" # Optional - Name of the queue layout. If unspecified then settings from Event will be used.
107-
111+
108112
requestUrl = request.original_url
109113
queueitToken = request.query_parameters[QueueIt::KnownUser::QUEUEIT_TOKEN_KEY.to_sym]
110-
114+
115+
# Initialize the SDK with the rails http context (must be done before calling validateRequestByIntegrationConfig)
116+
QueueIt::HttpContextProvider::setHttpContext(QueueIt::RailsHttpContext.new(request))
117+
111118
# Verify if the user has been through the queue
112119
validationResult = QueueIt::KnownUser.resolveQueueRequestByLocalConfig(
113-
requestUrl,
114-
queueitToken,
115-
eventConfig,
116-
customerId,
117-
secretKey,
118-
request)
119-
120+
requestUrl,
121+
queueitToken,
122+
eventConfig,
123+
customerId,
124+
secretKey)
125+
120126
if(validationResult.doRedirect)
121127
#Adding no cache headers to prevent browsers to cache requests
122128
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
123129
response.headers["Pragma"] = "no-cache"
124130
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
125131
#end
126-
if(!validationResult.isAjaxResult)
127-
# Send the user to the queue - either becuase hash was missing or becuase is was invalid
128-
redirect_to validationResult.redirectUrl
132+
if(!validationResult.isAjaxResult)
133+
# Send the user to the queue - either becuase hash was missing or becuase is was invalid
134+
redirect_to validationResult.redirectUrl
129135
else
130-
head :ok
131-
response.headers[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult.getAjaxRedirectUrl()
136+
head :ok
137+
ajaxQueueRedirectHeaderName = validationResult.getAjaxQueueRedirectHeaderKey()
138+
response.headers[ajaxQueueRedirectHeaderName] = validationResult.getAjaxRedirectUrl()
139+
response.headers["Access-Control-Expose-Headers"] = ajaxQueueRedirectHeaderName
132140
end
133141
else
134-
# Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
135-
pattern = Regexp.new("([\\?&])(" + QueueIt::KnownUser::QUEUEIT_TOKEN_KEY + "=[^&]*)", Regexp::IGNORECASE)
136-
requestUrlWithoutToken = requestUrl.gsub(pattern, '')
137-
138-
if(requestUrl != requestUrlWithoutToken && validationResult.actionType == "Queue")
139-
redirect_to requestUrlWithoutToken
140-
end
142+
# Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
143+
pattern = Regexp.new("([\\?&])(" + QueueIt::KnownUser::QUEUEIT_TOKEN_KEY + "=[^&]*)", Regexp::IGNORECASE)
144+
requestUrlWithoutToken = requestUrl.gsub(pattern, '')
145+
146+
if(requestUrl != requestUrlWithoutToken && validationResult.actionType == "Queue")
147+
redirect_to requestUrlWithoutToken
148+
end
141149
end
150+
142151
rescue StandardError => stdErr
143152
# There was an error validating the request
144153
# Use your own logging framework to log the error
@@ -148,3 +157,32 @@ class ResourceController < ApplicationController
148157
end
149158
end
150159
```
160+
161+
## Advanced Features
162+
### Request body trigger
163+
164+
The connector supports triggering on request body content. An example could be a POST call with specific item ID where you want end-users to queue up for.
165+
For this to work, you will need to contact Queue-it support or enable request body triggers in your integration settings in your GO Queue-it platform account.
166+
Once enabled you will need to update your integration so request body is available for the connector.
167+
You need to create a custom RailsHttpContext similar to this one (make sure to inherit from `QueueIt::RailsHttpContext`):
168+
169+
```ruby
170+
class RailsHttpContextWithRequestBody < QueueIt::RailsHttpContext
171+
@request
172+
173+
def initialize(request)
174+
super
175+
@request = request
176+
end
177+
178+
def requestBodyAsString
179+
return @request.raw_post
180+
end
181+
end
182+
```
183+
184+
Then, on each request, before calling the any of the SDK methods, you should initialize the SDK with your custom RailsHttpContext implementation, instead of the RailsHttpContext:
185+
186+
```ruby
187+
QueueIt::HttpContextProvider::setHttpContext(RailsHttpContextWithRequestBody.new(request))
188+
```

lib/queueit_knownuserv3.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require_relative "queueit_knownuserv3/httpcontext_provider"
12
require_relative "queueit_knownuserv3/known_user"
23
require_relative "queueit_knownuserv3/models"
34
require_relative "queueit_knownuserv3/connector_diagnostics"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
module QueueIt
2+
class IHttpContext
3+
4+
def userAgent
5+
raise 'userAgent not implemented'
6+
end
7+
8+
def headers
9+
raise 'headers not implemented'
10+
end
11+
12+
def url
13+
raise 'url not implemented'
14+
end
15+
16+
def userHostAddress
17+
raise 'userHostAddress not implemented'
18+
end
19+
20+
def cookieManager
21+
raise 'cookieManager not implemented'
22+
end
23+
24+
def requestBodyAsString
25+
raise 'requestBodyAsString not implemented'
26+
end
27+
28+
end
29+
30+
class RailsHttpContext < IHttpContext
31+
@request
32+
33+
def initialize(request)
34+
@request = request
35+
end
36+
37+
def userAgent
38+
return @request.user_agent
39+
end
40+
41+
def headers
42+
return @request.headers
43+
end
44+
45+
def url
46+
return @request.env["rack.url_scheme"] + "://" + @request.env["HTTP_HOST"] + @request.original_fullpath
47+
end
48+
49+
def userHostAddress
50+
return @request.remote_ip
51+
end
52+
53+
def cookieManager
54+
cookieManager = CookieManager.new(@request.cookie_jar)
55+
return cookieManager
56+
end
57+
58+
def requestBodyAsString
59+
return ''
60+
end
61+
62+
end
63+
64+
# Used to initialize SDK for each request
65+
class SDKInitializer
66+
67+
def self.setHttpContext(httpContext)
68+
if (httpContext.class < IHttpContext)
69+
HttpContextProvider.setHttpContext(httpContext)
70+
else
71+
raise "httpContext must be a subclass of IHttpContext (e.g. MyHttpContext < IHttpContext)"
72+
end
73+
end
74+
75+
end
76+
77+
class HttpContextProvider
78+
@@httpContext
79+
80+
def self.httpContext
81+
if (defined?(@@httpContext))
82+
return @@httpContext
83+
else
84+
raise "Please initialize the SDK using SDKInitializer.setHttpContext(httpContext) method"
85+
end
86+
end
87+
88+
def self.setHttpContext(httpContext)
89+
@@httpContext = httpContext
90+
end
91+
92+
end
93+
end

0 commit comments

Comments
 (0)