Skip to content

Commit

Permalink
Merge branch 'develop' into feature/swagger-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Jul 18, 2019
2 parents 6114c28 + e445132 commit 87c6b20
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.template.loader import render_to_string
from django.dispatch import receiver
from django.core.exceptions import ValidationError
from rest_framework import status
from rest_framework.exceptions import APIException

from bothub.authentication.models import User

Expand Down Expand Up @@ -182,35 +184,50 @@ class Meta:

@classmethod
def request_nlp_train(cls, user_authorization):
r = requests.post( # pragma: no cover
cls.nlp_train_url,
data={},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
try:
r = requests.post( # pragma: no cover
cls.nlp_train_url,
data={},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
except requests.exceptions.ConnectionError: # pragma: no cover
raise APIException( # pragma: no cover
{'status_code': status.HTTP_503_SERVICE_UNAVAILABLE},
code=status.HTTP_503_SERVICE_UNAVAILABLE)

@classmethod
def request_nlp_analyze(cls, user_authorization, data):
r = requests.post( # pragma: no cover
cls.nlp_analyze_url,
data={
'text': data.get('text'),
'language': data.get('language'),
},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
try:
r = requests.post( # pragma: no cover
cls.nlp_analyze_url,
data={
'text': data.get('text'),
'language': data.get('language'),
},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
except requests.exceptions.ConnectionError: # pragma: no cover
raise APIException( # pragma: no cover
{'status_code': status.HTTP_503_SERVICE_UNAVAILABLE},
code=status.HTTP_503_SERVICE_UNAVAILABLE)

@classmethod
def request_nlp_evaluate(cls, user_authorization, data):
r = requests.post( # pragma: no cover
cls.nlp_evaluate_url,
data={
'language': data.get('language'),
},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
try: # pragma: no cover
r = requests.post( # pragma: no cover
cls.nlp_evaluate_url,
data={
'language': data.get('language'),
},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
except requests.exceptions.ConnectionError: # pragma: no cover
raise APIException( # pragma: no cover
{'status_code': status.HTTP_503_SERVICE_UNAVAILABLE},
code=status.HTTP_503_SERVICE_UNAVAILABLE)

@property
def available_languages(self):
Expand Down

0 comments on commit 87c6b20

Please sign in to comment.