Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

93 righe
3.2 KiB

  1. import json
  2. import requests
  3. import sys
  4. from authorization import Authorization
  5. from majortel import Majortel
  6. from utils import Utils
  7. import os
  8. import ipaddress
  9. # \\\ CLIENT API ///
  10. #
  11. # Esempio chiamata:
  12. # >> python client_api.py args
  13. # Input data:
  14. # ARGV 1: Host server API
  15. # ARGV 2: Username
  16. # ARGV 3: Password
  17. # ARGV 4: comando (es. 'call'). Comando che identifica univocamente una API.
  18. # ARGV *: vedi documentazione singolo comando.
  19. # Politica nomenclatura comandi:
  20. # {http_method} _ {modulo} _ {nome_api}
  21. #
  22. # es:
  23. # get_presense_settings
  24. class ClientApi:
  25. def __init__(self, host_server = sys.argv[1], username = sys.argv[2], password = sys.argv[3], api_command = sys.argv[4], debug=False):
  26. print("Api command: "+api_command)
  27. self.debug = debug
  28. self.api_command = api_command
  29. self.api_url_base = Utils.generate_url_base(host_server)
  30. self.token_data = Authorization.get_token(self, {"username": username, "password": password})
  31. self.headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(self.token_data['access_token'])}
  32. self.check_command()
  33. def check_command(self):
  34. if (self.api_command == "post_majortel_call"):
  35. ''' post_majortel_call '''
  36. # ARGV 5: callerNumber. Numero chiamante
  37. # ARGV 6: calledNumber. Numero chiamato
  38. self.callerNumber = sys.argv[5]
  39. self.calledNumber = sys.argv[6]
  40. Majortel.post_call(self)
  41. elif (self.api_command == "post_majortel_ring"):
  42. ''' post_majortel_ring '''
  43. # ARGV 5: calledId. Id chiamato
  44. # ARGV 6: ringTime. Durata dello squillo (in millisecondi)
  45. # ARGV 7: calledNumber. Numero da chiamare
  46. self.calledId = sys.argv[5]
  47. self.ringTime = sys.argv[6]
  48. self.calledNumbers = []
  49. if self.debug: print(sys.argv)
  50. for count in range(7, len(sys.argv)):
  51. if self.debug: print(count)
  52. self.calledNumbers.append(sys.argv[count])
  53. if self.debug: print("numbers to call: ")
  54. if self.debug: print(self.calledNumbers)
  55. Majortel.post_ring(self)
  56. elif (self.api_command == "get_presense_settings"):
  57. ''' get_presense_settings '''
  58. return Utils.get_presense_settings()
  59. elif (self.api_command == "get_majortel_contacts"):
  60. ''' get_majortel_contacts '''
  61. # ARGV 5: username majornet
  62. # ARGV 6: password majornet
  63. # ARGV 7: nome rubrica nextcloud
  64. self.username = sys.argv[5]
  65. self.password = sys.argv[6]
  66. self.addressbookName = sys.argv[7]
  67. contacts = Majortel.get_contacts(self)
  68. return contacts
  69. elif (self.api_command == "get_majortel_contacts_microsip"):
  70. ''' get_majortel_contacts_microsip '''
  71. # ARGV 5: username majornet
  72. # ARGV 6: password majornet
  73. # ARGV 7: nome rubrica nextcloud
  74. self.username = sys.argv[5]
  75. self.password = sys.argv[6]
  76. self.addressbookName = sys.argv[7]
  77. contacts = Majortel.get_contacts_microsip(self)
  78. return contacts
  79. # MAIN
  80. ClientApi()