Refactoring Github response
This commit is contained in:
parent
4a3b895d91
commit
00912ed963
|
@ -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
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue