Search code examples
rubygithub-apirest-client

Ruby rest client gem and Github API


To query the Github API with 'rest_client' I do the following, if I want to search for users in London:

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

Direct browser query:

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

How would I construct the query if for example, I wanted to match users that joined at or after May 11th, 2013?

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

If I were to directly input this query using a browser I would do

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


Solution

  • Assuming this is your search query for the browser

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

    You can ask rest client to do the same like that:

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

    Checking the equality of results can be a tricky task. One way here is to compare total_count of objects using json parser:

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