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