summaryrefslogtreecommitdiff
path: root/lib/github/client.rb
blob: 95536cae57f6eff238622dcf0cfbe9aec7e50a0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Github
  class Client
    attr_reader :connection

    def initialize(options)
      @connection = Faraday.new(url: options.fetch(:url)) do |faraday|
        faraday.authorization 'token', options.fetch(:token)
        faraday.adapter :net_http
      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