Skip to content

Commit f0b0272

Browse files
committed
Fix the request auth params.
1 parent 8edffd1 commit f0b0272

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

coinbase/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@
3737
from oauth2client.client import AccessTokenRefreshError, \
3838
OAuth2Credentials, AccessTokenCredentialsError
3939
oauth2_supported = True
40-
except:
40+
except ImportError:
4141
oauth2_supported = False
4242

43+
try:
44+
from urllib import urlsplit, urlunsplit, quote
45+
except ImportError:
46+
from urllib import quote
47+
from urlparse import urlsplit, urlunsplit
48+
4349
import httplib2
4450
import json
4551
import os
@@ -160,7 +166,11 @@ def __call__(self, req):
160166
'ACCESS_NONCE': nonce})
161167

162168
elif self.api_key is not None:
163-
req.params.update({'api_key': api_key})
169+
url_parts = urlsplit(req.url)
170+
new_query = '&'.join(
171+
filter(None, [url_parts.query,
172+
quote('api_key={}'.format(self.api_key))]))
173+
req.url = urlunsplit(url_parts._replace(query=new_query))
164174
return req
165175

166176

coinbase/tests/test_buy_price.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def test_buy_price_with_oauth(self):
2424

2525
def go(self, account):
2626
this(account.buy_price()).should.equal(self.expected_price)
27-
this(last_request_params()).should.equal({'qty': ['1']})
27+
params = last_request_params()
28+
params.pop('api_key', None)
29+
this(params).should.equal({'qty': ['1']})
2830

2931
response_body = """
3032
{
@@ -54,7 +56,9 @@ def test_buy_price_with_oauth(self):
5456

5557
def go(self, account):
5658
this(account.buy_price('10')).should.equal(self.expected_price)
57-
this(last_request_params()).should.equal({'qty': ['10']})
59+
params = last_request_params()
60+
params.pop('api_key', None)
61+
this(params).should.equal({'qty': ['10']})
5862

5963
response_body = """
6064
{

coinbase/tests/test_sell_price.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def test_sell_price_with_oauth(self):
2424

2525
def go(self, account):
2626
this(account.sell_price()).should.equal(self.expected_price)
27-
this(last_request_params()).should.equal({'qty': ['1']})
27+
params = last_request_params()
28+
params.pop('api_key', None)
29+
this(params).should.equal({'qty': ['1']})
2830

2931
response_body = """
3032
{
@@ -54,7 +56,9 @@ def test_sell_price_with_oauth(self):
5456

5557
def go(self, account):
5658
this(account.sell_price(10)).should.equal(self.expected_price)
57-
this(last_request_params()).should.equal({'qty': ['10']})
59+
params = last_request_params()
60+
params.pop('api_key', None)
61+
this(params).should.equal({'qty': ['10']})
5862

5963
response_body = """
6064
{

0 commit comments

Comments
 (0)