Class: DailyRecipe::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/daily_recipe/Recipe.rb

Constant Summary collapse

BASE_URL =
"http://www.foodnetwork.com"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#api_idObject

Returns the value of attribute api_id.



4
5
6
# File 'lib/daily_recipe/Recipe.rb', line 4

def api_id
  @api_id
end

#cook_timeObject

Returns the value of attribute cook_time.



4
5
6
# File 'lib/daily_recipe/Recipe.rb', line 4

def cook_time
  @cook_time
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/daily_recipe/Recipe.rb', line 4

def name
  @name
end

#ratingObject

Returns the value of attribute rating.



4
5
6
# File 'lib/daily_recipe/Recipe.rb', line 4

def rating
  @rating
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/daily_recipe/Recipe.rb', line 4

def url
  @url
end

Class Method Details

.get_rating(api_id) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/daily_recipe/Recipe.rb', line 31

def self.get_rating(api_id) #@beingy is the man
  gigya_api_url = "http://comments.us1.gigya.com/comments.getStreamInfo?categoryID=recipe&streamID=API_ID&includeRatingDetails=true&APIKey=3_ClDcX23A7tU8pcydnKyENXSYP5kxCbwH4ZO741ZOujPRY8Ksj2UBnj8Zopb0OX0K&sdk=js_6.3.02&format=jsonp&callback=gigya._.apiAdapters.web.callback"
  api_id_url = gigya_api_url.gsub("API_ID", api_id)
  recipe_json = Nokogiri::HTML(open(api_id_url))
  part1 = recipe_json.text.gsub("gigya._.apiAdapters.web.callback(","")
  part2 = part1.gsub("});","}")
  parsed = JSON.parse(part2, symbolize_names: true)
  #binding.pry
  rating = parsed[:streamInfo][:avgRatings][:_overall]
  rating
end

.scrape_food_networkObject

def self.scrape_recipes

self.scrape_food_network

end



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/daily_recipe/Recipe.rb', line 15

def self.scrape_food_network
  recipes = []
  doc = Nokogiri::HTML(open("http://www.foodnetwork.com/recipes/photos/recipe-of-the-day-what-to-cook-now.html"))
  doc.search(".feed li").each do |x|
    #binding.pry
    recipe = self.new
    recipe.name = x.search("h6 a").text
    recipe.cook_time = x.search("dd").text
    recipe.api_id = (x.css("a.community-rating-stars").attribute("data-rating").value).scan(/\w+\-.+\w+/).join("-")
    recipe.url = BASE_URL + x.search(".community-rating-stars").attribute("href").value
    recipe.rating = get_rating(recipe.api_id)
    recipes << recipe
  end
  recipes
end

.scrape_full_recipe(the_recipe) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/daily_recipe/Recipe.rb', line 43

def self.scrape_full_recipe(the_recipe)

  doc = Nokogiri::HTML(open(the_recipe.url))
  ingredients = doc.search("div.ingredients li")
  puts ""
  puts "Ingredients"
  ingredients.each do |ingredient|
    puts ingredient.text
  end

  cooking_instructions = doc.search("div.directions li")
  cooking_instructions.each do |instruction|
    puts ""
    puts instruction.text
  end
end

.todayObject



6
7
8
# File 'lib/daily_recipe/Recipe.rb', line 6

def self.today
  self.scrape_food_network
end