def create(opt, conf, username, first_name=None, last_name=None): """ Добавляем пользователя fs-api -c account -a create -u <username> -e <email> [-p <password> --enabled=<1|0> -t <tariff_id>] [first_name last_name] # новый аккаунт """ url = "{2}://{0}{1}".format( conf.get(opt.section, "host"), conf.get(opt.section, "pref"), conf.get(opt.section, "protocol") ) if opt.email == "no": print( "fs-api -c account -a create -u <username> -e <email> [-p <password> --enabled=<1|0> -t <tariff_id>] [first_name last_name]" ) else: if int(opt.enabled) == 1: enabled = "true" else: enabled = "false" args = {"username": username, "email": opt.email, "enabled": enabled} if first_name is not None: args["first_name"] = first_name if last_name is not None: args["last_name"] = last_name if opt.password != "no": args["password"] = opt.password # print(args) con = Connection( url, username=conf.get(opt.section, "user"), password=conf.get(opt.section, "passwd"), path_cache=PATH_CACHE ) res = con.save("post", "/account/", args) if res: view(res) else: print("No create account: {0}; status: {1}".format(username, con.status))
def create(opt, conf, username, phone="no"): """ Добавляем новый номер телефона fs-api -c endpoint -a create -u <username> --phone=<phone> [-p <password> --enabled=<1|0>] [-s site] """ url = "{2}://{0}{1}".format(conf.get(opt.section, 'host'),conf.get(opt.section, 'pref'),conf.get(opt.section, 'protocol')) #TODO: если неуказан номер то берет первый из списка if phone == 'no': print('fs-api -c endpoint -a create -u <username> --phone=<phone> [-p <password> --enabled=<1|0>] [-s site]') else: if int(opt.enabled) == 1: enabled = 'true' else: enabled = 'false' args={'username': username, 'phone': phone, 'enabled': enabled} #if first_name is not None: # args['first_name'] = first_name #if last_name is not None: # args['last_name'] = last_name if opt.password != 'no': args['password'] = opt.password #print(args) con = Connection(url, username=conf.get(opt.section, 'user'), password=conf.get(opt.section, 'passwd'), path_cache=PATH_CACHE) res = con.save("post", '/endpoint/', args) if res: view(res) else: print('No create endpoint: {0}; status: {1}'.format(opt.phone,con.status))
def update(opt, conf, arg): """ обновление параметров телефонного номера fs-api -c endpoint -a update --phone <phone> <key> <val> Пример: fs-api -c endpoint -a update --phone 380895000000 effective_caller_id_name Neskaju """ url = "{2}://{0}{1}".format(conf.get(opt.section, 'host'),conf.get(opt.section, 'pref'),conf.get(opt.section, 'protocol')) con = Connection(url, username=conf.get(opt.section, 'user'), password=conf.get(opt.section, 'passwd'), path_cache=PATH_CACHE) res = con.save('put', '/endpoint/phone/{0}/'.format(opt.phone), arg) if res: view(res) else: print('No update endpoint: {0}; status: {1}'.format(opt.phone,con.status))
def update(opt, conf, username, arg): """ обновление аккаунта fs-api -c account -a update -u <username> <key> <val> Пример: fs-api -c account -a update -u testuser first_name Neskaju """ url = "{2}://{0}{1}".format( conf.get(opt.section, "host"), conf.get(opt.section, "pref"), conf.get(opt.section, "protocol") ) con = Connection( url, username=conf.get(opt.section, "user"), password=conf.get(opt.section, "passwd"), path_cache=PATH_CACHE ) res = con.save("put", "/account/{0}/".format(username), arg)