我在我的rails应用程序中使用github_api
gem,当我向location或repos发送请求时,它提供了完美的输出,但是当我发送两者的组合时(位置和repos)api给出空结果。我把我的逻辑放在下面,
LOGIC:
github = Github.new github.search.users keyword:"location:bangalore repos:1", type:'user',ref:'searchresults'
生成的请求网址
https://api.github.com/legacy/user/search/location%3Abangalore+repos%3A1?type=user&ref=searchresults
感谢。
答案 0 :(得分:0)
我通过以下网址获得结果:https://api.github.com/legacy/user/search/location:bangalore%20repos:1
我怀疑github_api没有预料到这些类型的关键字,也没有正确编码URL的那个片段。我建议你试试octokit
这是用Ruby编写的官方GitHub API包装器。我怀疑会有这个问题。
对于它的价值,如果你需要一个python包装器,我的github3.py
在这种情况下工作正常。 (这就是我从上面获得生成的URL的地方)
答案 1 :(得分:0)
我在url.rb文件中调试库,在关键字中应用CGI :: escape,因此生成请求网址就像
https://api.github.com/legacy/user/search/location%3Abangalore+repos%3A1?type=user&ref=searchresults
但此URL提供空结果,因为“+”符号不是编码。所以我现在覆盖该代码,它生成请求URL为
覆盖代码是,
require "github_api"
include ERB::Util
module Github
module Utils
module Url
def escape(s)
u s.to_s
end
end
end
end