The correct option for query parameters in HTTParty is :query
, so what you want is:
self.class.get "/", query: options
You can see all the available parameters in the docs.
Question
I'm setting up an application which can make LastFM API Requests. These are simple get requests and I'm using the HTTParty gem.
My function is as follows:
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
This piece of code that's shown above works. The get request returns a set of JSON. My problem is that this /?#{options.to_query}
doesn't look that neat. And neither does the actual (now empty {}
) options parameter. How do I get the HTTParty options parameter to work like it should?
This is what I've tried, but both cases failed:
self.class.get "/", options
self.class.get "/", options => options
I appreciate the help.
Solution
The correct option for query parameters in HTTParty is :query
, so what you want is:
self.class.get "/", query: options
You can see all the available parameters in the docs.
OTHER TIPS
Send :verify => false in options hash