voipms-api 1.0.0b9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import unittest
2
+ from voipms_api import VoipMsClient
3
+
4
+ class TestVoIPmsClient(unittest.TestCase):
5
+
6
+ def test_connection(self):
7
+ """
8
+ Tests if the credentials and IP address are correct.
9
+ """
10
+ client = VoipMsClient()
11
+ result = client.test_connection()
12
+ self.assertEqual(result["status"], "success")
13
+
14
+
15
+ if __name__ == "__main__":
16
+
17
+ unittest.main()
voipms_api/__init__.py ADDED
@@ -0,0 +1,25 @@
1
+ from .accounts import Accounts
2
+ from .call_hunting import CallHunting
3
+ from .dids import DIDs
4
+ from .forwarding import Forwarding
5
+ from .general import General
6
+ from .ivr import IVR
7
+ from .lnp import LNP
8
+ from .ring_groups import RingGroups
9
+ from .sms import SMS
10
+ from .voicemail import Voicemail
11
+ from .voipms_client import VoipMsClient
12
+
13
+ __all__ = [
14
+ "Accounts",
15
+ "CallHunting",
16
+ "DIDs",
17
+ "Forwarding",
18
+ "General",
19
+ "IVR",
20
+ "LNP",
21
+ "RingGroups",
22
+ "SMS",
23
+ "Voicemail",
24
+ "VoipMsClient"
25
+ ]
voipms_api/accounts.py ADDED
@@ -0,0 +1,161 @@
1
+ import requests
2
+ from typing import Optional, Union
3
+
4
+
5
+ class Accounts():
6
+ '''
7
+ A class to call the Sub Accounts functions of the VoIP.ms API.
8
+
9
+ Methods:
10
+ create_subaccount:
11
+ Creates a Sub Account and returns the result of the request.
12
+ '''
13
+
14
+ def __init__(self, username=None, password=None) -> None:
15
+
16
+ from voipms_api import VoipMsClient
17
+
18
+ if (username and not password) or (password and not username):
19
+ raise ValueError("Both username and password must be provided together")
20
+ elif(username and password):
21
+ self.username = username
22
+ self.password = password
23
+ self.vms_client = VoipMsClient(self.username, self.password)
24
+ else:
25
+ self.vms_client = VoipMsClient()
26
+
27
+
28
+ def create_subaccount(self,
29
+ username:str,
30
+ password:str,
31
+ extension:Optional[Union[str, int]]=None,
32
+ protocol:Optional[Union[str, int]]=1,
33
+ auth_type:Optional[Union[str, int]]=1,
34
+ device_type:Optional[Union[str, int]]=2,
35
+ ) -> dict:
36
+ """
37
+ Calls the VoIP.ms createSubAccount function.
38
+
39
+ Args:
40
+ username (str, required): Username to set to the sub account (Example: 'VoIP').
41
+ password (str, required): Password to set for the authentication.
42
+ extension str or int, optional): Sub Account Internal Extension (Example: 1 -> Creates 101).
43
+ protocol (str or int, optional): The protocol the sub account will use. Default is '1' for SIP (value from get_Protocols).
44
+ auth_type (str or int, optional): The authentication type the sub account will use. Default is '1' for User/Password (value from get_auth_types).
45
+ device_type (str or int, optional): Device type that will be used. Default is '2' for ATA device, IP Phone or Softphone (value from get_device_types).
46
+
47
+ Returns:
48
+ dict: A dictionary containing the status of the request and the Sub Account that was created.
49
+ """
50
+
51
+ mtd = "createSubAccount"
52
+
53
+ try:
54
+ params = {
55
+
56
+ # Required by this package.
57
+ "username": username,
58
+ "password": password,
59
+
60
+ # Required by the VoIP.ms API but set with default values in this package.
61
+ "lock_international": 1,
62
+ "international_route": 1,
63
+ "music_on_hold": "default",
64
+ "allowed_codecs": "g722",
65
+ "dtmf_mode": "auto",
66
+ "nat": "yes",
67
+ }
68
+
69
+ # Optional parameters in this package.
70
+ if protocol:
71
+ params["protocol"] = protocol
72
+ if auth_type:
73
+ params["auth_type"] = auth_type
74
+ if device_type:
75
+ params["device_type"] = device_type
76
+ if extension:
77
+ params["internal_extension"] = extension
78
+
79
+ data = self.vms_client.make_request(mtd, params)
80
+ return data
81
+
82
+ except requests.exceptions.HTTPError as http_err:
83
+ print(f"HTTP error ocurred: {http_err}")
84
+ return None
85
+ except KeyError as key_err:
86
+ print(f"Key error: {key_err}")
87
+ return None
88
+ except Exception as err:
89
+ print(f'An error occurred: {err}')
90
+ return None
91
+
92
+
93
+ def delete_subaccount(self,
94
+ id:Union[str, int],
95
+ ) -> dict:
96
+ """
97
+ Calls the VoIP.ms delSubAccount function.
98
+
99
+ Args:
100
+ id (str or int, required): ID of the Sub Account that will be deleted(Example: '99785' or 99785). Value from get_subaccounts.
101
+
102
+ Returns:
103
+ dict: A dictionary containing the status of the request and the Sub Account that was canceled.
104
+ """
105
+
106
+ mtd = "delSubAccount"
107
+
108
+ try:
109
+ params = {
110
+ "id": id,
111
+ }
112
+
113
+ data = self.vms_client.make_request(mtd, params)
114
+ data["result"] = "Sub Account deleted"
115
+ data["id"] = id
116
+ return data
117
+
118
+ except requests.exceptions.HTTPError as http_err:
119
+ print(f"HTTP error ocurred: {http_err}")
120
+ return None
121
+ except KeyError as key_err:
122
+ print(f"Key error: {key_err}")
123
+ return None
124
+ except Exception as err:
125
+ print(f'An error occurred: {err}')
126
+ return None
127
+
128
+
129
+ def get_subaccounts(self,
130
+ subaccount:Optional[Union[str, int]]=None
131
+ ) -> dict:
132
+ """
133
+ Calls the VoIP.ms getSubAccounts function.
134
+
135
+ Args:
136
+ subaccount (str or int, optional): Sub Account ID or username (Example: '100000_SubAccount' or 99785).
137
+
138
+ Returns:
139
+ dict: A dictionary containing the status of the request and the Sub Accounts and their data, or a specific Sub Account data if an ID or username is provided.
140
+ """
141
+
142
+ mtd = "getSubAccounts"
143
+
144
+ try:
145
+ params = {}
146
+
147
+ if subaccount:
148
+ params["account"] = subaccount
149
+
150
+ data = self.vms_client.make_request(mtd, params)
151
+ return data
152
+
153
+ except requests.exceptions.HTTPError as http_err:
154
+ print(f"HTTP error ocurred: {http_err}")
155
+ return None
156
+ except KeyError as key_err:
157
+ print(f"Key error: {key_err}")
158
+ return None
159
+ except Exception as err:
160
+ print(f'An error occurred: {err}')
161
+ return None
@@ -0,0 +1,173 @@
1
+ import requests
2
+ from typing import Optional, Union
3
+
4
+ class CallHunting():
5
+ '''
6
+ A class to call the Call Hunting functions of the VoIP.ms API.
7
+
8
+ Methods:
9
+ create_call_hunting:
10
+ Creates a new Call Hunting and returns the result of the request.
11
+ delete_call_hunting:
12
+ Deletes a specific Call Hunting and returns the result of the request.
13
+ get_call_hunting:
14
+ Returns all the existing Call Huntings, or a specific Call Hunting if a Call Hunting ID is provided.
15
+ '''
16
+
17
+ def __init__(self, username=None, password=None) -> None:
18
+
19
+ from voipms_api import Accounts, VoipMsClient
20
+
21
+ if (username and not password) or (password and not username):
22
+ raise ValueError("Both username and password must be provided together")
23
+ elif(username and password):
24
+ self.username = username
25
+ self.password = password
26
+ self.vms_client = VoipMsClient(self.username, self.password)
27
+ else:
28
+ self.vms_client = VoipMsClient()
29
+
30
+ # Code to get the Account number to set the Main Account as the default member so it is not required.
31
+ accounts = Accounts()
32
+ get_accounts = accounts.get_subaccounts()
33
+ self.acc_number = get_accounts['accounts'][0]['account']
34
+ self.acc_number = self.acc_number[0:6]
35
+
36
+
37
+ def create_call_hunting(self,
38
+ name:str,
39
+ recording:Optional[Union[str, int]]=None,
40
+ language:Optional[str]=None,
41
+ order:Optional[str]=None,
42
+ members:Optional[str]=None,
43
+ ) -> dict:
44
+ """
45
+ Calls the VoIP.ms setCallHunting function to create a new Call Hunting.
46
+
47
+ Args:
48
+ name (str, required): A name for the new Call Hunting.
49
+ recording (str or int, optional): ID of the recording to set to the Call Hunting. Values from get_recordings.
50
+ language (str, optional): Language of the Call Hunting. Default is 'en' for English. Values from get_languages.
51
+ order (str, optional): Ring order of the Call Hunting. Default is 'follow' to follow member's order. Alternative is 'random'.
52
+ members (srt, optional): A string of members separated by semicolons. Default is Main Account as only member. (Example: 'account:100001;fwd:16006'). See VoIP.ms API documentation for more details.
53
+
54
+ Returns:
55
+ dict: A dictionary containing the status of the request and the name of the Call Hunting that was created.
56
+ """
57
+
58
+ mtd = "setCallHunting"
59
+ main_account = "account:" + self.acc_number
60
+
61
+ try:
62
+ params = {
63
+ # Required by this package
64
+ "description": name,
65
+
66
+ # Required by VoIP.ms API but set with default values so it is not required in this package.
67
+ "music": "default",
68
+ "recording": "default",
69
+ "language": "en",
70
+ "order": "follow",
71
+ "members": main_account,
72
+ "ring_time": 25,
73
+ "press": 0
74
+ }
75
+
76
+ # Optional in this package.
77
+ if recording:
78
+ params["recording"] = recording
79
+ if language:
80
+ params["language"] = language
81
+ if order:
82
+ params["order"] = order
83
+ if members:
84
+ params["members"] = members
85
+
86
+ data = self.vms_client.make_request(mtd, params)
87
+ data["name"] = name
88
+ return data
89
+
90
+ except requests.exceptions.HTTPError as http_err:
91
+ print(f"HTTP error ocurred: {http_err}")
92
+ return None
93
+ except KeyError as key_err:
94
+ print(f"Key error: {key_err}")
95
+ return None
96
+ except Exception as err:
97
+ print(f'An error occurred: {err}')
98
+ return None
99
+
100
+
101
+ def delete_call_hunting(self,
102
+ call_hunting:Union[str, int],
103
+ ) -> dict:
104
+ """
105
+ Calls the VoIP.ms delCallHunting function.
106
+
107
+ Args:
108
+ call_hunting (str or int, required): ID of the call hunting that will be deleted (Example: 18635). Value from get_call_huntings.
109
+
110
+ Returns:
111
+ dict: A dictionary containing the status of the request and the ID of the call hunting that was deleted.
112
+ """
113
+
114
+ mtd = "delCallHunting"
115
+
116
+ try:
117
+ params = {
118
+ "callhunting": call_hunting,
119
+ }
120
+
121
+ # Code to get the name of the call hunting that is deleted.
122
+ ch_info = self.get_call_huntings(call_hunting)
123
+ ch_name = ch_info["call_hunting"][0]["description"]
124
+
125
+ data = self.vms_client.make_request(mtd, params)
126
+ data["call_hunting"] = ch_name
127
+ return data
128
+
129
+ except requests.exceptions.HTTPError as http_err:
130
+ print(f"HTTP error ocurred: {http_err}")
131
+ return None
132
+ except KeyError as key_err:
133
+ print(f"Key error: {key_err}")
134
+ return None
135
+ except Exception as err:
136
+ print(f'An error occurred: {err}')
137
+ return None
138
+
139
+
140
+ def get_call_huntings(self,
141
+ call_hunting:Optional[Union[str, int]]=None,
142
+ ) -> dict:
143
+ """
144
+ Calls the VoIP.ms getCallHuntings function.
145
+
146
+ Args:
147
+ call_hunting (str or int, optional): ID of a specific call hunting (Example: 323).
148
+
149
+ Returns:
150
+ dict: A dictionary containing the status of the request and the data of all the call huntings, or the data of a specific call hunting if an ID is provided.
151
+ """
152
+
153
+ mtd = "getCallHuntings"
154
+
155
+ try:
156
+ params = {}
157
+
158
+ # Optional in this package.
159
+ if call_hunting:
160
+ params["callhunting"] = call_hunting
161
+
162
+ data = self.vms_client.make_request(mtd, params)
163
+ return data
164
+
165
+ except requests.exceptions.HTTPError as http_err:
166
+ print(f"HTTP error ocurred: {http_err}")
167
+ return None
168
+ except KeyError as key_err:
169
+ print(f"Key error: {key_err}")
170
+ return None
171
+ except Exception as err:
172
+ print(f'An error occurred: {err}')
173
+ return None
voipms_api/dids.py ADDED
@@ -0,0 +1,222 @@
1
+ '''
2
+ VoIP.ms DIDs functions
3
+ '''
4
+
5
+ import requests
6
+ from typing import Optional, Union
7
+
8
+
9
+ class DIDs():
10
+ '''
11
+ A class to call the DID functions of the VoIP.ms API.
12
+
13
+ Methods:
14
+ cancel_did:
15
+ Cancels a specific DID number and returns the result of the request.
16
+ get_dids_info:
17
+ Returns the current balance of the VoIP.ms account.
18
+ '''
19
+
20
+ def __init__(self, username=None, password=None) -> None:
21
+
22
+ from voipms_api import VoipMsClient
23
+
24
+ if (username and not password) or (password and not username):
25
+ raise ValueError("Both username and password must be provided together")
26
+ elif(username and password):
27
+ self.username = username
28
+ self.password = password
29
+ self.vms_client = VoipMsClient(self.username, self.password)
30
+ else:
31
+ self.vms_client = VoipMsClient()
32
+
33
+
34
+ def cancel_did(self,
35
+ did:Union[str, int],
36
+ comment:Optional[str]=None,
37
+ port_out:Optional[Union[str, bool]]=None,
38
+ test:Optional[Union[str, bool]]=None
39
+ ) -> dict:
40
+ """
41
+ Calls the VoIP.ms cancelDID function.
42
+
43
+ Args:
44
+ did (str or int, required): Specific DID number to be canceled (Example: 5551234567).
45
+ comment (str, optional): Comment for DID cancellation.
46
+ port out (str or bool, optional): Set True if the DID was ported out.
47
+ test (str or bool, optional): Set True if testing the DID cancelation function.
48
+
49
+ Returns:
50
+ dict: A dictionary containing the status of the request and the DID that was canceled.
51
+ """
52
+
53
+ mtd = "cancelDID"
54
+
55
+ try:
56
+ params = {
57
+ "did": did,
58
+ }
59
+
60
+ if comment:
61
+ params["comment"] = comment
62
+ if port_out:
63
+ params["portout"] = port_out
64
+ if test:
65
+ params["test"] = test
66
+
67
+ data = self.vms_client.make_request(mtd, params)
68
+ data["result"] = "DID canceled"
69
+ data["did"] = did
70
+ return data
71
+
72
+ except requests.exceptions.HTTPError as http_err:
73
+ print(f"HTTP error ocurred: {http_err}")
74
+ return None
75
+ except KeyError as key_err:
76
+ print(f"Key error: {key_err}")
77
+ return None
78
+ except Exception as err:
79
+ print(f'An error occurred: {err}')
80
+ return None
81
+
82
+
83
+ def get_dids_info(self,
84
+ client:Optional[Union[str, int]]=None,
85
+ did:Optional[Union[str, int]]=None
86
+ ) -> dict:
87
+ """
88
+ Calls the VoIP.ms getDIDsInfo function.
89
+
90
+ Args:
91
+ client (str or int, optional): ID of a specific Reseller client or Sub Account (Example: 123456 or 100000_Account).
92
+ did (str or int, optional): Specific DID number or Sub Account (Example: 5551234567).
93
+
94
+ Returns:
95
+ dict: If no parameter is provided, a dictionary containing the status and information from all the DIDs.
96
+ If a client ID is provided, a dictionary containing the status and information from the client's DIDs.
97
+ If a Sub Account is provided, a dictionary containing the status and information of the Sub Account's DID.
98
+ If a DID is provided, a dictionary containing the status and information of the specific DID.
99
+ """
100
+
101
+ mtd = "getDIDsInfo"
102
+
103
+ try:
104
+ params = {}
105
+
106
+ if client:
107
+ params["client"] = client
108
+ if did:
109
+ params["did"] = did
110
+
111
+ data = self.vms_client.make_request(mtd, params)
112
+ return data
113
+
114
+ except requests.exceptions.HTTPError as http_err:
115
+ print(f"HTTP error ocurred: {http_err}")
116
+ return None
117
+ except KeyError as key_err:
118
+ print(f"Key error: {key_err}")
119
+ return None
120
+ except Exception as err:
121
+ print(f'An error occurred: {err}')
122
+ return None
123
+
124
+
125
+ def order_did(self,
126
+ did: Union[str, int],
127
+ routing: Optional[str]="sys:hangup",
128
+ pop:Optional[Union[str, int]]=22,
129
+ dial_time:Optional[Union[str, int]]=60,
130
+ cnam:Optional[Union[str, int]]=0,
131
+ billing_type: Optional[Union[str, int]]=1
132
+ )-> dict:
133
+ """
134
+ Calls the VoIP.ms orderDID function.
135
+
136
+ Args:
137
+ did (str or int, required): Specific DID number to be ordered (Example: 5551234567).
138
+ routing (str, optional): Routing of the DID. Default is sys:hangup.
139
+ pop (str or int, optional): POP server of the DID. Default is 22 (sanjose1.voip.ms). Data from get_severs.
140
+ dial time (str or int, optional): Ring time of the DID. Default is 60 (seconds).
141
+ cnam: (str or int, optional): Activates CNAM lookup. Default is 0 (disabled). Set 1 for enable.
142
+ billing type (str or int, optional): Sets the Billing plan. Default is 1 (Per Minute). Set 2 for Flat Rate.
143
+
144
+ Returns:
145
+ dict: A dictionary containing the status of the request and the DID that was ordered.
146
+ """
147
+
148
+ mtd = "orderDID"
149
+
150
+ try:
151
+ params = {
152
+ "did": did,
153
+ "routing": routing,
154
+ "pop": pop,
155
+ "dialtime": dial_time,
156
+ "cnam": cnam,
157
+ "billing_type": billing_type,
158
+ }
159
+
160
+ data = self.vms_client.make_request(mtd, params)
161
+ data["result"] = "DID ordered"
162
+ data["did"] = did
163
+ return data
164
+
165
+ except requests.exceptions.HTTPError as http_err:
166
+ print(f"HTTP error ocurred: {http_err}")
167
+ return None
168
+ except KeyError as key_err:
169
+ print(f"Key error: {key_err}")
170
+ return None
171
+ except Exception as err:
172
+ print(f'An error occurred: {err}')
173
+ return None
174
+
175
+
176
+ def order_toll_free(self,
177
+ did: Union[str, int],
178
+ routing: Optional[str]="sys:hangup",
179
+ pop:Optional[Union[str, int]]=22,
180
+ dial_time:Optional[Union[str, int]]=60,
181
+ cnam:Optional[Union[str, int]]=0
182
+ )-> dict:
183
+ """
184
+ Calls the VoIP.ms orderTollFree function.
185
+
186
+ Args:
187
+ did (str or int, required): Specific Toll-free DID number to be ordered (Example: 8771234567).
188
+ routing (str, optional): Routing of the DID. Default is sys:hangup.
189
+ pop (str or int, optional): POP server of the DID. Default is 22 (sanjose1.voip.ms). Data from get_severs.
190
+ dial time (str or int, optional): Ring time of the DID. Default is 60 (seconds).
191
+ cnam: (str or int, optional): Activates CNAM lookup. Default is 0 (disabled). Set 1 for enable.
192
+ billing type (str or int, optional): Sets the Billing plan. Default is 1 (Per Minute). Set 2 for Flat Rate.
193
+
194
+ Returns:
195
+ dict: A dictionary containing the status of the request and the DID that was ordered.
196
+ """
197
+
198
+ mtd = "orderTollFree"
199
+
200
+ try:
201
+ params = {
202
+ "did": did,
203
+ "routing": routing,
204
+ "pop": pop,
205
+ "dialtime": dial_time,
206
+ "cnam": cnam
207
+ }
208
+
209
+ data = self.vms_client.make_request(mtd, params)
210
+ data["result"] = "DID ordered"
211
+ data["did"] = did
212
+ return data
213
+
214
+ except requests.exceptions.HTTPError as http_err:
215
+ print(f"HTTP error ocurred: {http_err}")
216
+ return None
217
+ except KeyError as key_err:
218
+ print(f"Key error: {key_err}")
219
+ return None
220
+ except Exception as err:
221
+ print(f'An error occurred: {err}')
222
+ return None