我使用HTTParty与Github API进行交互。 Github API响应是分页的。分页包含在"链接" HTTP响应的标头。 See here.
我无法弄清楚如何访问HTTParty对象的链接头信息,以及如何提取分页信息。
我想了解如何在不需要额外宝石的情况下完成此操作。
到目前为止我的代码:
def ghapi path, query
query.merge!({
"per_page" => 100
})
return HTTParty.get("https://api.github.com/#{path}", query: query, headers: {
"Authorization" => "token #{session[:token]}",
"User-Agent" => "WDIDC"
})
end
ghapi.headers
显然是如何访问标头信息的。但是,这不包括相关信息。以下是其中包含的信息,其中包含敏感信息:
{
"server": [
"GitHub.com"
],
"date": [
"Sun, 05 Jul 2015 18:52:04 GMT"
],
"content-type": [
"application/json; charset=utf-8"
],
"content-length": [
"2"
],
"connection": [
"close"
],
"status": [
"200 OK"
],
"x-ratelimit-limit": [
"5000"
],
"x-ratelimit-remaining": [
"4870"
],
"x-ratelimit-reset": [
"1436125019"
],
"cache-control": [
"private, max-age=60, s-maxage=60"
],
"x-oauth-scopes": [
"gist, repo, user"
],
"x-accepted-oauth-scopes": [
""
],
"vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding"
],
"x-github-media-type": [
"github.v3; format=json"
],
"x-xss-protection": [
"1; mode=block"
],
"x-frame-options": [
"deny"
],
"content-security-policy": [
"default-src 'none'"
],
"access-control-allow-credentials": [
"true"
],
"access-control-expose-headers": [
"ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"
],
"access-control-allow-origin": [
"*"
],
"strict-transport-security": [
"max-age=31536000; includeSubdomains; preload"
],
"x-content-type-options": [
"nosniff"
],
}
我可以看到Link
中包含access-control-expose-headers
,但这并不包含任何实际信息......