Intridea Company Blog
Ruby-GitHub: Simple Access to the GitHub API
While the GitHub folks have produced their own github-gem that provides some useful command-line tools for GitHub users, the library they have written isn’t your traditional API wrapper since it’s focused around using GitHub rather than getting information from GitHub.
I’ve thrown together a small library called ruby-github that provides that kind of functionality. It’s extremely simple and works with all of the currently available API but that only comes down to three read-only calls at this point. Use like so:
user = GitHub::API.user('mbleigh')
user.name # => "Michael Bleigh"
user.repositories # => array of repositories
user.repositories.last.name # => "ruby-github"
user.repositories.last.url # => "http://github.com/mbleigh/ruby-github"
user.repositories.last.commits # => array of commits (see below)
commits = GitHub::API.commits('mbleigh','ruby-github')
commits.first.message # => "Moved github.rb to ruby-github.rb..."
commits.first.id # => "1d8c21062e11bb1ecd51ab840aa13d906993f3f7"
commit = GitHub::API.commit('mbleigh','ruby-github','1d8c21062e11bb1ecd51ab840aa13d906993f3f7')
commit.message # => "Moved github.rb to ruby-github.rb..."
commit.added.collect{|c| c.filename} # => ["init.rb", "lib/ruby-github.rb"]
Installation
The easiest way to install ruby-github is as a gem:
gem install ruby-github
You can also install it as a Rails plugin if that’s your thing:
<code>git clone git://github.com/mbleigh/ruby-github.git vendor/plugins/ruby-github</pre> **Update 4/12/2008:** Version 0.0.2 of the gem has been released and I have revised this post to adhere to the new gem's requirements.
The Intridea Blogs
Blog Archive
- June 2009 (7)
- May 2009 (4)
- April 2009 (6)
- March 2009 (15)
- February 2009 (18)
- January 2009 (4)
- December 2008 (2)
- November 2008 (3)
- October 2008 (7)
- September 2008 (9)
- August 2008 (2)
- July 2008 (7)
- June 2008 (14)
- May 2008 (5)
- April 2008 (14)
- March 2008 (6)
- February 2008 (5)
- January 2008 (6)
- December 2007 (5)
- November 2007 (5)
- October 2007 (7)
- September 2007 (2)
- August 2007 (7)
- July 2007 (4)
- June 2007 (3)
- April 2007 (1)
Michael Bleigh