From 00912ed963a3495d59d8632d8d195515e9686129 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 13 Apr 2017 13:59:26 -0300 Subject: [PATCH] Refactoring Github response --- lib/github/client.rb | 5 ++--- lib/github/response.rb | 14 +++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/github/client.rb b/lib/github/client.rb index 07cf264e8d7..1c24daba1ef 100644 --- a/lib/github/client.rb +++ b/lib/github/client.rb @@ -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 diff --git a/lib/github/response.rb b/lib/github/response.rb index 2fa852c9fdc..2fd07dd822e 100644 --- a/lib/github/response.rb +++ b/lib/github/response.rb @@ -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