Ruby Program未从httparty get请求返回结果

时间:2019-03-10 14:24:33

标签: ruby uri httparty

以下代码有问题。我没有收到任何错误,但是由于某种原因,每当我使用在字符串中带有空格的搜索关键字时,我的结果就会变空。我已经尝试过使用urleescape,但这也行不通。有人有见识吗?

require 'httparty'
require 'uri'

class Recipe
  include HTTParty

  base_uri 'recipepuppy.com'
  default_params onlyImages: "1"
  format :json

  #Uses request parameter to send to API
  def self.for(q)
    q = URI.escape(q)
    p q
    get("/api", query: {q: q})["results"]
  end

end

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

0 个答案:

没有答案