Skip to content

Commit abadcd6

Browse files
authored
Merge pull request #52 from ringcentral/RemoveAcceptHeader
removed accept header so to also work for binary response
2 parents 1b2c739 + c1d403a commit abadcd6

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

ringcentral/http/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def create_request(self, method='', url='', query_params=None, body=None, header
7575
url = url + ('&' if url.find('?') > 0 else '?') + query
7676

7777
content_type = None
78-
accept = None
79-
78+
8079
if headers is None:
8180
headers = {}
8281

@@ -86,16 +85,12 @@ def create_request(self, method='', url='', query_params=None, body=None, header
8685
if key.lower().find('content-type') >= 0:
8786
content_type = value
8887
if key.lower().find('accept') >= 0:
89-
accept = value
88+
headers['Accept'] = value
9089

9190
if content_type is None:
9291
content_type = 'application/json'
9392
headers['Content-Type'] = content_type
9493

95-
if accept is None:
96-
accept = 'application/json'
97-
headers['Accept'] = accept
98-
9994
if content_type.lower().find('application/json') >= 0:
10095
body = json.dumps(body) if body else None
10196
elif content_type.lower().find('application/x-www-form-urlencoded') >= 0:

ringcentral/platform/platform_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def test_login_code(self, mock):
2626
sdk.platform().login(code='foo')
2727
text = str(mock.request_history[-1].text)
2828
if sys.version_info[0] == 3:
29-
self.assertEqual(text, 'grant_type=authorization_code&redirect_uri=mock%3A%2F%2Fwhatever-redirect&code=foo')
29+
self.assertEqual(text, 'grant_type=authorization_code&redirect_uri=https%3A%2F%2Fwhatever-redirect&code=foo')
3030
else:
31-
self.assertEqual(text, 'code=foo&grant_type=authorization_code&redirect_uri=mock%3A%2F%2Fwhatever-redirect')
31+
self.assertEqual(text, 'code=foo&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fwhatever-redirect')
3232

3333
def test_login_fail(self, mock):
3434
sdk = self.get_sdk(mock)
@@ -123,7 +123,7 @@ def test_logout(self, mock):
123123
def test_api_url(self, mock):
124124
sdk = self.get_sdk(mock)
125125

126-
exp1 = 'mock://whatever/restapi/v1.0/account/~/extension/~?_method=POST&access_token=ACCESS_TOKEN'
126+
exp1 = 'https://whatever/restapi/v1.0/account/~/extension/~?_method=POST&access_token=ACCESS_TOKEN'
127127
act1 = sdk.platform().create_url('/account/~/extension/~', add_server=True, add_method='POST', add_token=True)
128128
self.assertEqual(exp1, act1)
129129

@@ -134,12 +134,12 @@ def test_api_url(self, mock):
134134

135135
def test_api_url_custom_prefixes(self, mock):
136136
sdk = self.get_sdk(mock)
137-
exp = 'mock://whatever/scim/v2/foo'
137+
exp = 'https://whatever/scim/v2/foo'
138138
url = '/scim/v2/foo'
139139
act = sdk.platform().create_url(url, add_server=True)
140140
self.assertEqual(exp, act)
141141

142-
exp = 'mock://whatever/analytics/phone/foo'
142+
exp = 'https://whatever/analytics/phone/foo'
143143
url = '/analytics/phone/foo'
144144
act = sdk.platform().create_url(url, add_server=True)
145145
self.assertEqual(exp, act)

ringcentral/sdk_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
class TestSDK(TestCase):
1010
def test_instance(self):
11-
sdk = SDK('whatever', 'whatever', 'mock://whatever')
12-
self.assertEqual(sdk.platform().create_url('/foo', add_server=True), 'mock://whatever/restapi/v1.0/foo')
11+
sdk = SDK('whatever', 'whatever', 'https://whatever')
12+
self.assertEqual(sdk.platform().create_url('/foo', add_server=True), 'https://whatever/restapi/v1.0/foo')
1313

1414

1515
if __name__ == '__main__':

ringcentral/test/testcase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, method_name=None):
1818

1919
def get_sdk(self, mock):
2020

21-
sdk = SDK('whatever', 'whatever', 'mock://whatever', redirect_uri='mock://whatever-redirect')
21+
sdk = SDK('whatever', 'whatever', 'https://whatever', redirect_uri='https://whatever-redirect')
2222

2323
self.authentication_mock(mock)
2424
sdk.platform().login('18881112233', None, 'password')
@@ -44,7 +44,7 @@ def get_sdk(self, mock):
4444
def add(self, mock, method, url, body, status=200):
4545
mock.register_uri(
4646
method=method,
47-
url='mock://whatever' + url,
47+
url='https://whatever' + url,
4848
text=json.dumps(body),
4949
headers={'Content-Type': 'application/json'},
5050
status_code=status

0 commit comments

Comments
 (0)