繁体   English   中英

如何使用Ruby HTTParty搜索多个单词的查询?

[英]How to search for a query with more than one word using Ruby HTTParty?

因此,我有此代码在该网站的http://www.recipepuppy.com/api中寻找关键字的地方。 def self.for(keyword)函数在此网站中查找关键字。 下面的chocolate示例有效,但是,如果我有2个或更多的单词,搜索结果将显示为空白。 我想知道如何弥补这一点。 任何帮助,将不胜感激!

require 'httparty'

class Recipe

  include HTTParty

  base_uri 'recipepuppy.com'
  default_params output: "json"
  format :json

  def self.for(keyword)
    get("/api", query: {q: keyword})
  end

end

puts Recipe.for("chocolate")
puts
puts Recipe.for("apple pie")

结果:

{"title"=>"Tim and Tracy's Chocolate Cake (Boiled)", "href"=>"http://www.recipezaar.com/Tim-and-Tracys-Chocolate-Cake-Boiled-259680", "ingredients"=>"baking soda, butter, cocoa powder, eggs, flour, sugar, water", "thumbnail"=>"http://img.recipepuppy.com/34464.jpg"}
{"title"=>"Chocolate Tea", "href"=>"http://www.recipezaar.com/Chocolate-Tea-205348", "ingredients"=>"milk, sugar, tea bag, water", "thumbnail"=>""}
{"title"=>"Chocolate-toffee Cream Pie", "href"=>"http://www.recipezaar.com/Chocolate-toffee-Cream-Pie-82097", "ingredients"=>"pie crust, toffee baking bits, cool whip, cream cheese, brown sugar, candy bars, vanilla extract, heavy cream", "thumbnail"=>""}
{"title"=>"Chocolate Chocolate Chocolate Butterscotch Chip Cookies Recipe", "href"=>"http://www.grouprecipes.com/50195/chocolate-chocolate-chocolate-butterscotch-chip-cookies.html", "ingredients"=>"cocoa powder, baking soda, brown sugar, butterscotch chips, eggs, flour, milk chocolate, salt, semisweet chocolate chips, sugar, vanilla extract", "thumbnail"=>"http://img.recipepuppy.com/231970.jpg"}
{"title"=>"Chocolate Cake With Fruits Recipe", "href"=>"http://www.grouprecipes.com/43318/chocolate-cake-with-fruits.html", "ingredients"=>"baking powder, baking soda, chocolate cake, eggs, frosting, vanilla extract, vanilla extract, salt, salt", "thumbnail"=>"http://img.recipepuppy.com/304911.jpg"}
{"title"=>"Chocolate Chip Cookies", "href"=>"http://www.recipezaar.com/Chocolate-Chip-Cookies-146432", "ingredients"=>"flour, baking soda, chocolate, eggs, brown sugar, corn syrup, nuts, salt, semisweet chocolate, butter, vanilla bean, sugar", "thumbnail"=>"http://img.recipepuppy.com/306284.jpg"}
{"title"=>"Chocolate Macadamia Cookies With White Chocolate Chunks", "href"=>"http://www.recipezaar.com/Chocolate-Macadamia-Cookies-With-White-Chocolate-Chunks-271061", "ingredients"=>"flour, almond extract, baking soda, brown sugar, butter, shortening, eggs, salt, sugar, macadamia nuts, cocoa powder, white chocolate", "thumbnail"=>""}
{"title"=>"Chocolate-Dipped Brownie Bites (Brownies)", "href"=>"http://www.recipezaar.com/Chocolate-Dipped-Brownie-Bites-Brownies-264833", "ingredients"=>"flour, baking soda, butter, eggs, chocolate, salt, semisweet chocolate chips, shortening, sugar, vanilla extract, water", "thumbnail"=>"http://img.recipepuppy.com/311066.jpg"}
{"title"=>"Darn Good Chocolate Cake ( Cake Mix Cake)", "href"=>"http://www.recipezaar.com/Darn-Good-Chocolate-Cake-Cake-Mix-Cake-87205", "ingredients"=>"frosting, cake mix, eggs, chocolate pudding, sour cream, vegetable oil, water", "thumbnail"=>"http://img.recipepuppy.com/42112.jpg"}
{"title"=>"Angelina?s Hot Chocolate", "href"=>"http://www.recipezaar.com/Angelinas-Hot-Chocolate-334398", "ingredients"=>"chocolate, water, milk, sugar, water, whipped cream", "thumbnail"=>"http://img.recipepuppy.com/62411.jpg"}

# Apple Pie function; This part is blank #

更改

base_uri 'recipepuppy.com'

base_uri 'www.recipepuppy.com'

他们的API搞砸了,并且以某种方式对其进行了修复...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM