fix twitter api responses

This commit is contained in:
Łukasz Jędyk 2022-01-24 22:20:54 +01:00
parent f8aab50eae
commit a41a7dc052

View File

@ -18,12 +18,9 @@ def get_twitter_accounts():
account_data['username'] = account.username account_data['username'] = account.username
accounts.append(account_data) accounts.append(account_data)
return Response( return jsonify({
jsonify({ "twitter_accounts": accounts
"twitter_accounts": accounts }), 200
}),
status=200,
)
@twitter.route('/account', methods=['POST']) @twitter.route('/account', methods=['POST'])
def add_twitter_account(): def add_twitter_account():
@ -31,10 +28,7 @@ def add_twitter_account():
if (content_type == 'application/json'): if (content_type == 'application/json'):
json = request.json json = request.json
if not json['veryfier'] or not json['oauth_token'] or not json['oauth_token_secret']: if not json['veryfier'] or not json['oauth_token'] or not json['oauth_token_secret']:
return Response( return "Invalid request!", 400
"Invalid request!",
status=400,
)
else: else:
consumer_key = current_app.config["TWITTER_CONSUMER_KEY"] consumer_key = current_app.config["TWITTER_CONSUMER_KEY"]
consumer_secret = current_app.config["TWITTER_CONSUMER_SECERT"] consumer_secret = current_app.config["TWITTER_CONSUMER_SECERT"]
@ -58,16 +52,7 @@ def add_twitter_account():
twitter_db.session.add(new_twitter_account) twitter_db.session.add(new_twitter_account)
twitter_db.session.commit() twitter_db.session.commit()
return Response( return "Twitter account succesfully added.", 201
jsonify({
"message": "Twitter account succesfully added."
}),
status=201,
)
else: else:
return Response( return "Content-type not supported!", 400
"Content-type not supported!",
status=400,
)