A homemade quick app (1 weekend POC) to self-book me into my two gym's (CLT & CRC) pilates and Group Cycle classes respectively (because they always get full). Multi-tenant so my friends can use it as well.
The scraping tasks run every 5 minutes. You can also trigger them manually from the admin's "Desired Bookings" tab.
The CRC gym provides a mobile application so there is a RESTful API we can leverage (as opposed to the web-scraping for CLT).
The admin user must first configure their crc_email and crc_password from the dashboard.
Every five minutes, a job is triggered for each enabled booking that performs the following steps:
- Calculates the next date and time for the booking based on the desired day of the week and time.
- If this datetime is more than 24 hours in the future, it simply skips since CRC does not permit bookings made too far in advance.
- Checks if a booking for the same datetime already exists in our database. If it does, it skips.
- If the
admin_userrow lacks acrc_user_idorcrc_token, we will first initiate an HTTP POST request to log in and retrieve these credentials, storing them for future use (until they expire). - Performs an HTTP GET request to locate the class ID that matches the user’s desired booking settings.
- After identifying the class id, the job proceeds with an HTTP POST request to book the class. Depending on the response result, it re-authenticates and retries, or attempts the next preferred station (aka bike).
- Once the booking succeeds, it creates a
bookingrecord, to prevent redundant booking attempts. This is crucial especially if a booking was intentionally cancelled via the CRC app to prevent unintentional re-booking.
- Postgres
- Redis
- liv (
brew install vips) - Ruby (Recommendations: install with
rbenv)
Clone this repository on your local machine.
Install the correct version of ruby that you can find in .ruby-version file.
Example with rbenv (double-check project ruby version in Gemfile in case it got updated):
rbenv install 3.2.2; rbenv local 3.2.2;gem install bundler
bundle install
gem install foremanMake sure you have postgres running.
Copy the file .env.example as .env and adjust if needed. The keys are just sample keys, so if you need them, ask a fellow developer.
rake db:create; rake db:schema:load(It will create two databases: never-miss-pilates_development and never-miss-pilates_test)
bundle exec rspecbundle exec rails linters -aMake sure you have postgres and redis running.
You can use foreman to start the server so you don't have to start sidekiq in a different terminal:
foreman start -f Procfile.devThen access the API on http://0.0.0.0:5100
For the CLT gym, booking relies on the heroku-buildpack-chrome-for-testing. Add it with:
heroku buildpacks:add -i 1 heroku-community/chrome-for-testing -a never-miss-pilates- It has new relic setup with structured logging so every step is logged and can be tracked.
- Error are reported into Bugsnag with custom tracing of important decisions to ease debugging.