Building My First App
Published: 2021-03-01 00:01:28

Four weeks in, I understood methods, could even write loops, and was finally grasping the concept of “self.” I was learning a lot but still had little idea what I was doing. Things were stressful, but learning how to code was exciting.

Then came the first project - build a CLI app using a public API. Not only did I not know what an API was, I had also been working with ruby for the first time in my life for a total of four weeks. I was overwhelmed with fear and anxiety. 

But trepidation eventually fizzles out. When it did, I realized that this could be fun. I finally get to apply my knowledge and everything I’ve learned.

***

##GETTING STARTED
After some mild procrastination and application of poor coping mechanisms, I remembered that art gets my heart beating. Once I settled on art, I searched and stumbled across the Art Institute’s public API. It was easy to use, and their documentation page laid everything out.

Things were starting to make sense, but I still didn’t know exactly how to start. There were so many different ways to begin. Tiny steps - I started with creating the folders and files I needed: bin folder with a run file, config folder with the environment file, lib folder with the cli/app file, and finally a Gemfile. 

From there I could start adding code, like ones necessary for the program to run. With only two lines of code, the run file was a good place to begin. In it we “require_relative” a local file, environment.rb. In addition, I also added code for the app (App class) to create a new instance of itself with 
`App.new.start`. 

Next, was the environment file, where we “require” native gems as well as others. For non-native gems, I used Bundler, which finds all the gems in the  Gemfile, along with their dependencies. To do so, I added the code `Bundler.require` immediately following `require "bundler/setup"`. Finishing the environment file, I “require_relative” all the files in the lib folder. 

* * *

##THE CODE: ACTUALLY STARTING
Once I had everything set up, I had to actually think about my app and, more specifically, what I wanted it to do. The Art Institute has a keyword API, where I can search for specific artworks relating to any keyword. With that, I can build an artwork generator that finds and returns an artwork based on keywords. 

At first I wanted to start by building classes in the lib folder, but the more and more I thought about it, the less it made sense. *Tiny steps* - start with functionality, like how would I present things to the user and, furthermore, collect their input. If I were the user, what would I like? How do I streamline the app to make it both aesthetically appealing and easy to use?

**Menus**. Menus would present the user with a list of options, in which they would select one and have something returned. In addition, it also solves the issue of the user entering things incorrectly or something I didn’t anticipate. 

###TTY::PROMPT
Luckily, ruby has a plethora of gems that simplifies the process of creating a menu and gathering user input, with TTY::PROMPT as a particularly useful one. TTY::PROMPT offers a variety of interactive prompts with clean styling. 

Before I could begin, I had to create a new instance of the gem class with `TTY::PROMPT.new`. I chose to make it a constant and added the code to the environment file. 

TTY::PROMPT has an ask method that asks the user for simple input, such as their name, but I wanted to use that input for a greeting so I wrote a gets.chomp method to collect their name instead. 

Then, I wrote my first menu using the select method. (TTY::PROMPT has a good, thorough Readme that explains its interface and how to use it). I defined an array of choices with hash values and keys. Next, I used the values in a case statement that matched each value to a specific condition - when the user chooses to exit, the program exits.

TTY::PROMPT was a game changer. With it I could interact with the user and gather their input, while also maintaining a clean, friendly interface. 

* * *

Building my first app was a whirlwind of emotions. At one point, I was in bed, under the covers in the fetal position, listening to sad music, wondering whether I could truly pull this off. With tiny steps in mind and an endless supply of Red Bull, I did. And there’s a thrill to building something and watching it grow and develop with every line of code.