import json import requests import sys from authorization import Authorization from majortel import Majortel from utils import Utils import os import ipaddress # \\\ CLIENT API /// # # Esempio chiamata: # >> python client_api.py args # Input data: # ARGV 1: Host server API # ARGV 2: Username # ARGV 3: Password # ARGV 4: comando (es. 'call'). Comando che identifica univocamente una API. # ARGV *: vedi documentazione singolo comando. # Politica nomenclatura comandi: # {http_method} _ {modulo} _ {nome_api} # # es: # get_presense_settings class ClientApi: def __init__(self, host_server = sys.argv[1], username = sys.argv[2], password = sys.argv[3], api_command = sys.argv[4], debug=False): print("Api command: "+api_command) self.debug = debug self.api_command = api_command self.api_url_base = Utils.generate_url_base(host_server) self.token_data = Authorization.get_token(self, {"username": username, "password": password}) self.headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(self.token_data['access_token'])} self.check_command() def check_command(self): if (self.api_command == "post_majortel_call"): ''' post_majortel_call ''' # ARGV 5: callerNumber. Numero chiamante # ARGV 6: calledNumber. Numero chiamato self.callerNumber = sys.argv[5] self.calledNumber = sys.argv[6] Majortel.post_call(self) elif (self.api_command == "post_majortel_ring"): ''' post_majortel_ring ''' # ARGV 5: calledId. Id chiamato # ARGV 6: ringTime. Durata dello squillo (in millisecondi) # ARGV 7: calledNumber. Numero da chiamare self.calledId = sys.argv[5] self.ringTime = sys.argv[6] self.calledNumbers = [] if self.debug: print(sys.argv) for count in range(7, len(sys.argv)): if self.debug: print(count) self.calledNumbers.append(sys.argv[count]) if self.debug: print("numbers to call: ") if self.debug: print(self.calledNumbers) Majortel.post_ring(self) elif (self.api_command == "get_presense_settings"): ''' get_presense_settings ''' return Utils.get_presense_settings() elif (self.api_command == "get_majortel_contacts"): ''' get_majortel_contacts ''' # ARGV 5: username majornet # ARGV 6: password majornet # ARGV 7: nome rubrica nextcloud self.username = sys.argv[5] self.password = sys.argv[6] self.addressbookName = sys.argv[7] contacts = Majortel.get_contacts(self) return contacts elif (self.api_command == "get_majortel_contacts_microsip"): ''' get_majortel_contacts_microsip ''' # ARGV 5: username majornet # ARGV 6: password majornet # ARGV 7: nome rubrica nextcloud self.username = sys.argv[5] self.password = sys.argv[6] self.addressbookName = sys.argv[7] contacts = Majortel.get_contacts_microsip(self) return contacts # MAIN ClientApi()