Skip to content

Commit 8720d6e

Browse files
committed
Refactor WHMCS API client models to use Pydantic for data validation and serialization
- Removed the WHMCSBaseRequest class and its associated methods. - Updated WHMCSBaseResponse, WHMCSErrorResponse, and WHMCSSuccessResponse classes to inherit from Pydantic's BaseModel. - Implemented field validation using Pydantic's field validators. - Simplified the to_dict and from_dict methods using Pydantic's built-in functionality. - Enhanced error handling in the REST client and improved request methods. - Added type hints and improved code readability throughout the client. - Removed deprecated imports and unnecessary code. - Added a py.typed file for type hinting support.
1 parent 86c249f commit 8720d6e

68 files changed

Lines changed: 5457 additions & 9511 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ coverage.xml
4545
*,cover
4646
.hypothesis/
4747
venv/
48+
.venv/
4849
.python-version
50+
.pytest_cache
4951

5052
# Translations
5153
*.mo

.gitlab-ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# NOTE: This file is auto generated by OpenAPI Generator.
2+
# URL: https://openapi-generator.tech
3+
#
4+
# ref: https://docs.gitlab.com/ee/ci/README.html
5+
# ref: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
6+
7+
stages:
8+
- test
9+
10+
.pytest:
11+
stage: test
12+
script:
13+
- pip install -r requirements.txt
14+
- pip install -r test-requirements.txt
15+
- pytest --cov=whmcs_client
16+
17+
pytest-3.9:
18+
extends: .pytest
19+
image: python:3.9-alpine
20+
pytest-3.10:
21+
extends: .pytest
22+
image: python:3.10-alpine
23+
pytest-3.11:
24+
extends: .pytest
25+
image: python:3.11-alpine
26+
pytest-3.12:
27+
extends: .pytest
28+
image: python:3.12-alpine
29+
pytest-3.13:
30+
extends: .pytest
31+
image: python:3.13-alpine
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Swagger Codegen Ignore
2-
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
33

44
# Use this file to prevent files from being overwritten by the generator.
55
# The patterns follow closely to .gitignore or .dockerignore.
66

77
# As an example, the C# client generator defines ApiClient.cs.
8-
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
99
#ApiClient.cs
1010

1111
# You can match any string of characters against a directory, file or extension with a single asterisk (*):

.openapi-generator/FILES

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.github/workflows/python.yml
2+
.gitignore
3+
.gitlab-ci.yml
4+
.travis.yml
5+
README.md
6+
docs/AddClientResponse.md
7+
docs/AddOrderResponse.md
8+
docs/DefaultApi.md
9+
docs/UpdateClientResponse.md
10+
docs/WHMCSBaseResponse.md
11+
docs/WHMCSErrorResponse.md
12+
docs/WHMCSSuccessResponse.md
13+
git_push.sh
14+
pyproject.toml
15+
requirements.txt
16+
setup.cfg
17+
setup.py
18+
test-requirements.txt
19+
test/__init__.py
20+
tox.ini
21+
whmcs_client/__init__.py
22+
whmcs_client/api/__init__.py
23+
whmcs_client/api/default_api.py
24+
whmcs_client/api_client.py
25+
whmcs_client/api_response.py
26+
whmcs_client/configuration.py
27+
whmcs_client/exceptions.py
28+
whmcs_client/models/__init__.py
29+
whmcs_client/models/add_client_response.py
30+
whmcs_client/models/add_order_response.py
31+
whmcs_client/models/update_client_response.py
32+
whmcs_client/models/whmcs_base_response.py
33+
whmcs_client/models/whmcs_error_response.py
34+
whmcs_client/models/whmcs_success_response.py
35+
whmcs_client/py.typed
36+
whmcs_client/rest.py

.openapi-generator/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.13.0

.swagger-codegen/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# ref: https://docs.travis-ci.com/user/languages/python
22
language: python
33
python:
4-
- "3.2"
5-
- "3.3"
6-
- "3.4"
7-
- "3.5"
8-
#- "3.5-dev" # 3.5 development branch
9-
#- "nightly" # points to the latest development branch e.g. 3.6-dev
4+
- "3.9"
5+
- "3.10"
6+
- "3.11"
7+
- "3.12"
8+
- "3.13"
9+
# uncomment the following if needed
10+
#- "3.13-dev" # 3.13 development branch
11+
#- "nightly" # nightly build
1012
# command to install dependencies
11-
install: "pip install -r requirements.txt"
13+
install:
14+
- "pip install -r requirements.txt"
15+
- "pip install -r test-requirements.txt"
1216
# command to run tests
13-
script: nosetests
17+
script: pytest --cov=whmcs_client

README.md

Lines changed: 75 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
# whmcs-api-client
2-
Python client for the WHMCS API. WHMCS (Web Host Manager Complete Solution) provides a single API endpoint that handles multiple operations through different 'action' parameters. This specification presents each action as an independent path while routing all requests to the /api.php endpoint.
2+
Python client for the WHMCS API.
33

4-
This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
4+
WHMCS (Web Host Manager Complete Solution) provides a single API endpoint that handles
5+
multiple operations through different 'action' parameters. This specification presents
6+
each action as an independent path while routing all requests to the /api.php endpoint.
7+
8+
9+
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
510

611
- API version: 1.0.0
7-
- Package version: 1.0.4
8-
- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen
12+
- Package version: 1.0.5
13+
- Generator version: 7.13.0
14+
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
915

1016
## Requirements.
1117

12-
Python 2.7 and 3.4+
18+
Python 3.9+
1319

1420
## Installation & Usage
1521
### pip install
1622

17-
If the python package is hosted on Github, you can install directly from Github
23+
If the python package is hosted on a repository, you can install directly using:
1824

1925
```sh
2026
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
@@ -23,7 +29,7 @@ pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
2329

2430
Then import the package:
2531
```python
26-
import whmcs_client
32+
import whmcs_client
2733
```
2834

2935
### Setuptools
@@ -40,46 +46,71 @@ Then import the package:
4046
import whmcs_client
4147
```
4248

49+
### Tests
50+
51+
Execute `pytest` to run the tests.
52+
4353
## Getting Started
4454

4555
Please follow the [installation procedure](#installation--usage) and then run the following:
4656

4757
```python
48-
from __future__ import print_function
49-
import time
58+
5059
import whmcs_client
5160
from whmcs_client.rest import ApiException
5261
from pprint import pprint
5362

54-
# create an instance of the API class
55-
api_instance = whmcs_client.DefaultApi(whmcs_client.ApiClient(configuration))
56-
57-
try:
58-
# Add a new client
59-
api_response = api_instance.add_client()
60-
pprint(api_response)
61-
except ApiException as e:
62-
print("Exception when calling DefaultApi->add_client: %s\n" % e)
63-
64-
# create an instance of the API class
65-
api_instance = whmcs_client.DefaultApi(whmcs_client.ApiClient(configuration))
66-
67-
try:
68-
# Create a new order
69-
api_response = api_instance.add_order()
70-
pprint(api_response)
71-
except ApiException as e:
72-
print("Exception when calling DefaultApi->add_order: %s\n" % e)
73-
74-
# create an instance of the API class
75-
api_instance = whmcs_client.DefaultApi(whmcs_client.ApiClient(configuration))
76-
77-
try:
78-
# Update client details
79-
api_response = api_instance.update_client()
80-
pprint(api_response)
81-
except ApiException as e:
82-
print("Exception when calling DefaultApi->update_client: %s\n" % e)
63+
# Defining the host is optional and defaults to https://your-whmcs-instance.com/includes
64+
# See configuration.py for a list of all supported configuration parameters.
65+
configuration = whmcs_client.Configuration(
66+
host = "https://your-whmcs-instance.com/includes"
67+
)
68+
69+
70+
71+
# Enter a context with an instance of the API client
72+
with whmcs_client.ApiClient(configuration) as api_client:
73+
# Create an instance of the API class
74+
api_instance = whmcs_client.DefaultApi(api_client)
75+
username = 'username_example' # str | Admin username/API identifier
76+
password = 'password_example' # str | Admin password/API secret
77+
action = AddClient # str | Must be 'AddClient' (default to AddClient)
78+
firstname = 'firstname_example' # str | First name of the client
79+
lastname = 'lastname_example' # str | Last name of the client
80+
email = 'email_example' # str | Email address of the client
81+
address1 = 'address1_example' # str | Address line 1
82+
city = 'city_example' # str | City
83+
state = 'state_example' # str | State
84+
postcode = 'postcode_example' # str | Postal code
85+
country = 'country_example' # str | 2 character ISO country code
86+
phonenumber = 'phonenumber_example' # str | Phone number
87+
accesskey = 'accesskey_example' # str | Optional API access key (optional)
88+
responsetype = json # str | Response format (optional) (default to json)
89+
owner_user_id = 56 # int | The ID of the user that should own the client (optional)
90+
companyname = 'companyname_example' # str | Company name (optional)
91+
address2 = 'address2_example' # str | Address line 2 (optional)
92+
tax_id = 'tax_id_example' # str | Client's tax ID (optional)
93+
password2 = 'password2_example' # str | Password for the new user account (optional)
94+
securityqid = 56 # int | Security question ID (optional)
95+
securityqans = 'securityqans_example' # str | Security question answer (optional)
96+
currency = 56 # int | Currency ID (optional)
97+
groupid = 56 # int | Client group ID (optional)
98+
customfields = 'customfields_example' # str | Base64 encoded serialized array of custom field values (optional)
99+
language = 'language_example' # str | Default language setting (optional)
100+
clientip = 'clientip_example' # str | Originating IP address (optional)
101+
notes = 'notes_example' # str | Admin only notes (optional)
102+
marketingoptin = True # bool | Opt-in to marketing emails (optional)
103+
noemail = True # bool | Set to true to suppress the Order Confirmation email being sent (optional)
104+
skipvalidation = True # bool | Ignore required field validation (optional)
105+
106+
try:
107+
# Add a new client
108+
api_response = api_instance.add_client(username, password, action, firstname, lastname, email, address1, city, state, postcode, country, phonenumber, accesskey=accesskey, responsetype=responsetype, owner_user_id=owner_user_id, companyname=companyname, address2=address2, tax_id=tax_id, password2=password2, securityqid=securityqid, securityqans=securityqans, currency=currency, groupid=groupid, customfields=customfields, language=language, clientip=clientip, notes=notes, marketingoptin=marketingoptin, noemail=noemail, skipvalidation=skipvalidation)
109+
print("The response of DefaultApi->add_client:\n")
110+
pprint(api_response)
111+
except ApiException as e:
112+
print("Exception when calling DefaultApi->add_client: %s\n" % e)
113+
83114
```
84115

85116
## Documentation for API Endpoints
@@ -92,27 +123,25 @@ Class | Method | HTTP request | Description
92123
*DefaultApi* | [**add_order**](docs/DefaultApi.md#add_order) | **POST** /AddOrder | Create a new order
93124
*DefaultApi* | [**update_client**](docs/DefaultApi.md#update_client) | **POST** /UpdateClient | Update client details
94125

126+
95127
## Documentation For Models
96128

97-
- [AddClientBody](docs/AddClientBody.md)
98-
- [AddClientRequest](docs/AddClientRequest.md)
99129
- [AddClientResponse](docs/AddClientResponse.md)
100-
- [AddOrderBody](docs/AddOrderBody.md)
101-
- [AddOrderRequest](docs/AddOrderRequest.md)
102130
- [AddOrderResponse](docs/AddOrderResponse.md)
103-
- [UpdateClientBody](docs/UpdateClientBody.md)
104-
- [UpdateClientRequest](docs/UpdateClientRequest.md)
105131
- [UpdateClientResponse](docs/UpdateClientResponse.md)
106-
- [WHMCSBaseRequest](docs/WHMCSBaseRequest.md)
107132
- [WHMCSBaseResponse](docs/WHMCSBaseResponse.md)
108133
- [WHMCSErrorResponse](docs/WHMCSErrorResponse.md)
109134
- [WHMCSSuccessResponse](docs/WHMCSSuccessResponse.md)
110135

136+
137+
<a id="documentation-for-authorization"></a>
111138
## Documentation For Authorization
112139

113-
All endpoints do not require authorization.
140+
Endpoints do not require authorization.
114141

115142

116143
## Author
117144

118145

146+
147+

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"packageName": "whmcs_client",
33
"projectName": "whmcs-api-client",
4-
"packageVersion": "1.0.4",
4+
"packageVersion": "1.0.5",
55
"packageUrl": "https://github.com/truehostcloud/whmcs-python-client",
66
"packageCompany": "Truehost",
77
"packageAuthor": "William Mwai",

docs/AddClientBody.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)