HTTParty选项参数无法正常运行

Bik*_*ire 8 ruby httparty

我正在设置一个可以生成LastFM API请求的应用程序.这些是简单的get请求,我正在使用HTTParty gem.

我的功能如下:

def get_albums
  self.class.base_uri "http://ws.audioscrobbler.com/2.0/"
  options = {
    :user => "Gerard1992",
    :method => "user.gettopalbums", 
    :api_key => Constants::LASTFM_API_KEY, 
    :format => "json"
  }
  puts options.to_query
  self.class.get "/?#{options.to_query}", {} #options don't work
end
Run Code Online (Sandbox Code Playgroud)

上面显示的这段代码有效.get请求返回一组JSON.我的问题是,这/?#{options.to_query}看起来并不整洁.实际(现在为空{})选项参数也不是.如何让HTTParty选项参数像它应该的那样工作?

这是我尝试过的,但两种情况都失败了:

self.class.get "/", options
self.class.get "/", options => options
Run Code Online (Sandbox Code Playgroud)

我很感激帮助.

And*_*all 22

HTTParty中查询参数的正确选项是:query,所以你想要的是:

self.class.get "/", query: options
Run Code Online (Sandbox Code Playgroud)

您可以在文档中查看所有可用参数.