Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Ruby wrapper for GitHub's v3 API
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


githu3 is a ruby wrapper for github's v3 api.


gem install githu3



There are two ways to authenticate

Basic Authentication:

client ='username', 'password')

OAuth2 Token (send in a header):

client ='myawesomelyverylongoauth2token')

Or you can use the lib as an un-authenticated client to access only public Github resources...

client =

Getting the basics

The Githu3::Client instance can directly access github's top-level resources : orgs, repos, teams and users

to get them :

c =

# Org
rails_org = 'rails' # -> 'rails' organization wrapped in a Gihu3::Org object

# Repo
rails_repo = c.repo 'rails/rails' # -> That's Rails !

# User
sbellity = c.user 'sbellity' # -> That's me !

# Team
a_team = 123 # -> well... team number '123' if you have access to it

Getting your stuff

When authenticated, your Githu3::Client instance can give you direct access to your top-level stuff...

me = 'myawesomelyverylongoauth2token'

# Orgs
# returns a paginable Githu3::ResourceCollection stuffed with YOUR organizations
# more on this Githu3::ResourceCollection thing later...
my_orgs = me.orgs

# Repos
my_repos = me.repos

# Me
me =                # -> well, you get the point...

# Followers
me.following              # -> returns a list a the Githu3::User, that you follow
me.followers              # -> returns a list a the Githu3::User, that follow you
me.following?("rails")    # -> true if you follow 'rails', false otherwise

Getting deeper inside the API with Githu3::Resource Objects

All the calls to the API either return Githu3::Resource objects (ex. Githu3::User, Githu3::Repo, Githu3::Org...) et Githu3::ResourceCollection objects that wrap... Githu3::Resource objects


All the member attributes are accessible directly via their names. If you try to access an attribute that does not exist... you'll get nil


c =

rails_org = 'rails'
rails_org.login           # -> 'rails'
rails_org.html_url        # -> ''
rails_org.public_repos    # -> 44             # -> nil


Relations between the Resources follow the nesting of the Github's REST Api. For example, you can get the list of an org's repos directly from the Githu3::Org object.

c =
rails_org = "rails"
rails_org.repos # -> the list of rails' repos

You can even do this !

rails_org.repos.first.issues # -> latest issues from rails' first repo


Github often embeds objects inside others. For example, rails Repo has an owner object, that is a Githu3::User object... which let you do this:

rails_repo = c.repo "rails/rails"
rails_repo.owner  # -> rails org wrapped in a Githu3::User object

Getting lots of stuff with Githu3::ResourceCollection Objects

Acts as Enumerable

Most results from the Api calls are collections of stuff. Those collections are wrapped in Githu3::ResourceCollection objects that primarily act as Arrays. Meaning that you can safely call the usual length, first, last, each, map, select... an so on... on them.


Warning !... this Pagination api is very alpha-ish... and very susceptible to change

In fact, Github's api generally returns paginated results. Github::ResourceCollection have a pagination api built right in, that lets you do those kinds of stuff :

rails_repo = c.repo "rails/rails"
rails_issues = rails_repo.issues(:per_page => 10, :page => 4) # -> :per_page defaults to 30, :page defaults to 1

rails_issues.current_page               # -> 4
rails_issues.length                     # -> 10

next_issues = rails_issues.fetch_next   # -> next_issues is a plain Array here... 
                                        # new records are added to your original collection
rails_issues.current_page               # -> 5
rails_issues.length                     # -> 20

Filtering & Sorting

Github Api provides filter options for most collection calls. To use a filter on your Githu3::ResourceCollection object, you can do

repo  = c.repo "sbellity/githu3"
open_issues = repo.issues :state => "open"
bugs        = repo.issues :tag => "bug"
my_issues   = repo.issues :assignee => "sbellity"

# You can also combine and sort them
my_open_bugs = repo.issues  :assignee => "sbellity", 
                            :tag => "bug", 
                            :state => "open", 
                            :sort => "updated", 
                            :direction => "desc"

Rate limiting

Your app may generate a LOT of requests to Github's API... By default, you are rate-limitted to 5000 requests per day. You can check anytime the status of your allowance via the method "rate_limit" on your Githu3::Client instance.

c =
c.rate_limit  # -> {:limit=>"5000", :remaining=>"4969"}

Caching results

Githu3 provides a very basic cache mechanism to avoid making duplicate requests too often. Basically what it does is just record HTTP request results in a store with an expiration timeout and attempts to retrieve the results back from this store before hitting Github's servers. The different clients private data... should be safe, the request headers (that contain auth info) are used to generate the hash. 2 stores are provided by default : Redis and Disk.

To use them (these are the default options):

disk_cached_client ='myawesomelyverylongoauth2token', :cache => :disk, :cache_config => {
  :path       => "/tmp/githu3", 
  :namespace  => "cache",       # or "myawesomelyverylongoauth2token" if you are paranoid...
  :expire     => 120            # in seconds

require 'redis'
require 'redis-namespace'
redis_cached_client ='myawesomelyverylongoauth2token', :cache => :redis, :cache_config => {
  :host       => "localhost",     # defaults to localhost
  :port       => 6379             # defaults to 6379
  :namespace  => "githu3",        # or "githu3:myawesomelyverylongoauth2token" if you are paranoid...
  :expire     => 120              # in seconds

Limitations / Known issues

  • The current version (0.1.x branch) only supports read (GET) operations on Github... support for CREATE / UPDATE operations should show up in the the 0.2.x branch.
  • Github's api is still in beta, so this lib could break anytime if they change something, stay tuned for new versions and please report any issue on the project issue tracker.
  • Some calls (ex. c.repo('rails/rails').issues -> 2 HTTP GET) make unnecessary calls to github, we will try to find a way to avoid this overhead in a future version.
  • This lib is VERY young, please be kind and help me improve it

Contributing to githu3

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright (c) 2011 Stephane Bellity. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.