Skip to content

Instantly share code, notes, and snippets.

@lisantwi
Last active July 11, 2019 04:39
Show Gist options
  • Save lisantwi/66d75ef40b0fe4a6613a3e8ee445438c to your computer and use it in GitHub Desktop.
Save lisantwi/66d75ef40b0fe4a6613a3e8ee445438c to your computer and use it in GitHub Desktop.
updated fist
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