BigW Consortium Gitlab

client.rb 634 Bytes
Newer Older
1 2
module Github
  class Client
3
    attr_reader :connection, :rate_limit
4

5 6
    def initialize(options)
      @connection = Faraday.new(url: options.fetch(:url)) do |faraday|
7 8
        faraday.options.open_timeout = options.fetch(:timeout, 60)
        faraday.options.timeout = options.fetch(:timeout, 60)
9
        faraday.authorization 'token', options.fetch(:token)
10
        faraday.adapter :net_http
11
      end
12 13

      @rate_limit = RateLimit.new(connection)
14 15 16
    end

    def get(url, query = {})
17 18
      exceed, reset_in = rate_limit.get
      sleep reset_in if exceed
19

20
      Github::Response.new(connection.get(url, query))
21 22 23
    end
  end
end