-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathapi.py
More file actions
84 lines (70 loc) · 2.33 KB
/
Copy pathapi.py
File metadata and controls
84 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from smsapi.account.models import AccountBalanceResult, UserResult
from smsapi.api import Api
from smsapi.endpoint import bind_api_endpoint
from smsapi.exception import EndpointException
from smsapi.models import ResultCollection
from smsapi.sms import response_format_param
from smsapi.utils import update_dict
accept_parameters = [
'name',
'password',
'api_password',
'limit',
'month_limit',
'senders',
'phonebook',
'active',
'info',
'without_prefix'
]
def parameters_transformer(mapping):
def _parameters_transformer(_, parameters):
for k, v in mapping.items():
parameters[v] = parameters.pop(k)
parameters['pass'] = parameters.pop('password', None)
parameters['pass_api'] = parameters.pop('api_password', None)
return parameters
return _parameters_transformer
class Account(Api):
path = 'user.do'
balance = bind_api_endpoint(
method='GET',
path=path,
mapping=AccountBalanceResult,
force_parameters=update_dict(response_format_param, {'credits': 1, 'details': 1}),
exception_class=EndpointException
)
user = bind_api_endpoint(
method='GET',
path=path,
mapping=UserResult,
accept_parameters=['without_prefix', 'name'],
force_parameters=response_format_param,
exception_class=EndpointException,
parameters_transformer=parameters_transformer({'name': 'get_user'})
)
create_user = bind_api_endpoint(
method='POST',
path=path,
mapping=UserResult,
accept_parameters=accept_parameters,
force_parameters=response_format_param,
exception_class=EndpointException,
parameters_transformer=parameters_transformer({'name': 'add_user'})
)
update_user = bind_api_endpoint(
method='PUT',
path=path,
mapping=UserResult,
accept_parameters=accept_parameters,
force_parameters=response_format_param,
exception_class=EndpointException,
parameters_transformer=parameters_transformer({'name': 'set_user'})
)
list_users = bind_api_endpoint(
method='GET',
path=path,
mapping=(UserResult, ResultCollection),
force_parameters=update_dict(response_format_param, {'list': 1}),
exception_class=EndpointException
)