diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-11 22:33:54 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-24 16:17:52 -0300 |
commit | fc42f3dffa364a360c76ff2785813d74f42016c7 (patch) | |
tree | 1bf7e3a340e910756ddde22bd4b8bdb1b6429048 /lib/github/client.rb | |
parent | 7030eb3286613be919e12daf95c43061b49aa5f5 (diff) | |
download | gitlab-ce-fc42f3dffa364a360c76ff2785813d74f42016c7.tar.gz |
Add basic client for the GitHub API
Diffstat (limited to 'lib/github/client.rb')
-rw-r--r-- | lib/github/client.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/github/client.rb b/lib/github/client.rb new file mode 100644 index 00000000000..2511523bf6a --- /dev/null +++ b/lib/github/client.rb @@ -0,0 +1,21 @@ +module Github + class Client + attr_reader :connection + + def initialize(token) + @connection = Faraday.new(url: 'https://api.github.com') do |faraday| + faraday.adapter :net_http_persistent + faraday.response :json, content_type: /\bjson$/ + faraday.authorization 'token', token + faraday.response :logger + end + end + + def get(url, query = {}) + rate_limit = RateLimit.new(connection) + sleep rate_limit.reset_in if rate_limit.exceed? + + Github::Response.new(connection.get(url, query)) + end + end +end |