Finding the Meaning of Life with Ruby…My First Week at a Coding Bootcamp
From the greatest minds in history to the everyday person, people spend their entire life asking the question, what is the meaning of life?
After a short 21 years of life and a week at The Flatiron School, I have found the answer and want to share it, all I need is a phone number. No, seriously. Using Ruby and Twilio I was able to build a program that only tells only a select few people what the meaning of life is.
How the App Works
So how does Ruby know the meaning of life, let me tell you.
The app I built is a command line app that works by responding to user inputs and involves their cell phone. When the app pops open a user will see:
What the user must do is enter their cellphone number, and then the magic happens.
The app takes in the cellphone number, and uses Twilio to send a text message to that person’s phone with a unique code. This ensures that them, and only them, giving them access to the most important information to ever be passed to a human.
The user then takes this number and enters it into the command line and then…
You find out the meaning of life is YOLO.
If you haven’t realized, Drake is basically God, so now it’s time to get out from the rock you live under and start living your life knowing this is your only life!
How It Was Built
As mentioned, this command line app was built in Ruby and used the Twilio REST API.
The first thing I did was sign up for a free account with Twilio here. This trial does have some limitations, including only having one phone number, and having to confirm each phone number to which you want to send an SMS. You can learn more about the restrictions here.
Once I was signed up, I dove right in and started building the system for sending a SMS, which was fairly straightforward. I created a new phone number, downloaded the twilio-ruby gem, and then looked into the documentation to see how to send out a message. But first, things first; I needed to create a way to interact with the user.
Interacting With The User
For the part of the program that interacted with the user, a simple prompt came up asking for the user’s phone number.
After getting the user’s number I create a new Messages instance from the class shown below.
The Messages class takes in a phone number when being initialized, and is used later for the address.
Then I created a method called full_send, which is where the message is actually sent. A random verification code is created, and is then used to verify the user. The account SID and the Authorization Token are put in, then the REST API is accessed. Then all that is needed is the phone number from Twilio (you receive it with your account), the recipient (which comes from the user’s input), and a message which contains the verification code.
Then the message is sent to the user’s phone, and they must enter it into the prompt.
This is a simple loop which runs until the user types in the correct code that is sent to their phone. The four digit code that is sent is created for that method call, and must match the user’s input. The person has ten tries, otherwise they are locked out from the meaning of life (you can’t hear us now).
If they get it right, the message is theirs and the program is over.
Overall this was a great project that did not take too long, and it covered a fair amount of Ruby that I’ve learned this week! The Flatiron School has been incredible and I can’t wait for the weeks ahead!
The meaning of life on github.