Skip to content

Commit 15a28bd

Browse files
authored
Merge pull request #10 from soda480/0.0.7
Add version parameter and disable chunkedencodingerror retry
2 parents e47185d + 40b22fb commit 15a28bd

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
]
3535
summary = 'An advanced REST client for the GitHub API'
3636
url = 'https://github.com/soda480/github3api'
37-
version = '0.0.6'
37+
version = '0.0.7'
3838
default_task = [
3939
'clean',
4040
'analyze',

src/main/python/github3api/githubapi.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
logging.getLogger('urllib3.connectionpool').setLevel(logging.CRITICAL)
2828

2929
HOSTNAME = 'api.github.com'
30+
VERSION = 'v3'
3031

3132

3233
class GitHubAPI(RESTclient):
@@ -36,6 +37,7 @@ class GitHubAPI(RESTclient):
3637
def __init__(self, **kwargs):
3738
logger.debug('executing GitHubAPI constructor')
3839
hostname = kwargs.pop('hostname', HOSTNAME)
40+
self.version = kwargs.pop('version', VERSION)
3941
super(GitHubAPI, self).__init__(hostname, **kwargs)
4042

4143
def get_response(self, response, **kwargs):
@@ -50,7 +52,7 @@ def get_headers(self, **kwargs):
5052
""" return headers to pass to requests method
5153
"""
5254
headers = super(GitHubAPI, self).get_headers(**kwargs)
53-
headers['Accept'] = 'application/vnd.github.v3+json'
55+
headers['Accept'] = f'application/vnd.github.{self.version}+json'
5456
return headers
5557

5658
def _get_next_endpoint(self, link_header):
@@ -175,7 +177,7 @@ def retry_ratelimit_error(exception):
175177
return False
176178

177179
@staticmethod
178-
def retry_chunkedencodingerror_error(exception):
180+
def _retry_chunkedencodingerror_error(exception):
179181
""" return True if exception is ChunkedEncodingError, False otherwise
180182
retry:
181183
wait_fixed:10000

src/unittest/python/test_githubapi.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ def test__get_headers_Should_SetAcceptHeader_When_Called(self, *patches):
165165
result = client.get_headers()
166166
self.assertEqual(result['Accept'], 'application/vnd.github.v3+json')
167167

168+
def test__get_headers_Should_SetAcceptHeader_When_Version(self, *patches):
169+
client = GitHubAPI(bearer_token='bearer-token', version='v2')
170+
result = client.get_headers()
171+
self.assertEqual(result['Accept'], 'application/vnd.github.v2+json')
172+
168173
def test__get_next_endpoint_Should_ReturnNone_When_NoLinkHeader(self, *patches):
169174
client = GitHubAPI(bearer_token='bearer-token')
170175
self.assertIsNone(client._get_next_endpoint(None))
@@ -328,11 +333,11 @@ def test__get_client_Should_CallAndReturnExpected_When_Called(self, githubapi_pa
328333
def test__get_retries_Should_ReturnExpected_When_Called(self, *patches):
329334
client = GitHubAPI(bearer_token='bearer-token')
330335
expected_retries = [
331-
{
332-
'retry_on_exception': client.retry_chunkedencodingerror_error,
333-
'stop_max_attempt_number': 120,
334-
'wait_fixed': 10000
335-
},
336+
# {
337+
# 'retry_on_exception': client.retry_chunkedencodingerror_error,
338+
# 'stop_max_attempt_number': 120,
339+
# 'wait_fixed': 10000
340+
# },
336341
{
337342
'retry_on_exception': client.retry_ratelimit_error,
338343
'stop_max_attempt_number': 60,
@@ -344,8 +349,8 @@ def test__get_retries_Should_ReturnExpected_When_Called(self, *patches):
344349

345350
def test__retry_chunkedencodingerror_error_Should_Return_False_When_NotChunkEncodingError(self, *patches):
346351

347-
self.assertFalse(GitHubAPI.retry_chunkedencodingerror_error(Exception('test')))
352+
self.assertFalse(GitHubAPI._retry_chunkedencodingerror_error(Exception('test')))
348353

349354
def test__retry_chunkedencodingerror_error_Should_Return_True_When_ChunkEncodingError(self, *patches):
350355

351-
self.assertTrue(GitHubAPI.retry_chunkedencodingerror_error(ChunkedEncodingError()))
356+
self.assertTrue(GitHubAPI._retry_chunkedencodingerror_error(ChunkedEncodingError()))

0 commit comments

Comments
 (0)