Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib fix and test valid tokens
.travis.yml Initial commit
Gemfile Initial commit Update badge to svg format
Rakefile Initial commit
git_hub_bub.gemspec fix and test valid tokens


Build Status

A low level GitHub client that makes the disgusting issue of header based url pagination simple.


Seriously? I just told you, see above.


I'm using this in a few places such as Need low level control, without sacrificing usability.


In your Gemfile

gem 'git_hub_bub'

Then run $ bundle install

GET Whatever you Want:

To make requests to a GET endpoint use GitHubBub.get

response = GitHubBub.get('repos/rails/rails/issues')

Now you can do stuff like grab the json-ified body:

response.json_body # => { foo: "bar" ...}

And get pagination (if there is any):

response.next_url   # => ""
response.last_url?  # => false
response.pagination # => {"next_url"=>"", "last_url"=>""}

Passing Params

To pass parameters such as page number, or sorting or whatever, input a hash as the second argument.

GitHubBub.get('repositories/8514/issues', page: 1, sort: 'comments', direction:'desc')

Passing Anything Else

Anything else you pass in the third argument will be given to Excon which powers GitHubBub. So if you want to set headers you can do it like this:

GitHubBub.get('repositories/8514/issues', {page: 1}, {headers: { "Content-Type" => "application/x-www-form-urlencoded" }})


GitHubBub.get('repositories/8514/issues', {}, {headers: { "Content-Type" => "application/x-www-form-urlencoded" }})

See Excon for documentation on more available options.

Default Headers

Default headers are set in GitHubBub::Request

BASE_HEADERS   = {'Accept' => "application/#{GITHUB_VERSION}", "User-Agent" => USER_AGENT}

You can change GitHubBub::Request::GITHUB_VERSION and GitHubBub::Request::USER_AGENT.

If you want any other default headers you can set them in EXTRA_HEADERS like so:

GitHubBub::Request::EXTRA_HEADERS = { "Content-Type" => "application/x-www-form-urlencoded" }

Keep in mind this will change them for every request. If you need logic behind your default headers, consider adding a before_send_callback to conditionally modify headers

Authenticated Requests

Some GitHub endpoints require a user's authorization you can do that by passing in token:

GitHubBub.get('/user', token: 'a38ck38ckgoldfishtoken')

Or you can manually set a header like so:

GitHubBub.get('/user', {} {headers: {"Authorization" => "token a38ck38ckgoldfishtoken"}})

You will need to use one of these every time the GitHub api says "as an authenticated user".


If you want to mess with the url or options before sending a request you can set a callback globally

GitHubBub::Request.set_before_callback do |request|
  request.url     = ""
  request.options = {do: "anything you want to _all_ the requests" }


Check GitHub Developer Docs. When you see something like

GET /users/:user/repos

It means you need to use the GitHubBub.get method and pass in a string like '/users/schneems/repos' the full request might look like this:


Other HTTP Methods

Supports everything GitHub currently supports :

HEAD   # => GitHubBub.head
GET    # => GitHubBub.get
POST   # =>
PATCH  # => GitHubBub.patch
PUT    # => GitHubBub.put
DELETE # => GitHubBub.delete


You can use callbacks and there are some constants you can set, look in GitHubBub::Request. You will definetly want to set GitHubBub::Request::USER_AGENT It needs to be unique to your app: (

GitHubBub::Request::USER_AGENT = 'a-unique-and-permanent-agent-to-my-app'


This gem is tested using the super cool request recording/stubbing framework VCR. This does mean at one point and time all tests ran successfully against GitHub's servers. This also means if you want to write any tests any that are not already recorded will need to hit GitHub servers. So make sure the tests you write don't do anything really bad.

You'll also need a valid .env file

$ cp .sample.env .env

Anything you put in this file will be sourced into your environment for tests. Here is an example .env file.

USER_NAME="Richard Schneeman"

You will need to change most of these values


Your github API key, you can get one from


Your public github username


A repo that you have commit access too.

USER_NAME="Richard Schneeman"

Your real name


The :owner of a repo you might watch or want to watch, needs to be combined with WATCH_REPO. This should be different from OWNER


A repo that the WATCH_OWNER owns. Should be different from REPO



Something went wrong with that request. Please try again.