apiService.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import requests
  2. import json
  3. import traceback
  4. class ApiService:
  5. """
  6. This class intended to provide helper methods W.r.t to API's
  7. Methods
  8. -------
  9. callRestAPI(file_name,extension,user_id)
  10. calls RestAPI to write information to DynamoDB.
  11. """
  12. def post_api_call(self,content_api_call, api_url):
  13. """ Rest API Call
  14. Attributes
  15. ----------
  16. file_name:string
  17. The name of the file which need to be posted.
  18. extension:string
  19. The extension of the file which need to be posted
  20. user_id:string
  21. Which need to be posted as well along with the above.
  22. """
  23. response= requests.post(api_url, json = content_api_call)
  24. return response
  25. def content_to_api_call(self,file_id,file_name,user_id,extension):
  26. """Prepares an json to pass as an body to the rest api call
  27. Parameters:
  28. file_id: string
  29. Id which need to be uploaded to dynamo db
  30. file_name : string
  31. file_name associated with the file_id
  32. user_id: string
  33. To send the back the response of users with the user_id
  34. extension: string
  35. The extension of the file.
  36. Returns:
  37. A dictionary where file_id, file_name, user_id, and file_type are the keys.
  38. """
  39. api_call_content = [{'file_id': file_id, 'file_name': file_name, 'user_id' : user_id, 'file_type':extension}]
  40. print("The api-call-content is",api_call_content)
  41. #print("The api-call content type is",type(api_api_call_content))
  42. return api_call_content
  43. #Corrections:
  44. # I have to use same uuid when posting the
  45. #URL as parameter
  46. #Seperate function for post event
  47. #PostDataToURL take only 2 parameters.