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
1
Merge Requests
1
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
nexedi
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
Hide 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
...
@@ -4,10 +4,8 @@ module Github
def
initialize
(
token
)
def
initialize
(
token
)
@connection
=
Faraday
.
new
(
url:
'https://api.github.com'
)
do
|
faraday
|
@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
.
authorization
'token'
,
token
faraday
.
response
:logger
faraday
.
adapter
:net_http
end
end
end
end
...
@@ -15,7 +13,8 @@ module Github
...
@@ -15,7 +13,8 @@ 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?
Github
::
Response
.
new
(
connection
.
get
(
url
,
query
))
response
=
connection
.
get
(
url
,
query
)
Github
::
Response
.
new
(
response
.
headers
,
response
.
body
,
response
.
status
)
end
end
end
end
end
end
lib/github/rate_limit.rb
View file @
104144f3
...
@@ -16,11 +16,11 @@ module Github
...
@@ -16,11 +16,11 @@ module Github
end
end
def
remaining
def
remaining
@remaining
||=
response
.
body
.
dig
(
'rate'
,
'remaining'
).
to_i
@remaining
||=
body
.
dig
(
'rate'
,
'remaining'
).
to_i
end
end
def
reset_in
def
reset_in
@reset
||=
response
.
body
.
dig
(
'rate'
,
'reset'
).
to_i
@reset
||=
body
.
dig
(
'rate'
,
'reset'
).
to_i
end
end
private
private
...
@@ -30,7 +30,11 @@ module Github
...
@@ -30,7 +30,11 @@ module Github
end
end
def
response
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
end
# GitHub Rate Limit API returns 404 when the rate limit is disabled
# GitHub Rate Limit API returns 404 when the rate limit is disabled
...
...
lib/github/response.rb
View file @
104144f3
module
Github
module
Github
class
Response
class
Response
attr_reader
:
raw
,
:
headers
,
:body
,
:status
attr_reader
:headers
,
:body
,
:status
def
initialize
(
response
)
def
initialize
(
headers
,
body
,
status
)
@raw
=
response
@headers
=
headers
@headers
=
response
.
headers
@body
=
Oj
.
load
(
body
,
class_cache:
false
,
mode: :compat
)
@body
=
response
.
body
@status
=
status
@status
=
response
.
status
end
end
def
rels
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