summaryrefslogtreecommitdiff
path: root/lib/github/client.rb
diff options
context:
space:
mode:
authorRuben Davila <rdavila84@gmail.com>2017-05-02 13:20:41 -0500
committerRuben Davila <rdavila84@gmail.com>2017-05-02 13:20:41 -0500
commitbbfbcebdf69261bac6aa142f430719955e8e86b9 (patch)
tree25916a1a761cb6c8fcdac4b20b76017a7f4506d3 /lib/github/client.rb
parent3b82444eb7791e58e3e0ba2f08b8ccde48e3d4c6 (diff)
parent920d55b9f8afd35e16351fb57d671acf66092e89 (diff)
downloadgitlab-ce-bbfbcebdf69261bac6aa142f430719955e8e86b9.tar.gz
Merge branch 'master' into 28433-internationalise-cycle-analytics-page
Diffstat (limited to 'lib/github/client.rb')
-rw-r--r--lib/github/client.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/github/client.rb b/lib/github/client.rb
new file mode 100644
index 00000000000..e65d908d232
--- /dev/null
+++ b/lib/github/client.rb
@@ -0,0 +1,23 @@
+module Github
+ class Client
+ attr_reader :connection, :rate_limit
+
+ def initialize(options)
+ @connection = Faraday.new(url: options.fetch(:url)) do |faraday|
+ faraday.options.open_timeout = options.fetch(:timeout, 60)
+ faraday.options.timeout = options.fetch(:timeout, 60)
+ faraday.authorization 'token', options.fetch(:token)
+ faraday.adapter :net_http
+ end
+
+ @rate_limit = RateLimit.new(connection)
+ end
+
+ def get(url, query = {})
+ exceed, reset_in = rate_limit.get
+ sleep reset_in if exceed
+
+ Github::Response.new(connection.get(url, query))
+ end
+ end
+end