Adding URL to download premium voices

pull/175/head
Matheus Lima 2019-06-04 18:34:01 -03:00
parent d90e80d463
commit 32f7363d1f
2 changed files with 37 additions and 1 deletions

View File

@ -23,6 +23,7 @@ from .endpoints.device_subscription import DeviceSubscriptionEndpoint
from .endpoints.google_stt import GoogleSTTEndpoint
from .endpoints.oauth_callback import OauthCallbackEndpoint
from .endpoints.open_weather_map import OpenWeatherMapEndpoint
from .endpoints.premium_voice import PremiumVoiceEndpoint
from .endpoints.wolfram_alpha import WolframAlphaEndpoint
from .endpoints.wolfram_alpha_spoken import WolframAlphaSpokenEndpoint
@ -130,13 +131,18 @@ public.add_url_rule(
methods=['GET']
)
public.add_url_rule(
'/v1/device/<string:device_id>/voice',
view_func=PremiumVoiceEndpoint.as_view('premium_voice_api'),
methods=['GET']
)
public.add_url_rule(
'/v1/device/<string:device_id>/<string:oauth_path>/<string:credentials>',
view_func=OauthServiceEndpoint.as_view('oauth_api'),
methods=['GET']
)
"""
This is a workaround to allow the API return 401 when we call a non existent path. Use case:
GET /device/{uuid} with empty uuid. Core today uses the 401 to validate if it needs to perform a pairing process

View File

@ -0,0 +1,30 @@
import os
from http import HTTPStatus
from selene.api import SeleneEndpoint
from selene.data.account import AccountRepository
class PremiumVoiceEndpoint(SeleneEndpoint):
def __init__(self):
super(PremiumVoiceEndpoint, self).__init__()
def get(self, device_id):
self._authenticate()
arch = self.request.args.get('arch')
account = AccountRepository(self.db).get_account_by_device_id(device_id)
if account and account.membership:
link = self._get_premium_voice_link(arch)
response = {'link': link}, HTTPStatus.OK
else:
response = '', HTTPStatus.NO_CONTENT
return response
def _get_premium_voice_link(self, arch):
if arch == 'arm':
response = os.environ['URL_VOICE_ARM']
elif arch == 'x86_86':
response = os.environ['URL_VOICE_X86_64']
else:
response = ''
return response