Skip to content

Commit

Permalink
enabled raw_response option
Browse files Browse the repository at this point in the history
  • Loading branch information
gurudevrao authored Aug 5, 2020
1 parent badf8d1 commit 3332e88
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gurunudi/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import constants
from . import lang
from . import config

import sys

class AI(object):
"""
Expand Down Expand Up @@ -235,7 +235,7 @@ def translate(self,text,target_lang,src_lang):
return self.__call_api(constants.API_TRANSLATE,{constants.FIELD_TEXT:text,constants.FIELD_LANG:src_lang,constants.FIELD_TARGET_LANG:target_lang})


def __call_api(self,api,data):
def __call_api(self,api,data,raw_response=False):
"""
calls given Gurunudi api with given data and returns the result
api (string): The name of the API to call
Expand Down Expand Up @@ -263,7 +263,7 @@ def __call_api(self,api,data):

if response.status_code==200:#if response OK
#if raw json response is requested
if raw_response=True:
if raw_response:
return json

if constants.FIELD_TEXT in json:#if response is plain text
Expand All @@ -277,6 +277,7 @@ def __call_api(self,api,data):
raise APIError("status_code_"+str(response.status_code))

except requests.exceptions.ConnectionError as ex:
print(ex,file=sys.stderr)
raise APIError(constants.ERROR_SERVER_INACCESSIBLE)


Expand Down

0 comments on commit 3332e88

Please sign in to comment.