queue_it 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/views/queue_it/cheating_queue.html.erb +3 -0
- data/app/views/queue_it/enter_queue.html.erb +3 -0
- data/lib/queue_it/known_user_checker.rb +60 -0
- data/lib/queue_it/queueable.rb +49 -0
- data/lib/queue_it/railtie.rb +7 -0
- data/lib/queue_it/url_builder.rb +45 -0
- data/lib/queue_it/version.rb +3 -0
- data/lib/queue_it.rb +10 -0
- data/queue_it.gemspec +23 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kasper Grubbe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# QueueIt
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'queue_it'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install queue_it
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require "queue_it/url_builder"
|
3
|
+
|
4
|
+
module QueueIt
|
5
|
+
class KnownUserChecker
|
6
|
+
|
7
|
+
attr_accessor :shared_event_key, :event_id, :customer_id
|
8
|
+
|
9
|
+
def initialize(shared_event_key, event_id, customer_id)
|
10
|
+
self.shared_event_key = shared_event_key
|
11
|
+
self.event_id = event_id
|
12
|
+
self.customer_id = customer_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# This is bound to Rails!
|
16
|
+
def create_or_verify_queue_it_session!(url, params)
|
17
|
+
queue_id = params['q' ] # A QuID, the user’s queue ID
|
18
|
+
encrypted_place_in_queue = params['p' ] # A text, an encrypted version of the user’s queue number
|
19
|
+
expected_hash = params['h' ] # An integer calculated hash
|
20
|
+
timestamp = params['ts'] # An integer timestamp counting number of seconds since 1970-01-01 00:00:00 UTC
|
21
|
+
|
22
|
+
verify_request!(url, queue_id, encrypted_place_in_queue, expected_hash, timestamp)
|
23
|
+
end
|
24
|
+
|
25
|
+
def verify_request!(url, queue_id, encrypted_place_in_queue, expected_hash, timestamp)
|
26
|
+
if verify_md5_hash?(url, queue_id, encrypted_place_in_queue, expected_hash, timestamp)
|
27
|
+
decrypted_place_in_queue(encrypted_place_in_queue)
|
28
|
+
else
|
29
|
+
raise QueueIt::NotAuthorized.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# uses one char of each string at a given starting point
|
36
|
+
# given b852fe78-0d10-4254-823c-f8749c401153 should get 4212870
|
37
|
+
def decrypted_place_in_queue(encrypted_place_in_queue)
|
38
|
+
return encrypted_place_in_queue[ 30..30 ] + encrypted_place_in_queue[ 3..3 ] + encrypted_place_in_queue[ 11..11 ] +
|
39
|
+
encrypted_place_in_queue[ 20..20 ] + encrypted_place_in_queue[ 7..7 ] + encrypted_place_in_queue[ 26..26 ] +
|
40
|
+
encrypted_place_in_queue[ 9..9 ]
|
41
|
+
end
|
42
|
+
|
43
|
+
# TODO add timestamp check
|
44
|
+
def verify_md5_hash?(url, queue_id, encrypted_place_in_queue, expected_hash, timestamp)
|
45
|
+
raise QueueIt::MissingArgsGiven.new if [ url, queue_id, encrypted_place_in_queue, timestamp, expected_hash ].any?( &:nil? )
|
46
|
+
|
47
|
+
url_no_hash = "#{ url[ 0..-33 ] }#{ shared_event_key }" # Remove hash value and add SharedEventKey
|
48
|
+
actual_hash = Digest::MD5.hexdigest( utf8_encode( url_no_hash ) )
|
49
|
+
|
50
|
+
return false unless expected_hash == actual_hash
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def utf8_encode(s)
|
55
|
+
s.encode('UTF-8', 'UTF-8')
|
56
|
+
s
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module QueueIt
|
2
|
+
module Queueable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
def queue_it_queue_id(event_id)
|
7
|
+
session[queue_it_session_variable(event_id)].to_i
|
8
|
+
end
|
9
|
+
|
10
|
+
def destroy_all_queue_it_sessions
|
11
|
+
session_variable_prefix = queue_it_session_variable("")
|
12
|
+
session.reject!{ |session_key| session_key.start_with?(session_variable_prefix) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy_queue_it_session(event_id)
|
16
|
+
session.delete(queue_it_session_variable(event_id))
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_or_verify_queue_it_session(secret_key, event_id, customer_id, request_url, params)
|
20
|
+
# If there exists a session, we return. This needs to be refactored when we start to look at the timestamp parameter
|
21
|
+
return if session[queue_it_session_variable(event_id)].present?
|
22
|
+
|
23
|
+
begin
|
24
|
+
user_checker = QueueIt::KnownUserChecker.new(secret_key, event_id, customer_id)
|
25
|
+
session[queue_it_session_variable(event_id)] = user_checker.create_or_verify_queue_it_session!(request_url, params)
|
26
|
+
|
27
|
+
# If the request URL contains queue_it params we remove them and redirect
|
28
|
+
# this is done to mask the params we use to create and verify the queue_it session
|
29
|
+
if QueueIt::UrlBuilder.contains_queue_params?(request_url)
|
30
|
+
redirect_to QueueIt::UrlBuilder.clean_url(request_url) and return
|
31
|
+
end
|
32
|
+
rescue QueueIt::MissingArgsGiven
|
33
|
+
queue_url = QueueIt::UrlBuilder.build_queue_url(customer_id, event_id)
|
34
|
+
render("queue_it/enter_queue", layout: false, locals: { queue_it_url: queue_url }) and return
|
35
|
+
rescue QueueIt::NotAuthorized
|
36
|
+
queue_cancel_url = QueueIt::UrlBuilder.build_cancel_url(customer_id, event_id)
|
37
|
+
render("queue_it/cheating_queue", layout: false, locals: { queue_it_url: queue_cancel_url }) and return
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def queue_it_session_variable(event_id)
|
43
|
+
"KnownQueueItUser-#{event_id}"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
module QueueIt
|
4
|
+
class UrlBuilder
|
5
|
+
def self.build_queue_url(customer_id, event_id)
|
6
|
+
"http://q.queue-it.net/?c=#{customer_id}&e=#{event_id}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.build_cancel_url(customer_id, event_id, queue_id = nil)
|
10
|
+
"http://q.queue-it.net/cancel.aspx?c=#{customer_id}&e=#{event_id}&q=#{queue_id}"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Removes all queue_it params from URL
|
14
|
+
# eg.:
|
15
|
+
# http://billetto.com/events/distortion/tickets?q=3d2d5097-c7e1-40e3-8d55-4bb721819324&p=56d0f360-4201-4e47-90d9-333872063976&ts=1393411468&c=billettodk&e=rainmaking&rt=Queue&h=0931dc67562c9a25c7a37bad33a6b46a
|
16
|
+
# to:
|
17
|
+
# http://billetto.com/events/distortion/tickets
|
18
|
+
def self.clean_url(request_url)
|
19
|
+
uri = Addressable::URI.parse(request_url)
|
20
|
+
|
21
|
+
params = uri.query_values
|
22
|
+
queue_it_params.each do |param|
|
23
|
+
params.delete(param)
|
24
|
+
end
|
25
|
+
|
26
|
+
uri.query_values = params
|
27
|
+
uri.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.contains_queue_params?(request_url)
|
31
|
+
uri = Addressable::URI.parse(request_url)
|
32
|
+
request_params = uri.query_values
|
33
|
+
|
34
|
+
# Check if request_params contains any queue_it_params
|
35
|
+
!(queue_it_params & request_params.keys).empty?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def self.queue_it_params
|
40
|
+
['q', 'p', 'h', 'ts', 'e', 'rt', 'c']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
data/lib/queue_it.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "queue_it/version"
|
2
|
+
require "queue_it/known_user_checker"
|
3
|
+
|
4
|
+
module QueueIt
|
5
|
+
class NotAuthorized < StandardError; end
|
6
|
+
class MissingArgsGiven < StandardError; end
|
7
|
+
end
|
8
|
+
|
9
|
+
require "queue_it/queueable" if defined?(::Rails)
|
10
|
+
require "queue_it/railtie" if defined?(::Rails)
|
data/queue_it.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'queue_it/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "queue_it"
|
8
|
+
spec.version = QueueIt::VERSION
|
9
|
+
spec.authors = ["Kasper Grubbe"]
|
10
|
+
spec.email = ["kawsper@gmail.com"]
|
11
|
+
spec.description = %q{Gem to handle the implementation of http://queue-it.net!}
|
12
|
+
spec.summary = %q{Gem to handle the implementation of http://queue-it.net}
|
13
|
+
spec.homepage = "https://github.com/gfish/queue_it"
|
14
|
+
spec.license = "GNU/GPLv3"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: queue_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kasper Grubbe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Gem to handle the implementation of http://queue-it.net!
|
47
|
+
email:
|
48
|
+
- kawsper@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- app/views/queue_it/cheating_queue.html.erb
|
59
|
+
- app/views/queue_it/enter_queue.html.erb
|
60
|
+
- lib/queue_it.rb
|
61
|
+
- lib/queue_it/known_user_checker.rb
|
62
|
+
- lib/queue_it/queueable.rb
|
63
|
+
- lib/queue_it/railtie.rb
|
64
|
+
- lib/queue_it/url_builder.rb
|
65
|
+
- lib/queue_it/version.rb
|
66
|
+
- queue_it.gemspec
|
67
|
+
homepage: https://github.com/gfish/queue_it
|
68
|
+
licenses:
|
69
|
+
- GNU/GPLv3
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.23
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Gem to handle the implementation of http://queue-it.net
|
92
|
+
test_files: []
|