Flatiron Phase One CLI Project

Rachel Marin
3 min readDec 6, 2020

-Asheville Brewery List-

Welcome, in this blog post I will describe my process on how I built my CLI Application.

Asheville! Beer City! Because I live in the beautiful city of Asheville NC, I often see that there is a need for an easy way for locals and tourists to find the right brewery to visit in a vast land of beer, I thought a database with a list of all of Asheville’s breweries would be a great little project to make.

I decided to use an application program interface (API). This API will allow me to add brewery data and functionality to the application I have built. this data will provide a full list of all breweries located in the Asheville city limits along with the option to select a brewery you are interested in knowing more about. Once selected it will give you details like the type of brewery, the street address, postal code, phone number, and website.

Who has time to try and search online for a full list of local breweries?! This app will save you time as you plan your vacation or date night.

This is the process I used to build my CLI.

Install Bundler Gem:

“Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.”

-https://bundler.io/v2.1/#getting-started

To create a gem using Bundler, use the command line bellow.

Example:

#bundle gem <name of your project>

Add an executable file:

Next we want to add an executable file to run our project. I placed mine in my gem’s bin directory. The file itself has to have a shebang line in order to run the file in the right program. Any executable files placed in a bin directory need to begin with the following line.

Example:

#!/usr/bin/env ruby

Since I am using ruby we added “ruby” at the end, but lets say you are using python. Instead, it would look like this.

Example:

#!/usr/bin/env python

After our shebang line, we need the required relative to pull from the required relatives in the environment file (to be created later) along with the class.object.instant to run the program.

Example:

#!/usr/bin/env ruby

require_relative “../lib/environment”

Cli.new.start

Requirements in my environment file:

You want to create an environment file that will have your required relatives along with the required gems.

Example:

require_relative “../lib/asheville_brewery_list/cli.rb”

require_relative “../lib/asheville_brewery_list/api.rb”

require_relative “../lib/asheville_brewery_list/version.rb”

require_relative “../lib/asheville_brewery_list/brewery.rb”

require ‘pry’

require ‘rest-client’

require ‘net/http’

require ‘open-uri’

require ‘json’

Gemspec Folder:

The gemspec file specifies the dependencies information about a gem. You can get error messages if this step is missing. I also made sure to add sourcing for my gems.

Example:

source “https://rubygems.org"

#gemspec

gem ‘json’

gem “pry”

gem “rake”, “~> 12.0”

gem “rest-client”

gem ‘brewery_db’

My API and Object files

I went through three different API’s before I settled on one I felt was giving the the information I wanted to use and would fit well with the app I wanted to make. I parsed the data using JSON so that I could use the information I needed from the API. I also created an Object file that has an object class, attributes, and an initialize method to use the data in my CLI code.

Write The CLI:

As was instructed, I started my CLI once my environment was fully set up.

The CLI (command line interfaces) will obtain the wanted action response from the user and display that information. This is where I will create the greeting to the user along with a menu and instructions to pull the information the user is looking for.

Things started off pretty easy, once I created my class, I created my start method with a system (“clear”) at the top to keep it looking clean. I then added my intro/welcome to the program with some “puts” methods along with a call to the API class. Next it flows into the main menu options. I used an array with an iterated index. I made sure to add a looping method to keep the user from getting stuck on a dead end in the program.

All in all, I am very proud of my first project! I was so proud the moment it ran through without a single error code. I made sure to test it for any bugs or holes and didn't see any in the end. Success! I really enjoyed this project and can’t wait to code more in the future.

She is Seeking to make an income in a career she loves, to create a life full of joy and memorable experiences. Rachel is Looking for a Full-Time Position as a Software Engineer.

Find more from Rachel

Github: https://github.com/rachelmarin

LinkedIn: https://www.linkedin.com/in/rachel-marin/

--

--