簡體   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