Ruby rest客户端gem和Github API

时间:2014-06-22 14:22:01

标签: ruby github-api rest-client

使用' rest_client'查询Github API如果我想在伦敦搜索用户,我会执行以下操作:

require 'rest_client'
response = RestClient.get 'https://api.github.com/search/users', {:params => {:q => 'location:london'}}

直接浏览器查询:

  

https://api.github.com/search/users?q=location:london

如果我想匹配2013年5月11日或之后加入的用户,我将如何构建查询?

参考:https://help.github.com/articles/searching-users#created

如果我要使用浏览器直接输入此查询,我会这样做

  

https://api.github.com/search/users?q=location:london%20created:2013-03-06

1 个答案:

答案 0 :(得分:0)

假设这是您对浏览器的搜索查询

  

https://api.github.com/search/users?q=location%3alondon+created:>2013-03-16

你可以要求rest client做同样的事情:

params = {:q => 'location:london created:>2013-03-16'}
result = RestClient.get('https://api.github.com/search/users', {:params => params})

检查结果是否相等可能是一项棘手的任务。这里的一种方法是使用json解析器比较total_count个对象:

require 'json'
JSON.parse(result)['total_count'] # => 4552, just as stated if opened in browser