-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Take args from JSON post data #8
base: master
Are you sure you want to change the base?
Changes from 4 commits
c8e822a
e47adf4
dac83a8
13dea4d
b75a99e
7ee4f65
6942484
c624e4d
595d0ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,12 +45,28 @@ | |
def hello_world(): | ||
if request.headers.get('TOKEN', '') != token_value: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sameetandpotatoes Change this on service side as well ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
abort(401) | ||
if 'item' not in request.args: | ||
abort(400) | ||
item = request.args['item'] | ||
merch.vend(item[0], int(item[1])) | ||
return json.dumps({'success': True}), 200, {'ContentType': 'application/json'} | ||
data = request.json() | ||
items = data['items'] | ||
transaction_id = data['transaction_id'] | ||
|
||
|
||
statuses = [] | ||
for i, item in enumerate(items): | ||
try: | ||
merch.vend(item[0], int(item[1])) | ||
statuses.append({'error': None, 'location': item}) | ||
|
||
except Exception as e: | ||
# Some error occurred while vending | ||
# I'd prefer to catch Merch.VendError's only, but if something else | ||
# goes wrong, we still need to let the client know instead of | ||
# throwing a 500 | ||
statuses.append({'error': str(e), 'location': item}) | ||
|
||
return jsonify(transaction_id=transaction_id, items=statuses) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, host='0.0.0.0') | ||
# Make sure flask runs in a single thread. Otherwise concurrent requests | ||
# may cause problems with vending | ||
app.run(debug=True, host='0.0.0.0', threaded=False) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be something like
"Requests to the device must contain a valid token in the Authorization Header for a request to be processed.
As of now the only token will be given solely to the groot merch service, so if you wish to make merch requests go through groot. "
Also rename the header field from Token to Authorization, better match with web conventions (may require change by @sameetandpotatoes on the service side)