Add HTTP endpoints for GET/POST reviews.

* GET /reviews (packageName, nextPageToken) => get list of reviews
* POST /reviews => Not implemented
This commit is contained in:
John Giannelos 2018-10-23 14:52:25 +02:00
Родитель d05e87f246
Коммит daa63d809e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7927444B540C0A7B
1 изменённых файлов: 43 добавлений и 0 удалений

43
api.py Normal file
Просмотреть файл

@ -0,0 +1,43 @@
import os
from flask import Flask, make_response, request
from flask.json import jsonify
from mozapkpublisher.common.googleplay import connect
app = Flask(__name__)
# Settings
PLAY_ACCOUNT = os.getenv('PLAY_ACCOUNT')
PLAY_CREDENTIALS_PATH = os.getenv('PLAY_CREDENTIALS_PATH')
def get_reviews_service():
"""Create new instance of google play API service."""
service = connect(PLAY_ACCOUNT, PLAY_CREDENTIALS_PATH)
return service.reviews()
@app.route('/reviews', methods=['GET'])
def get_reviews():
"""Get playstore reviews. Proxy playstore API requests."""
packageName = request.args.get('packageName', None)
nextPageToken = request.args.get('nextPageToken', None)
if not packageName:
content = jsonify(msg='Missing `packageName` from request query')
return make_response(content, 400)
reviews_service = get_reviews_service()
query = reviews_service.list(packageName=packageName, token=nextPageToken)
return make_response(jsonify(query.execute()), 200)
@app.route('/reviews', methods=['POST'])
def post_reviews():
"""Post playstore reviews."""
return make_response(jsonify(msg='POST method not implemented'), 501)