1

我有以下功能,可以通过Rotten Tomatoes API按标题搜索电影,这可能会不小心拼写为非基本英语。我使用HTTParty gem来包装 API。

def self.search_by_title(title)
    options = {query: {apikey: "secret", page_limit: "1" }}
    response = self.get("http://api.rottentomatoes.com/api/public/v1.0/movies.json?q=#{CGI.escape(title)}", options)

    movie = JSON.parse(response.body)
end

因此,如果我提出以下请求(搜索“Rashômon”电影):

http://api.rottentomatoes.com/api/public/v1.0/movies.json?q=#{CGI.escape(Rashômon)}&apikey=apikey

它返回空哈希

{"total"=>0, "movies"=>[], "links"=>{"self"=>"http://api.rottentomatoes.com/api/public/v1.0/movies.json?q=Rash%C3%83%C2%B4mon&page_limit=1&page=1"}

如果我只使用“罗生门”就可以了。但我通过 3d 派对 API 获得这些标题,有时它会提供这种格式的标题。

我知道我可能应该通过其他标识(imdb_id、英文名称等)进行搜索,但有时我无法提供这些变量并使用 search_by_title 作为后备函数。

有没有办法绕过它?

4

0 回答 0