Last active
July 11, 2019 04:39
-
-
Save lisantwi/66d75ef40b0fe4a6613a3e8ee445438c to your computer and use it in GitHub Desktop.
updated fist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'open-uri' | |
require 'json' | |
require 'pry' | |
class GetProducts | |
URL = "https://makeup-api.herokuapp.com/api/v1/products.json?product_type=eyeshadow" | |
def get_products | |
uri = URI.parse(URL) | |
response = Net::HTTP.get_response(uri) | |
response.body | |
end | |
def product_list | |
products = JSON.parse(self.get_products) | |
count = 0 | |
products.select do |product| | |
if product["rating"].to_i > 3 && product["price"].to_i < 30 && !product["description"].include?("mica") | |
puts "#{count}. Product Name: #{product["name"]}. Price: #{product["price"]}" | |
count +=1 | |
end | |
end | |
return "Search Complete" | |
end | |
end | |
products = GetProducts.new | |
puts products.product_list | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment