codeclimate/gh

Name: gh

Owner: Code Climate

Description: Layered GitHub API client

Created: 2015-02-24 16:24:35.0

Updated: 2015-05-21 20:19:37.0

Pushed: 2015-02-25 00:19:08.0

Homepage: http://about.travis-ci.org/gh/

Size: 448

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

GH - Layered GitHub API client

Build Status

This is a highly flexible, layered, low-level GitHub client library, trying to get out of your way and let you get to the GitHub data as simple as possible. Unless you add layers, you will end up with Hashes and Arrays. The approach and API should be familiar from projects like Rack or Faraday.

Simple example:

ire 'gh'
 GH['users/rkh']['name']

This will by default use all the middleware that ships with GH, in the following order:

The following middleware is not included by default:

Main Entry Points

Every layer has two main entry points:

These two methods are exposed by any instance of a layer and the GH constant.

Using a Single Layer

You can initialize and use any layer on its own:

 GH::Remote.new
 gh['users/rkh']['name']

Layers know which other layer they should usually wrap (Remote wraps no other layer, LazyLoader and LinkFollower wrap Normalizer by default, anything else wraps Remote), so you can initialize them right away:

 GH::LazyLoader.new

You can also pass the layer that should be wrapped as an argument:

 GH::LazyLoader.new(GH::LinkFollower.new)
Creating Your Own Stack

For convinience a stack DSL is provided:

me as GH::Normalizer.new(GH::Cache.new)
 GH::Stack.build do
e GH::Normalizer
e GH::Cache


 gh['users/rkh']['name']

You can also create reusable Stack instances:

k = GH::Stack.new do
e GH::Normalizer
e GH::Cache


 stack.build username: 'rkh', password: 'abc123'
 gh['user']['name']

One such instance (with the standard setup) can be accessed as GH::DefaultStack

Scoping

With the main goal to separate authentication from other logic, the gh library supports scopting:

ith GH::LazyLoader.new do
ts GH['users/rkh']['name']

That way, you could create a stack with, for instance, an access token:

enticated = GH::DefaultStack.build token: 'e72e16c7e42f292c6912e7710c838347ae178b4a'

ith(authenticated) do
...

Since this is rather common, you can pass options directly to with:

ith(username: 'rkh', password: 'abc123') do
...

Scoping is thread-safe.

Is this production ready?

I hope so, we use it in production for Travis CI. The work on this library has been funded by the Travis Love Campaign.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.