Skip to content

this is an educational exercise to practice using a gen servers with an external API using producers, producer_consumers, and consumers

Notifications You must be signed in to change notification settings

ZackAttax/mocktail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mocktail

Description

This is a learning excercise to practice what I have learned in Elixir using Gen Servers Producers, Producer/Consumers, and Consumers with an external API. Using these tools the aim is to download pictures of smart active cats!

App Flow Chart

The app is given a list of cat breeds

The producer pulls from this list and passes them to the producer_consumer

The producer_consumer then filters the cats. We only want pictures of cats with an energy level greater than 5 and adaptability of greater than 2

The consumer then generates a name for the cat, gets the temperaments of the cat, full breed name, and downloads a picture. The cat picture is sent to the pic_server where it is stored in a map with the name as a key, the cats temparement and name is sent to the temparment_server here the cats name is stored in a list under the keys of its temperaments, and finally the name and breed are sent to the cat_breed_server where the name of the cat is stored in a list under the key of the cat breed.

While this is happening a list of available breeds and temperaments are printed in the console.

We now have our cat information stored in the state of our three GenServers cat_breed_server, temparment_server, pic_server. We can extract this information with the use of the functions below.

Mocktail.get_breed/1 to get a list of cats of a particular breed

Mocktail.get_temperament/1 to get a list of cats with a particular temperament

Mocktail.get_pics_of_breed/1 to download pictures of a particular breed to /cat_pics

Mocktail.get_pics_of_temperament/1 to downloads pictures of a particular temperament to /cat_pics

Mocktail.get_pics/1 takes a list of cat names and downloads pictures to /cat_pics

Mocktail.get_pic_of/1 takes a cat's name and downloads pictures to /cat_pics

Instructions

I use asdf to manage my versions of Elixir and Erlang(among others)

Install Erlang 25.2.1

Install Elixir 1.14

clone the repo from Github

get an api key from https://thecatapi.com/#pricing

run mix deps.get

start the app with API_KEY=(your api key here) iex -S mix

As pictures are downloaded the temperaments and breeds available will print in the console. Below is a list of functions you can copy and paste if you see thier arguments as Available.

Mocktail.get_breed("Cymric")

Mocktail.get_temperament("Gentle")

Mocktail.get_pics_of_breed("Balinese")

Mocktail.get_pics_of_temperament("Loyal")

About

this is an educational exercise to practice using a gen servers with an external API using producers, producer_consumers, and consumers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages