summaryrefslogtreecommitdiff
path: root/lib/github
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-12 22:44:55 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commit104144f373a58069680dd3639e89eb1fce9a3a9b (patch)
treedb4d837d1f7cd9fd3b7fa369a0d68367faecbb0b /lib/github
parent8538066e00d8bda542f219fb03d104f8364760bd (diff)
downloadgitlab-ce-104144f373a58069680dd3639e89eb1fce9a3a9b.tar.gz
Refactoring client to not parse response body automatically
Diffstat (limited to 'lib/github')
-rw-r--r--lib/github/client.rb7
-rw-r--r--lib/github/rate_limit.rb10
-rw-r--r--lib/github/response.rb11
3 files changed, 15 insertions, 13 deletions
diff --git a/lib/github/client.rb b/lib/github/client.rb
index 2511523bf6a..07cf264e8d7 100644
--- a/lib/github/client.rb
+++ b/lib/github/client.rb
@@ -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
diff --git a/lib/github/rate_limit.rb b/lib/github/rate_limit.rb
index 30b000f8a9a..9dbdf2f4c68 100644
--- a/lib/github/rate_limit.rb
+++ b/lib/github/rate_limit.rb
@@ -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
diff --git a/lib/github/response.rb b/lib/github/response.rb
index c34b69aa4ea..2fa852c9fdc 100644
--- a/lib/github/response.rb
+++ b/lib/github/response.rb
@@ -1,12 +1,11 @@
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