added countries endpoint, added code generation tool for adding endpoints
This commit is contained in:
parent
297a67f57e
commit
25e0635db8
3
templates/dir_init.j2
Normal file
3
templates/dir_init.j2
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@property
|
||||||
|
def {{method_name}}(self):
|
||||||
|
return self.general.{{method_name}}
|
7
templates/endpoint.j2
Normal file
7
templates/endpoint.j2
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class {{class_name}}():
|
||||||
|
def __init__(self, base):
|
||||||
|
self.method = "{{endpoint}}"
|
||||||
|
self.base = base
|
||||||
|
|
||||||
|
def fetch(self, params={}):
|
||||||
|
return self.base.request(self.method)
|
1
templates/import.j2
Normal file
1
templates/import.j2
Normal file
@ -0,0 +1 @@
|
|||||||
|
from voipms.api.{{category_name}}.{{method_name}} import {{class_name}}
|
1
templates/initialize.j2
Normal file
1
templates/initialize.j2
Normal file
@ -0,0 +1 @@
|
|||||||
|
self._{{method_name}} = None
|
68
templates/method_generator.py
Normal file
68
templates/method_generator.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
file_loader = FileSystemLoader('.')
|
||||||
|
env = Environment(loader=file_loader)
|
||||||
|
|
||||||
|
print("Which category does this endpoint fall under?")
|
||||||
|
subdir_index = int(input("1: accounts, 2: call_detail_records, 3: dids, 4: general, 5: voicemail: "))
|
||||||
|
subdir = ("accounts", "call_detail_records", "dids", "general", "voicemail")[subdir_index - 1]
|
||||||
|
|
||||||
|
endpoint = "getCountries"
|
||||||
|
method = "countries"
|
||||||
|
|
||||||
|
filename = "../voipms/api/{}/{}.py".format(subdir, method)
|
||||||
|
|
||||||
|
template = env.get_template('endpoint.j2')
|
||||||
|
method_split = method.split('_')
|
||||||
|
class_name = ''.join((i.title() for i in method_split))
|
||||||
|
output = template.render(endpoint=endpoint, class_name=class_name)
|
||||||
|
|
||||||
|
with open(filename, 'a') as file:
|
||||||
|
file.writelines(output)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
filename = "../voipms/api/{}/__init__.py".format(subdir)
|
||||||
|
template = env.get_template('import.j2')
|
||||||
|
method_split = method.split('_')
|
||||||
|
class_name = ''.join((i.title() for i in method_split))
|
||||||
|
output_import = template.render(method_name=method, class_name=class_name, category_name=subdir)
|
||||||
|
|
||||||
|
template = env.get_template('initialize.j2')
|
||||||
|
output_init = template.render(method_name=method)
|
||||||
|
|
||||||
|
template = env.get_template('subdir_init.j2')
|
||||||
|
output_property = template.render(method_name=method, class_name=class_name)
|
||||||
|
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
contents = file.readlines()
|
||||||
|
|
||||||
|
pos = 0
|
||||||
|
|
||||||
|
for k, v in enumerate(contents):
|
||||||
|
if v == "\n":
|
||||||
|
contents.insert(k, output_import + "\n")
|
||||||
|
pos = k
|
||||||
|
break
|
||||||
|
|
||||||
|
print(pos)
|
||||||
|
|
||||||
|
for k, v in enumerate(contents[pos+2:], pos+2):
|
||||||
|
if v == "\n":
|
||||||
|
contents.insert(k, output_init + "\n")
|
||||||
|
break
|
||||||
|
|
||||||
|
contents.append("\n\n" + output_property)
|
||||||
|
|
||||||
|
with open(filename, 'w') as file:
|
||||||
|
file.writelines(contents)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
filename = "../voipms/api/__init__.py"
|
||||||
|
|
||||||
|
template = env.get_template('dir_init.j2')
|
||||||
|
output = template.render(method_name=method)
|
||||||
|
|
||||||
|
with open(filename, 'a') as file:
|
||||||
|
file.writelines("\n\n" + output)
|
5
templates/subdir_init.j2
Normal file
5
templates/subdir_init.j2
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
@property
|
||||||
|
def {{method_name}}(self):
|
||||||
|
if self._{{method_name}} is None:
|
||||||
|
self._{{method_name}} = {{class_name}}(self.base)
|
||||||
|
return self._{{method_name}}
|
@ -83,3 +83,11 @@ class Client(object):
|
|||||||
@property
|
@property
|
||||||
def ip(self):
|
def ip(self):
|
||||||
return self.general.ip
|
return self.general.ip
|
||||||
|
|
||||||
|
@property
|
||||||
|
def transaction_history(self):
|
||||||
|
return self.general.transaction_history
|
||||||
|
|
||||||
|
@property
|
||||||
|
def countries(self):
|
||||||
|
return self.general.countries
|
@ -1,10 +1,14 @@
|
|||||||
from voipms.api.general.balance import Balance
|
from voipms.api.general.balance import Balance
|
||||||
from voipms.api.general.ip import IP
|
from voipms.api.general.ip import IP
|
||||||
|
from voipms.api.general.transaction_history import TransactionHistory
|
||||||
|
from voipms.api.general.countries import Countries
|
||||||
|
|
||||||
class General():
|
class General():
|
||||||
def __init__(self, base):
|
def __init__(self, base):
|
||||||
self._balance = None
|
self._balance = None
|
||||||
self._ip = None
|
self._ip = None
|
||||||
|
self._transaction_history = None
|
||||||
|
self._countries = None
|
||||||
|
|
||||||
self.base = base
|
self.base = base
|
||||||
|
|
||||||
@ -19,3 +23,15 @@ class General():
|
|||||||
if self._ip is None:
|
if self._ip is None:
|
||||||
self._ip = IP(self.base)
|
self._ip = IP(self.base)
|
||||||
return self._ip
|
return self._ip
|
||||||
|
|
||||||
|
@property
|
||||||
|
def transaction_history(self):
|
||||||
|
if self._transaction_history is None:
|
||||||
|
self._transaction_history = TransactionHistory(self.base)
|
||||||
|
return self._transaction_history
|
||||||
|
|
||||||
|
@property
|
||||||
|
def countries(self):
|
||||||
|
if self._countries is None:
|
||||||
|
self._countries = Countries(self.base)
|
||||||
|
return self._countries
|
7
voipms/api/general/countries.py
Normal file
7
voipms/api/general/countries.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class Countries():
|
||||||
|
def __init__(self, base):
|
||||||
|
self.method = "getCountries"
|
||||||
|
self.base = base
|
||||||
|
|
||||||
|
def fetch(self, params={}):
|
||||||
|
return self.base.request(self.method)
|
7
voipms/api/general/transaction_history.py
Normal file
7
voipms/api/general/transaction_history.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class TransactionHistory():
|
||||||
|
def __init__(self, base):
|
||||||
|
self.method = "getTransactionHistory"
|
||||||
|
self.base = base
|
||||||
|
|
||||||
|
def fetch(self, params={}):
|
||||||
|
return self.base.request(self.method)
|
Loading…
Reference in New Issue
Block a user