Refactoring Github response

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