Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
104144f3
Commit
104144f3
authored
Apr 12, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring client to not parse response body automatically
parent
8538066e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
13 deletions
+15
-13
lib/github/client.rb
lib/github/client.rb
+3
-4
lib/github/rate_limit.rb
lib/github/rate_limit.rb
+7
-3
lib/github/response.rb
lib/github/response.rb
+5
-6
No files found.
lib/github/client.rb
View file @
104144f3
...
...
@@ -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
lib/github/rate_limit.rb
View file @
104144f3
...
...
@@ -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
...
...
lib/github/response.rb
View file @
104144f3
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment