BigW Consortium Gitlab

Refactoring client to not parse response body automatically

parent 8538066e
......@@ -4,10 +4,8 @@ module Github
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
faraday.adapter :net_http
end
end
......@@ -15,7 +13,8 @@ module Github
rate_limit = RateLimit.new(connection)
sleep rate_limit.reset_in if rate_limit.exceed?
Github::Response.new(connection.get(url, query))
response = connection.get(url, query)
Github::Response.new(response.headers, response.body, response.status)
end
end
end
......@@ -16,11 +16,11 @@ module Github
end
def remaining
@remaining ||= response.body.dig('rate', 'remaining').to_i
@remaining ||= body.dig('rate', 'remaining').to_i
end
def reset_in
@reset ||= response.body.dig('rate', 'reset').to_i
@reset ||= body.dig('rate', 'reset').to_i
end
private
......@@ -30,7 +30,11 @@ module Github
end
def response
@response ||= connection.get(rate_limit_url)
connection.get(rate_limit_url)
end
def body
@body ||= Oj.load(response.body, class_cache: false, mode: :compat)
end
# GitHub Rate Limit API returns 404 when the rate limit is disabled
......
module Github
class Response
attr_reader :raw, :headers, :body, :status
attr_reader :headers, :body, :status
def initialize(response)
@raw = response
@headers = response.headers
@body = response.body
@status = response.status
def initialize(headers, body, status)
@headers = headers
@body = Oj.load(body, class_cache: false, mode: :compat)
@status = status
end
def rels
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment