voipms-api 1.0.0b9__tar.gz

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,19 @@
1
+ Copyright (c) 2024 Jose Pineda joseanmont.info
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.1
2
+ Name: voipms-api
3
+ Version: 1.0.0b9
4
+ Summary: A python package to simplify the use of the VoIP.ms API
5
+ Author-email: Jose Pineda <hello@joseanmont.com>
6
+ Project-URL: Homepage, https://github.com/joseanmont/voipms-api
7
+ Project-URL: Issues, https://github.com/joseanmont/voipms-api/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.32.3
15
+
16
+ # voipms-api
17
+
18
+ This package is developed to streamline the process of integrating with the VoIP.ms API, allowing developers to focus on implementing functionality without the need to write boilerplate code for API connectivity and function calls. The VoIP.ms API Client encapsulates all necessary code to connect and interact with the VoIP.ms API, enabling developers to call functions directly.
19
+
20
+ ## Features
21
+
22
+ - **Simplified Integration**: Connect to the VoIP.ms API with minimal setup.
23
+ - **Modular Design**: Organized into separate modules for different functionalities, allowing targeted imports and reduced overhead.
24
+ - **Ongoing Development**: New functions will continue to be added.
25
+
26
+ ## Installation
27
+
28
+ Add the package to your project to be able to import its modules, classes and methods.
29
+
30
+ Check requirements.txt to see the packages that need to be installed.
31
+
32
+ **Note:** If you have problems importing the modules, add the path to the directory and subdirectories in PYTHONPATH.
33
+
34
+ ## Package structure
35
+
36
+ ```plaintext
37
+ voipms-api
38
+ ├── src/
39
+ │ └── voipms-api/
40
+ │ ├── __init__.py
41
+ │ ├── accounts.py
42
+ │ ├── call_hunting.py
43
+ │ ├── dids.py
44
+ │ ├── forwarding.py
45
+ │ ├── general.py
46
+ │ ├── ivr.py
47
+ │ ├── lnp.py
48
+ │ ├── ring_groups.py
49
+ │ ├── sms.py
50
+ │ ├── voicemail.py
51
+ │ └── voipms_client.py
52
+ │── tests/
53
+ │ └── test_voipms_client.py
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ The credentials can be loaded on your virtual enviroment by adding the following variables on an .env file:
59
+
60
+ ```.env
61
+ VOIPMS_API_USER = "Your VoIP.ms account email"
62
+ VOIPMS_API_PASSWORD = "Your VoIP.ms API password"
63
+ ```
64
+
65
+ However, you can also add your credentials or use different credentials by using the class VoipMsClient. Here is an example:
66
+
67
+ ```
68
+ from voipms_api import VoipMsClient
69
+ vms_client = VoipMsClient(username="me@email.com", password="your VoIP.ms API password")
70
+ ```
71
+
72
+ Or, you can do it when calling a single instance. For example:
73
+
74
+ ```
75
+ from voipms_api import General
76
+ balance = General(username="me@email.com", password="api_password")
77
+ print(balance.get_balance())
78
+ ```
79
+
80
+ ## Module Capabilities
81
+
82
+ Currently, the modules of accounts and voice features within the voipms-api package provide basic functionalities for creating, retrieving, and deleting items.
83
+
84
+ You will find the current available functions in the description of each class.
85
+
86
+ Additional functionalities will be added over time.
87
+
88
+ ## Examples of scripts
89
+
90
+ You can find more example scripts in the examples directory. These scripts demonstrate how to use the some features of the voipms-api package.
91
+
92
+ ## Contributing
93
+
94
+ Currently, we are not accepting collaborations. However, if you have suggestions or feedback, feel free to contact us. Issues can be reported on GitHub.
95
+
96
+ ## License
97
+
98
+ This package is free to use and can be included in any project. See the LICENSE file for more details.
99
+
100
+ ## Support
101
+
102
+ For any issues or questions, please raise an issue on GitHub or contact us directly at hello@joseanmont.info
103
+
104
+ ## Special Thanks
105
+
106
+ Kudos to the VoIP.ms development team. They have developed an understandable, simple but still powerful API that lets users take their VoIP system beyond limits.
@@ -0,0 +1,91 @@
1
+ # voipms-api
2
+
3
+ This package is developed to streamline the process of integrating with the VoIP.ms API, allowing developers to focus on implementing functionality without the need to write boilerplate code for API connectivity and function calls. The VoIP.ms API Client encapsulates all necessary code to connect and interact with the VoIP.ms API, enabling developers to call functions directly.
4
+
5
+ ## Features
6
+
7
+ - **Simplified Integration**: Connect to the VoIP.ms API with minimal setup.
8
+ - **Modular Design**: Organized into separate modules for different functionalities, allowing targeted imports and reduced overhead.
9
+ - **Ongoing Development**: New functions will continue to be added.
10
+
11
+ ## Installation
12
+
13
+ Add the package to your project to be able to import its modules, classes and methods.
14
+
15
+ Check requirements.txt to see the packages that need to be installed.
16
+
17
+ **Note:** If you have problems importing the modules, add the path to the directory and subdirectories in PYTHONPATH.
18
+
19
+ ## Package structure
20
+
21
+ ```plaintext
22
+ voipms-api
23
+ ├── src/
24
+ │ └── voipms-api/
25
+ │ ├── __init__.py
26
+ │ ├── accounts.py
27
+ │ ├── call_hunting.py
28
+ │ ├── dids.py
29
+ │ ├── forwarding.py
30
+ │ ├── general.py
31
+ │ ├── ivr.py
32
+ │ ├── lnp.py
33
+ │ ├── ring_groups.py
34
+ │ ├── sms.py
35
+ │ ├── voicemail.py
36
+ │ └── voipms_client.py
37
+ │── tests/
38
+ │ └── test_voipms_client.py
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ The credentials can be loaded on your virtual enviroment by adding the following variables on an .env file:
44
+
45
+ ```.env
46
+ VOIPMS_API_USER = "Your VoIP.ms account email"
47
+ VOIPMS_API_PASSWORD = "Your VoIP.ms API password"
48
+ ```
49
+
50
+ However, you can also add your credentials or use different credentials by using the class VoipMsClient. Here is an example:
51
+
52
+ ```
53
+ from voipms_api import VoipMsClient
54
+ vms_client = VoipMsClient(username="me@email.com", password="your VoIP.ms API password")
55
+ ```
56
+
57
+ Or, you can do it when calling a single instance. For example:
58
+
59
+ ```
60
+ from voipms_api import General
61
+ balance = General(username="me@email.com", password="api_password")
62
+ print(balance.get_balance())
63
+ ```
64
+
65
+ ## Module Capabilities
66
+
67
+ Currently, the modules of accounts and voice features within the voipms-api package provide basic functionalities for creating, retrieving, and deleting items.
68
+
69
+ You will find the current available functions in the description of each class.
70
+
71
+ Additional functionalities will be added over time.
72
+
73
+ ## Examples of scripts
74
+
75
+ You can find more example scripts in the examples directory. These scripts demonstrate how to use the some features of the voipms-api package.
76
+
77
+ ## Contributing
78
+
79
+ Currently, we are not accepting collaborations. However, if you have suggestions or feedback, feel free to contact us. Issues can be reported on GitHub.
80
+
81
+ ## License
82
+
83
+ This package is free to use and can be included in any project. See the LICENSE file for more details.
84
+
85
+ ## Support
86
+
87
+ For any issues or questions, please raise an issue on GitHub or contact us directly at hello@joseanmont.info
88
+
89
+ ## Special Thanks
90
+
91
+ Kudos to the VoIP.ms development team. They have developed an understandable, simple but still powerful API that lets users take their VoIP system beyond limits.
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=71.1.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "voipms-api"
7
+ version = "1.0.0b9"
8
+ authors = [{ name = "Jose Pineda", email = "hello@joseanmont.com" }]
9
+ description = "A python package to simplify the use of the VoIP.ms API"
10
+ readme = "README.md"
11
+ requires-python = ">=3.10"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ dependencies = ["requests>=2.32.3"]
18
+
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/joseanmont/voipms-api"
22
+ Issues = "https://github.com/joseanmont/voipms-api/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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()
@@ -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
+ ]
@@ -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