Skip to content

Commit d9f8f05

Browse files
committed
Merge pull request #17 from cardforcoin/code-style
Some simple code style fixes
2 parents 5ff0f68 + dc13af3 commit d9f8f05

7 files changed

Lines changed: 36 additions & 34 deletions

File tree

README.txt

Whitespace-only changes.

coinbase/__init__.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
__author__ = 'gsibble'
3535

36-
from oauth2client.client import AccessTokenRefreshError, OAuth2Credentials, AccessTokenCredentialsError
36+
from oauth2client.client import AccessTokenRefreshError, OAuth2Credentials, \
37+
AccessTokenCredentialsError
3738

3839
import requests
3940
import httplib2
@@ -59,8 +60,8 @@ def __init__(self,
5960
oauth2_credentials=None,
6061
api_key=None):
6162
"""
62-
63-
:param oauth2_credentials: JSON representation of Coinbase oauth2 credentials
63+
:param oauth2_credentials: JSON representation of Coinbase oauth2
64+
credentials
6465
:param api_key: Coinbase API key
6566
"""
6667

@@ -81,7 +82,8 @@ def __init__(self,
8182
self.http = httplib2.Http(ca_certs=ca_path)
8283

8384
#Create our credentials from the JSON sent
84-
self.oauth2_credentials = OAuth2Credentials.from_json(oauth2_credentials)
85+
self.oauth2_credentials = \
86+
OAuth2Credentials.from_json(oauth2_credentials)
8587

8688
#Check our token
8789
self.token_expired = False
@@ -115,7 +117,7 @@ def _check_oauth_expired(self):
115117
"""
116118

117119
#Check if they are expired
118-
if self.oauth2_credentials.access_token_expired == True:
120+
if self.oauth2_credentials.access_token_expired:
119121

120122
#Print an notification message if they are
121123
print 'oAuth2 Token Expired'
@@ -127,7 +129,8 @@ def refresh_oauth(self):
127129
"""
128130
Refresh our oauth2 token
129131
:return: JSON representation of oauth token
130-
:raise: AccessTokenRefreshError if there was an error refreshing the token
132+
:raise: AccessTokenRefreshError if there was an error refreshing the
133+
token
131134
"""
132135

133136
#See if we can refresh the token
@@ -136,7 +139,6 @@ def refresh_oauth(self):
136139
self.oauth2_credentials.refresh(http=self.http)
137140

138141
#We were successful
139-
#print 'Your token was refreshed with the following response...'
140142

141143
#Return the token for storage
142144
return self.oauth2_credentials
@@ -223,28 +225,24 @@ def sell_price(self, qty=1):
223225
results = response.json()
224226
return CoinbaseAmount(results['amount'], results['currency'])
225227

226-
# @property
227-
# def user(self):
228-
# url = COINBASE_ENDPOINT + '/account/receive_address'
229-
# response = self.session.get(url)
230-
# return response.json()
231-
232-
233228
def buy_btc(self, qty, pricevaries=False):
234229
"""
235230
Buy BitCoin from Coinbase for USD
236231
:param qty: BitCoin quantity to be bought
237-
:param pricevaries: Boolean value that indicates whether or not the transaction should
238-
be processed if Coinbase cannot gaurentee the current price.
239-
:return: CoinbaseTransfer with all transfer details on success or
240-
CoinbaseError with the error list received from Coinbase on failure
232+
:param pricevaries: Boolean value that indicates whether or not the
233+
transaction should be processed if Coinbase cannot guarantee
234+
the current price.
235+
:return: CoinbaseTransfer with all transfer details on success or
236+
CoinbaseError with the error list received from Coinbase on
237+
failure
241238
"""
242239
url = COINBASE_ENDPOINT + '/buys'
243240
request_data = {
244241
"qty": qty,
245242
"agree_btc_amount_varies": pricevaries
246243
}
247-
response = self.session.post(url=url, data=json.dumps(request_data), params=self.global_request_params)
244+
response = self.session.post(url=url, data=json.dumps(request_data),
245+
params=self.global_request_params)
248246
response_parsed = response.json()
249247
if response_parsed['success'] == False:
250248
return CoinbaseError(response_parsed['errors'])
@@ -257,13 +255,15 @@ def sell_btc(self, qty):
257255
Sell BitCoin to Coinbase for USD
258256
:param qty: BitCoin quantity to be sold
259257
:return: CoinbaseTransfer with all transfer details on success or
260-
CoinbaseError with the error list received from Coinbase on failure
258+
CoinbaseError with the error list received from Coinbase
259+
on failure
261260
"""
262261
url = COINBASE_ENDPOINT + '/sells'
263262
request_data = {
264263
"qty": qty,
265264
}
266-
response = self.session.post(url=url, data=json.dumps(request_data), params=self.global_request_params)
265+
response = self.session.post(url=url, data=json.dumps(request_data),
266+
params=self.global_request_params)
267267
response_parsed = response.json()
268268
if response_parsed['success'] == False:
269269
return CoinbaseError(response_parsed['errors'])
@@ -310,7 +310,8 @@ def request(self, from_email, amount, notes='', currency='BTC'):
310310

311311
def send(self, to_address, amount, notes='', currency='BTC'):
312312
"""
313-
Send BitCoin from this account to either an email address or a BTC address
313+
Send BitCoin from this account to either an email address or a BTC
314+
address
314315
:param to_address: Email or BTC address to where coin should be sent
315316
:param amount: Amount of currency to send
316317
:param notes: Notes to be included with transaction
@@ -338,7 +339,8 @@ def send(self, to_address, amount, notes='', currency='BTC'):
338339
}
339340
}
340341

341-
response = self.session.post(url=url, data=json.dumps(request_data), params=self.global_request_params)
342+
response = self.session.post(url=url, data=json.dumps(request_data),
343+
params=self.global_request_params)
342344
response_parsed = response.json()
343345

344346
if response_parsed['success'] == False:
@@ -413,7 +415,7 @@ def get_transaction(self, transaction_id):
413415
response = self.session.get(url, params=self.global_request_params)
414416
results = response.json()
415417

416-
if results.get('success', True) == False:
418+
if not results.get('success', True):
417419
pass
418420
#TODO: Add error handling
419421

@@ -461,7 +463,8 @@ def generate_receive_address(self, callback_url=None):
461463
"callback_url": callback_url
462464
}
463465
}
464-
response = self.session.post(url=url, data=json.dumps(request_data), params=self.global_request_params)
466+
response = self.session.post(url=url, data=json.dumps(request_data),
467+
params=self.global_request_params)
465468
return response.json()['address']
466469

467470

coinbase/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88

99
TEMP_CREDENTIALS = '''
10-
{"_module": "oauth2client.client", "token_expiry": "2013-03-24T02:37:50Z", "access_token": "2a02d1fc82b1c42d4ea94d6866b5a232b53a3a50ad4ee899ead9afa6144c2ca3", "token_uri": "https://www.coinbase.com/oauth/token", "invalid": false, "token_response": {"access_token": "2a02d1fc82b1c42d4ea94d6866b5a232b53a3a50ad4ee899ead9afa6144c2ca3", "token_type": "bearer", "expires_in": 7200, "refresh_token": "ffec0153da773468c8cb418d07ced54c13ca8deceae813c9be0b90d25e7c3d71", "scope": "all"}, "client_id": "2df06cb383f4ffffac20e257244708c78a1150d128f37d420f11fdc069a914fc", "id_token": null, "client_secret": "7caedd79052d7e29aa0f2700980247e499ce85381e70e4a44de0c08f25bded8a", "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials", "refresh_token": "ffec0153da773468c8cb418d07ced54c13ca8deceae813c9be0b90d25e7c3d71", "user_agent": null}'''
10+
{"_module": "oauth2client.client", "token_expiry": "2013-03-24T02:37:50Z", "access_token": "2a02d1fc82b1c42d4ea94d6866b5a232b53a3a50ad4ee899ead9afa6144c2ca3", "token_uri": "https://www.coinbase.com/oauth/token", "invalid": false, "token_response": {"access_token": "2a02d1fc82b1c42d4ea94d6866b5a232b53a3a50ad4ee899ead9afa6144c2ca3", "token_type": "bearer", "expires_in": 7200, "refresh_token": "ffec0153da773468c8cb418d07ced54c13ca8deceae813c9be0b90d25e7c3d71", "scope": "all"}, "client_id": "2df06cb383f4ffffac20e257244708c78a1150d128f37d420f11fdc069a914fc", "id_token": null, "client_secret": "7caedd79052d7e29aa0f2700980247e499ce85381e70e4a44de0c08f25bded8a", "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials", "refresh_token": "ffec0153da773468c8cb418d07ced54c13ca8deceae813c9be0b90d25e7c3d71", "user_agent": null}'''

coinbase/models/error.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
__author__ = 'kroberts'
22

33

4-
54
class CoinbaseError(object):
65

76
def __init__(self, errorList):

coinbase_oauth2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def receive_token():
3636
return make_response(token.to_json())
3737

3838
if __name__ == '__main__':
39-
APP.run(host='0.0.0.0', port=80)
39+
APP.run(host='0.0.0.0', port=80)

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ def do_coinbase_stuff(account):
6262

6363
if __name__ == '__main__':
6464
account = CoinbaseAccount(oauth2_credentials=TEMP_CREDENTIALS)
65-
do_coinbase_stuff(account=account)
65+
do_coinbase_stuff(account=account)

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
'Operating System :: Microsoft :: Windows',
2020
'Operating System :: POSIX',
2121
'Programming Language :: Python',
22-
'Topic :: Software Development :: Libraries :: Python Modules'
23-
],
22+
'Topic :: Software Development :: Libraries :: Python Modules',
23+
],
2424
install_requires=[
2525
'httplib2>=0.8',
2626
'requests>=1.1.0',
27-
'oauth2client>=1.1'
28-
],
27+
'oauth2client>=1.1',
28+
],
2929
tests_require=[
3030
'sure>=1.2.5',
3131
'httpretty>=0.8.0',
32-
],
32+
],
3333
)

0 commit comments

Comments
 (0)