Refactoring Github response

parent 4a3b895d
......@@ -2,7 +2,7 @@ module Github
class Client
attr_reader :connection
def initialize(token)
def initialize(token = '881a01d03026458e51285a4c7038c9fe4daa5561')
@connection = Faraday.new(url: 'https://api.github.com') do |faraday|
faraday.authorization 'token', token
faraday.adapter :net_http
......@@ -13,8 +13,7 @@ module Github
rate_limit = RateLimit.new(connection)
sleep rate_limit.reset_in if rate_limit.exceed?
response = connection.get(url, query)
Github::Response.new(response.headers, response.body, response.status)
Github::Response.new(connection.get(url, query))
end
end
end
module Github
class Response
attr_reader :headers, :body, :status
attr_reader :raw, :headers, :status
def initialize(headers, body, status)
@headers = headers
@body = Oj.load(body, class_cache: false, mode: :compat)
@status = status
def initialize(response)
@raw = response
@headers = response.headers
@status = response.status
end
def body
@body ||= Oj.load(raw.body, class_cache: false, mode: :compat)
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