2017-04-12 01:33:54 +00:00
|
|
|
module Github
|
|
|
|
class Client
|
2017-04-24 22:49:17 +00:00
|
|
|
attr_reader :connection, :rate_limit
|
2017-04-12 01:33:54 +00:00
|
|
|
|
2017-04-19 23:04:58 +00:00
|
|
|
def initialize(options)
|
|
|
|
@connection = Faraday.new(url: options.fetch(:url)) do |faraday|
|
2017-04-25 00:21:58 +00:00
|
|
|
faraday.options.open_timeout = options.fetch(:timeout, 60)
|
|
|
|
faraday.options.timeout = options.fetch(:timeout, 60)
|
2017-04-19 23:04:58 +00:00
|
|
|
faraday.authorization 'token', options.fetch(:token)
|
2017-04-13 01:44:55 +00:00
|
|
|
faraday.adapter :net_http
|
2017-04-12 01:33:54 +00:00
|
|
|
end
|
2017-04-24 22:49:17 +00:00
|
|
|
|
|
|
|
@rate_limit = RateLimit.new(connection)
|
2017-04-12 01:33:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(url, query = {})
|
2017-04-24 22:49:17 +00:00
|
|
|
exceed, reset_in = rate_limit.get
|
|
|
|
sleep reset_in if exceed
|
2017-04-12 01:33:54 +00:00
|
|
|
|
2017-04-13 16:59:26 +00:00
|
|
|
Github::Response.new(connection.get(url, query))
|
2017-04-12 01:33:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|