-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation
- Introduction
- Installation
- Getting Started
- Methods
- Uninstall UserQ
- Contributing
UserQ is a user-queue engine. Tell it how many items (i.e. tickets to sell) you've got and we'll magically create a queue - allowing people to reserve a place and then complete their transaction in a certain time limit (but only much quicker).
An example of a website using a UserQ-like plugin is Ticketmaster.
We think a utility like UserQ massively helps with engagement rates and user experience. We use it so you don't see a ticket form if you aren't guaranteed a ticket. Nothing good enough to serve that purpose exists so we built UserQ.
UserQ is lightweight and very reliable. In fact, it is already used on production through the StudentHack website with over 50% of ticket reservations powered by UserQ converting into a paid ticket sale. We love it and we think you will too.
There are three ways you can get UserQ on your application. The first two (stable versions) are recommended as they are production ready.
Install as a gem (Stable)
$ gem install userq
$ rails generate userq:install
Install using Bundler (Stable)
In your Gemfile, add
gem "userq"
Then run the following
$ bundle install
$ rails generate userq:install
You want bleeding-edge. Go wild.
$ git clone https://github.com/studenthack/userq.git
Nothing better than a few code examples to get you started.
A single Queue consists of many entries. Most only need to use a single UserQ queue.
single_queue = UserQ::Queue.new(capacity: 10)
premium_queue = UserQ::Queue.new(context: 'premium', capacity: 10)
standard_queue = UserQ::Queue.new(context: 'standard', capacity: 50)
single_queue = UserQ::Queue.new(capacity: 10)
if single_queue.enter_into_queue?
entry_id = single_queue.enter.code
# now we can deal with entries
else
# refresh this page every n seconds
# the code below tells them how long their waiting time is
# puts single_queue.avg_wait_time => "Less than a minute remaining"
end
This acts for people who are successfully given a place in the queue (i.e. shown the ticket purchase form in the ticket queue).
entry = UserQ::Entry.new(entry_id)
entry = UserQ::Entry.new(entry_id)
if entry.valid_context?("premium")
throw "You are not from the premium queue"
end
entry = UserQ::Entry.new(entry_id)
entry.expires # => 180
entry.extend(10) # => 190
# entry.shorten(30) # => 160
# entry.expired? # => false
# entry.alive? # => true
single_queue = UserQ::Queue.new(capacity: 10)
custom_data = { "first_name" => "Bob", "last_name" => "Smith" }
entry = single_queue.enter(custom_data)
# Get first name
first_name = entry.data["first_name"]
single_queue = UserQ::Queue.new(capacity: 10, auto_clean: false)
single_queue = UserQ::Queue.new(capacity: 10)
single_queue.reset
# Create new Queue
new(constraints)
# Update constraints
constraints(constraints) # => { constraints }
constraint(constraints) # => { constraints }
# Queue status
enter_into_queue? # => true/false
empty? # => true/false
# Waiting time
nearest_entry() # => 180
avg_wait_time() # => "approximately 2 minutes"
# Create entry in queue
enter()
enter(custom_data)
# Manage queue
empty_queue() # => true
reset() # => true
# New entry
new(entry_id)
# Verify the context
valid_context?(context)
# Entry status
expired? # => true/false
alive? # => true/false
expires # => integer of seconds left
alive # => integer of seconds entry has been alive
# Immediately expire entry (but not delete)
expire # => true
# Alter entry
extend(seconds) # => integer of seconds left
shorten(seconds) # => integer of seconds left
# Expire and delete entry
remove # => true
removed? # => true/false
# Get custom data (if applicable)
data # => object of custom data
Revoke the UserQ migration:
$ rake db:rollback
Remove everything UserQ:
$ rails destroy userq:install
Directly clone the repository (or fork it and clone your fork):
$ git clone https://github.com/studenthack/userq.git
Do some awesome stuff. To test simply run
$ rake test
We love pull requests! Make sure you write a test for your contribution.