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

    def initialize(token)
      @connection = Faraday.new(url: 'https://api.github.com') do |faraday|
        faraday.adapter :net_http_persistent
        faraday.response :json, content_type: /\bjson$/
        faraday.authorization 'token', token
        faraday.response :logger
      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