Giter Site home page Giter Site logo

gh's Introduction

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:

require 'gh'
puts GH['users/rkh']['name']

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

  • GH::Remote - sends HTTP requests to GitHub and parses the response
  • GH::Normalizer - renames fields consistenly, adds hypermedia links if possible
  • GH::LazyLoader - will load missing fields when accessed (handy for dealing with incomplete data without sending to many requests)
  • GH::MergeCommit - adds infos about merge commits to pull request payloads
  • GH::LinkFollower - will add content of hypermedia links as fields (lazyly), allows you to traverse relations
  • GH::Pagination - adds support for transparent pagination
  • GH::Instrumentation - let's you instrument gh

The following middleware is not included by default:

  • GH::Cache - caches the responses (will use Rails cache if in Rails, in-memory cache otherwise)

Main Entry Points

Every layer has two main entry points:

  • [key] - loads data from GitHub
  • load(data) - takes data and applies modifications (handy for dealing with service hook payloads)

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 = GH::Remote.new
puts 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 = GH::LazyLoader.new

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

gh = GH::LazyLoader.new(GH::LinkFollower.new)

Creating Your Own Stack

For convinience a stack DSL is provided:

# Same as GH::Normalizer.new(GH::Cache.new)
gh = GH::Stack.build do
  use GH::Normalizer
  use GH::Cache
end

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

You can also create reusable Stack instances:

stack = GH::Stack.new do
  use GH::Normalizer
  use GH::Cache
end

gh = stack.build username: 'rkh', password: 'abc123'
puts 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 scoping:

GH.with GH::LazyLoader.new do
  puts GH['users/rkh']['name']
end

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

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

GH.with(authenticated) do
  # ...
end

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

GH.with(username: 'rkh', password: 'abc123') do
  # ...
end

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.

gh's People

Contributors

aaron1011 avatar arr-ee avatar banzaiman avatar calavera avatar drblinken avatar gbarc avatar grosser avatar igorwwwwwwwwwwwwwwwwwwww avatar ioquatix avatar jfahrer avatar joecorcoran avatar joshcheek avatar joshk avatar marshally avatar meatballhat avatar murtaza-swati avatar p avatar pavel-d avatar rkh avatar roidrage avatar sarahhodne avatar vitalied avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gh's Issues

Not seeing versions > 0.18.0 published to rubygems

Due to the issue mentioned in the title, installing and using the travis gem on my local results in a Faraday incompatibility, where the new (and required) travis version needs 2.7 but gh 0.18.0 specifies 1.x.

New mergeable_state for pull requests

It seems that pull requests recently got a new mergeable_state which is unknown to GH:

unknown mergeable_state "unstable" for https://api.github.com/repos/.../.../pulls/1

Please release the gem

Hey there. I'm wondering if you could please cut a new release of the gem. I'd really like to get the looser addressable dependency out there. It would allow us to bring the 2.5.2 release into our environment which has some nice fixes.

Thanks,
Tim

License is not specified

Hi,

There is no license specified, either in the repository or in the gem metadata. Please include this licensing information.

Thanks!

Robert

ActiveSupport dependency

Currently released versions of gh (0.16 and 0.17) depend on ActiveSupport 5. This makes gh incompatible with any application that uses AS 6.

In my case, my application uses travis which depends on gh. Although I do not directly use gh I must either use an old version of travis that uses pre-0.16 gh which does not depend on AS at all, or I cannot use AS 6 in my application.

The old versions of travis/gh use pre-1.0 faraday dependency, thus if I want to have AS 6 and faraday 1.0 in my application I am unable to figure out how to use travis at all.

update faraday to ~> 2.0 and remove faraday_middleware

We'd like to update faraday in debian to 2.0+ and gh has a stricter requirement for faraday. Please update faraday to ~> 2.0 and while at it, faraday_middleare is deprecated so will need to be replaced with specific middle ware gems instead of a single gem.

Relax constraints on faraday and faraday_middleware

Hi,

With faraday 1.1.0 and faraday_middleware 1.0.0, gh fails to build/work, only because of the ~> constraints. If it could be >= instead, that'd work great!


Here's a patch:

Author: Utkarsh Gupta <[email protected]>
Bug-Debian: https://bugs.debian.org/976163
Last-Update: 2020-11-30

--- a/gh.gemspec
+++ b/gh.gemspec
@@ -19,8 +19,8 @@
   s.add_development_dependency 'rspec'
   s.add_development_dependency 'webmock'
 
-  s.add_runtime_dependency 'faraday',     '~> 0.8'
-  s.add_runtime_dependency 'faraday_middleware', '~> 0.12.2'
+  s.add_runtime_dependency 'faraday',     '>= 0.8'
+  s.add_runtime_dependency 'faraday_middleware', '>= 0.12.2'
   s.add_runtime_dependency 'activesupport', '>= 5.0', '< 6.1'
   s.add_runtime_dependency 'multi_json',  '~> 1.0'
   s.add_runtime_dependency 'addressable', '~> 2.4'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.