Back to Parent

def find_recipe api_url


  # Use HTTParty to 
  response = HTTParty.get (api_url),
  headers:{
  "X-Mashape-Key" => ENV["SPOONACULAR_API"],
  "Accept" => "application/json"
  }

  puts response.body
  response = JSON.parse( response.body.to_s )

  # return the title of the first result
  recipe = response["results"][0]["title"]
  recipe.to_s
end




def find_image api_url


  # Use HTTParty to
  response = HTTParty.get (api_url),
  headers:{
  "X-Mashape-Key" => ENV["SPOONACULAR_API"],
  "Accept" => "application/json"
  }

  puts response.body
  response = JSON.parse( response.body.to_s )

  # return the image of the first result
  recipe = response["results"][0]["image"]
  recipe.to_s
end



def find_URL api_url
  # Use HTTParty to
  response = HTTParty.get (api_url),
  headers:{
  "X-Mashape-Key" => ENV["SPOONACULAR_API"],
  "Accept" => "application/json"
  }

  puts response.body
  response = JSON.parse( response.body.to_s )

  # extract an ID number to be passed through another search function/
  id = response["results"][0]["id"]
  id.to_s



  response_step2 = HTTParty.get "https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/" + id.to_s + "/information?includeNutrition=false",
    headers:{
      "X-Mashape-Key" => ENV["SPOONACULAR_API"],
      "Accept" => "application/json"
    }

  puts response_step2.body
  response_step2 = JSON.parse( response_step2.body.to_s )

  # return the URL of the first result
  recipe_URL = response_step2["sourceUrl"]
  recipe_URL.to_s
end
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0