celitech-sdk 1.2.5__tar.gz → 1.3.4__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.
- {celitech_sdk-1.2.5/src/celitech_sdk.egg-info → celitech_sdk-1.3.4}/PKG-INFO +35 -4
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/PyPI_README.md +34 -3
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/README.md +34 -3
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/pyproject.toml +1 -1
- celitech_sdk-1.3.4/src/celitech/hooks/hook.py +35 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/__init__.py +2 -0
- celitech_sdk-1.3.4/src/celitech/models/get_access_token_ok_response.py +33 -0
- celitech_sdk-1.3.4/src/celitech/models/get_access_token_request.py +59 -0
- celitech_sdk-1.3.4/src/celitech/net/oauth/token_manager.py +85 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/hook_handler.py +2 -2
- celitech_sdk-1.3.4/src/celitech/net/request_chain/handlers/oauth_handler.py +51 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/sdk.py +58 -4
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/destinations.py +1 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/e_sim.py +4 -0
- celitech_sdk-1.3.4/src/celitech/services/o_auth.py +35 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/packages.py +1 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/purchases.py +5 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/utils/base_service.py +6 -1
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4/src/celitech_sdk.egg-info}/PKG-INFO +35 -4
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech_sdk.egg-info/SOURCES.txt +5 -0
- celitech_sdk-1.2.5/src/celitech/hooks/hook.py +0 -84
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/LICENSE +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/setup.cfg +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/hooks/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/create_purchase_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/create_purchase_request.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/edit_purchase_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/edit_purchase_request.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_esim_device_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_esim_history_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_esim_mac_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_esim_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_purchase_consumption_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/list_destinations_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/list_packages_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/list_purchases_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/top_up_esim_ok_response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/top_up_esim_request.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/utils/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/utils/base_model.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/utils/cast_models.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/utils/json_map.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/utils/one_of_base_model.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/environment/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/environment/environment.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/headers/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/headers/base_header.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/base_handler.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/http_handler.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/retry_handler.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/request_chain.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/transport/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/transport/request.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/transport/request_error.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/transport/response.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/transport/serializer.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/transport/utils.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/utils/__init__.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/utils/default_headers.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/services/utils/validator.py +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech_sdk.egg-info/dependency_links.txt +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech_sdk.egg-info/requires.txt +0 -0
- {celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech_sdk.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: celitech-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.4
|
|
4
4
|
Summary: Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/)
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.7
|
|
@@ -8,14 +8,14 @@ Description-Content-Type: text/markdown
|
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Dist: requests>=2.31.0
|
|
10
10
|
|
|
11
|
-
# Celitech Python SDK 1.
|
|
11
|
+
# Celitech Python SDK 1.3.4<a id="celitech-python-sdk-134"></a>
|
|
12
12
|
|
|
13
13
|
Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
|
|
14
14
|
|
|
15
15
|
## Versions<a id="versions"></a>
|
|
16
16
|
|
|
17
17
|
- API version: `1.1.0`
|
|
18
|
-
- SDK version: `1.
|
|
18
|
+
- SDK version: `1.3.4`
|
|
19
19
|
|
|
20
20
|
## About the API<a id="about-the-api"></a>
|
|
21
21
|
|
|
@@ -26,6 +26,8 @@ Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.
|
|
|
26
26
|
- [Setup & Configuration](#setup--configuration)
|
|
27
27
|
- [Supported Language Versions](#supported-language-versions)
|
|
28
28
|
- [Installation](#installation)
|
|
29
|
+
- [Authentication](#authentication)
|
|
30
|
+
- [OAuth Authentication](#oauth-authentication)
|
|
29
31
|
- [Environment Variables](#environment-variables)
|
|
30
32
|
- [Setting a Custom Timeout](#setting-a-custom-timeout)
|
|
31
33
|
- [Sample Usage](#sample-usage)
|
|
@@ -47,6 +49,30 @@ To get started with the SDK, we recommend installing using `pip`:
|
|
|
47
49
|
pip install celitech-sdk
|
|
48
50
|
```
|
|
49
51
|
|
|
52
|
+
## Authentication<a id="authentication"></a>
|
|
53
|
+
|
|
54
|
+
### OAuth Authentication<a id="oauth-authentication"></a>
|
|
55
|
+
|
|
56
|
+
The Celitech API uses OAuth for authentication.
|
|
57
|
+
|
|
58
|
+
You need to provide the OAuth parameters when initializing the SDK.
|
|
59
|
+
|
|
60
|
+
```py
|
|
61
|
+
sdk = Celitech(
|
|
62
|
+
client_id="client-id",
|
|
63
|
+
client_secret="client-secret",
|
|
64
|
+
client_id="CLIENT_ID",
|
|
65
|
+
client_secret="CLIENT_SECRET"
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If you need to set or update the OAuth parameters after the SDK initialization, you can use:
|
|
70
|
+
|
|
71
|
+
```py
|
|
72
|
+
sdk.set_client_id("CLIENT_ID")
|
|
73
|
+
sdk.set_client_secret("CLIENT_SECRET")
|
|
74
|
+
```
|
|
75
|
+
|
|
50
76
|
## Environment Variables<a id="environment-variables"></a>
|
|
51
77
|
|
|
52
78
|
These are the environment variables for the SDK:
|
|
@@ -79,7 +105,9 @@ from celitech import Celitech
|
|
|
79
105
|
|
|
80
106
|
sdk = Celitech(
|
|
81
107
|
client_id="client-id",
|
|
82
|
-
client_secret="client-secret"
|
|
108
|
+
client_secret="client-secret",
|
|
109
|
+
client_id="CLIENT_ID",
|
|
110
|
+
client_secret="CLIENT_SECRET"
|
|
83
111
|
)
|
|
84
112
|
|
|
85
113
|
result = sdk.destinations.list_destinations()
|
|
@@ -97,6 +125,7 @@ The SDK provides various services to interact with the API.
|
|
|
97
125
|
|
|
98
126
|
| Name |
|
|
99
127
|
| :----------- |
|
|
128
|
+
| o_auth |
|
|
100
129
|
| destinations |
|
|
101
130
|
| packages |
|
|
102
131
|
| purchases |
|
|
@@ -113,6 +142,8 @@ The SDK includes several models that represent the data structures used in API r
|
|
|
113
142
|
|
|
114
143
|
| Name | Description |
|
|
115
144
|
| :------------------------------- | :---------- |
|
|
145
|
+
| GetAccessTokenRequest | |
|
|
146
|
+
| GetAccessTokenOkResponse | |
|
|
116
147
|
| ListDestinationsOkResponse | |
|
|
117
148
|
| ListPackagesOkResponse | |
|
|
118
149
|
| ListPurchasesOkResponse | |
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Celitech Python SDK 1.
|
|
1
|
+
# Celitech Python SDK 1.3.4<a id="celitech-python-sdk-134"></a>
|
|
2
2
|
|
|
3
3
|
Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
|
|
4
4
|
|
|
5
5
|
## Versions<a id="versions"></a>
|
|
6
6
|
|
|
7
7
|
- API version: `1.1.0`
|
|
8
|
-
- SDK version: `1.
|
|
8
|
+
- SDK version: `1.3.4`
|
|
9
9
|
|
|
10
10
|
## About the API<a id="about-the-api"></a>
|
|
11
11
|
|
|
@@ -16,6 +16,8 @@ Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.
|
|
|
16
16
|
- [Setup & Configuration](#setup--configuration)
|
|
17
17
|
- [Supported Language Versions](#supported-language-versions)
|
|
18
18
|
- [Installation](#installation)
|
|
19
|
+
- [Authentication](#authentication)
|
|
20
|
+
- [OAuth Authentication](#oauth-authentication)
|
|
19
21
|
- [Environment Variables](#environment-variables)
|
|
20
22
|
- [Setting a Custom Timeout](#setting-a-custom-timeout)
|
|
21
23
|
- [Sample Usage](#sample-usage)
|
|
@@ -37,6 +39,30 @@ To get started with the SDK, we recommend installing using `pip`:
|
|
|
37
39
|
pip install celitech-sdk
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
## Authentication<a id="authentication"></a>
|
|
43
|
+
|
|
44
|
+
### OAuth Authentication<a id="oauth-authentication"></a>
|
|
45
|
+
|
|
46
|
+
The Celitech API uses OAuth for authentication.
|
|
47
|
+
|
|
48
|
+
You need to provide the OAuth parameters when initializing the SDK.
|
|
49
|
+
|
|
50
|
+
```py
|
|
51
|
+
sdk = Celitech(
|
|
52
|
+
client_id="client-id",
|
|
53
|
+
client_secret="client-secret",
|
|
54
|
+
client_id="CLIENT_ID",
|
|
55
|
+
client_secret="CLIENT_SECRET"
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If you need to set or update the OAuth parameters after the SDK initialization, you can use:
|
|
60
|
+
|
|
61
|
+
```py
|
|
62
|
+
sdk.set_client_id("CLIENT_ID")
|
|
63
|
+
sdk.set_client_secret("CLIENT_SECRET")
|
|
64
|
+
```
|
|
65
|
+
|
|
40
66
|
## Environment Variables<a id="environment-variables"></a>
|
|
41
67
|
|
|
42
68
|
These are the environment variables for the SDK:
|
|
@@ -69,7 +95,9 @@ from celitech import Celitech
|
|
|
69
95
|
|
|
70
96
|
sdk = Celitech(
|
|
71
97
|
client_id="client-id",
|
|
72
|
-
client_secret="client-secret"
|
|
98
|
+
client_secret="client-secret",
|
|
99
|
+
client_id="CLIENT_ID",
|
|
100
|
+
client_secret="CLIENT_SECRET"
|
|
73
101
|
)
|
|
74
102
|
|
|
75
103
|
result = sdk.destinations.list_destinations()
|
|
@@ -87,6 +115,7 @@ The SDK provides various services to interact with the API.
|
|
|
87
115
|
|
|
88
116
|
| Name |
|
|
89
117
|
| :----------- |
|
|
118
|
+
| o_auth |
|
|
90
119
|
| destinations |
|
|
91
120
|
| packages |
|
|
92
121
|
| purchases |
|
|
@@ -103,6 +132,8 @@ The SDK includes several models that represent the data structures used in API r
|
|
|
103
132
|
|
|
104
133
|
| Name | Description |
|
|
105
134
|
| :------------------------------- | :---------- |
|
|
135
|
+
| GetAccessTokenRequest | |
|
|
136
|
+
| GetAccessTokenOkResponse | |
|
|
106
137
|
| ListDestinationsOkResponse | |
|
|
107
138
|
| ListPackagesOkResponse | |
|
|
108
139
|
| ListPurchasesOkResponse | |
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Celitech Python SDK 1.
|
|
1
|
+
# Celitech Python SDK 1.3.4
|
|
2
2
|
|
|
3
3
|
Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
|
|
4
4
|
|
|
5
5
|
## Versions
|
|
6
6
|
|
|
7
7
|
- API version: `1.1.0`
|
|
8
|
-
- SDK version: `1.
|
|
8
|
+
- SDK version: `1.3.4`
|
|
9
9
|
|
|
10
10
|
## About the API
|
|
11
11
|
|
|
@@ -16,6 +16,8 @@ Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.
|
|
|
16
16
|
- [Setup & Configuration](#setup--configuration)
|
|
17
17
|
- [Supported Language Versions](#supported-language-versions)
|
|
18
18
|
- [Installation](#installation)
|
|
19
|
+
- [Authentication](#authentication)
|
|
20
|
+
- [OAuth Authentication](#oauth-authentication)
|
|
19
21
|
- [Environment Variables](#environment-variables)
|
|
20
22
|
- [Setting a Custom Timeout](#setting-a-custom-timeout)
|
|
21
23
|
- [Sample Usage](#sample-usage)
|
|
@@ -37,6 +39,30 @@ To get started with the SDK, we recommend installing using `pip`:
|
|
|
37
39
|
pip install celitech-sdk
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
## Authentication
|
|
43
|
+
|
|
44
|
+
### OAuth Authentication
|
|
45
|
+
|
|
46
|
+
The Celitech API uses OAuth for authentication.
|
|
47
|
+
|
|
48
|
+
You need to provide the OAuth parameters when initializing the SDK.
|
|
49
|
+
|
|
50
|
+
```py
|
|
51
|
+
sdk = Celitech(
|
|
52
|
+
client_id="client-id",
|
|
53
|
+
client_secret="client-secret",
|
|
54
|
+
client_id="CLIENT_ID",
|
|
55
|
+
client_secret="CLIENT_SECRET"
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If you need to set or update the OAuth parameters after the SDK initialization, you can use:
|
|
60
|
+
|
|
61
|
+
```py
|
|
62
|
+
sdk.set_client_id("CLIENT_ID")
|
|
63
|
+
sdk.set_client_secret("CLIENT_SECRET")
|
|
64
|
+
```
|
|
65
|
+
|
|
40
66
|
## Environment Variables
|
|
41
67
|
|
|
42
68
|
These are the environment variables for the SDK:
|
|
@@ -69,7 +95,9 @@ from celitech import Celitech
|
|
|
69
95
|
|
|
70
96
|
sdk = Celitech(
|
|
71
97
|
client_id="client-id",
|
|
72
|
-
client_secret="client-secret"
|
|
98
|
+
client_secret="client-secret",
|
|
99
|
+
client_id="CLIENT_ID",
|
|
100
|
+
client_secret="CLIENT_SECRET"
|
|
73
101
|
)
|
|
74
102
|
|
|
75
103
|
result = sdk.destinations.list_destinations()
|
|
@@ -87,6 +115,7 @@ The SDK provides various services to interact with the API.
|
|
|
87
115
|
|
|
88
116
|
| Name |
|
|
89
117
|
| :------------------------------------------------------------------- |
|
|
118
|
+
| [OAuthService](documentation/services/OAuthService.md) |
|
|
90
119
|
| [DestinationsService](documentation/services/DestinationsService.md) |
|
|
91
120
|
| [PackagesService](documentation/services/PackagesService.md) |
|
|
92
121
|
| [PurchasesService](documentation/services/PurchasesService.md) |
|
|
@@ -103,6 +132,8 @@ The SDK includes several models that represent the data structures used in API r
|
|
|
103
132
|
|
|
104
133
|
| Name | Description |
|
|
105
134
|
| :------------------------------------------------------------------------------------------- | :---------- |
|
|
135
|
+
| [GetAccessTokenRequest](documentation/models/GetAccessTokenRequest.md) | |
|
|
136
|
+
| [GetAccessTokenOkResponse](documentation/models/GetAccessTokenOkResponse.md) | |
|
|
106
137
|
| [ListDestinationsOkResponse](documentation/models/ListDestinationsOkResponse.md) | |
|
|
107
138
|
| [ListPackagesOkResponse](documentation/models/ListPackagesOkResponse.md) | |
|
|
108
139
|
| [ListPurchasesOkResponse](documentation/models/ListPurchasesOkResponse.md) | |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "celitech-sdk"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.3.4"
|
|
8
8
|
license = { text = "MIT" }
|
|
9
9
|
description = """Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/) """
|
|
10
10
|
readme = "PyPI_README.md"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class Request:
|
|
2
|
+
def __init__(self, method, url, headers, body=""):
|
|
3
|
+
self.method = method
|
|
4
|
+
self.url = url
|
|
5
|
+
self.headers = headers
|
|
6
|
+
self.body = body
|
|
7
|
+
|
|
8
|
+
def __str__(self):
|
|
9
|
+
return f"method={self.method}, url={self.url}, headers={self.headers}, body={self.body})"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Response:
|
|
13
|
+
def __init__(self, status, headers, body):
|
|
14
|
+
self.status = status
|
|
15
|
+
self.headers = headers
|
|
16
|
+
self.body = body
|
|
17
|
+
|
|
18
|
+
def __str__(self):
|
|
19
|
+
return "Response(status={}, headers={}, body={})".format(
|
|
20
|
+
self.status, self.headers, self.body
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DefaultHook:
|
|
25
|
+
|
|
26
|
+
def before_request(self, request: Request, **kwargs):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
def after_response(self, request: Request, response: Response, **kwargs):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def on_error(
|
|
33
|
+
self, error: Exception, request: Request, response: Response, **kwargs
|
|
34
|
+
):
|
|
35
|
+
pass
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from .get_access_token_request import GetAccessTokenRequest, GrantType
|
|
2
|
+
from .get_access_token_ok_response import GetAccessTokenOkResponse
|
|
1
3
|
from .list_destinations_ok_response import ListDestinationsOkResponse, Destinations
|
|
2
4
|
from .list_packages_ok_response import ListPackagesOkResponse, Packages
|
|
3
5
|
from .list_purchases_ok_response import ListPurchasesOkResponse, Purchases
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .utils.json_map import JsonMap
|
|
2
|
+
from .utils.base_model import BaseModel
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@JsonMap({})
|
|
6
|
+
class GetAccessTokenOkResponse(BaseModel):
|
|
7
|
+
"""GetAccessTokenOkResponse
|
|
8
|
+
|
|
9
|
+
:param access_token: access_token, defaults to None
|
|
10
|
+
:type access_token: str, optional
|
|
11
|
+
:param token_type: token_type, defaults to None
|
|
12
|
+
:type token_type: str, optional
|
|
13
|
+
:param expires_in: expires_in, defaults to None
|
|
14
|
+
:type expires_in: int, optional
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self, access_token: str = None, token_type: str = None, expires_in: int = None
|
|
19
|
+
):
|
|
20
|
+
"""GetAccessTokenOkResponse
|
|
21
|
+
|
|
22
|
+
:param access_token: access_token, defaults to None
|
|
23
|
+
:type access_token: str, optional
|
|
24
|
+
:param token_type: token_type, defaults to None
|
|
25
|
+
:type token_type: str, optional
|
|
26
|
+
:param expires_in: expires_in, defaults to None
|
|
27
|
+
:type expires_in: int, optional
|
|
28
|
+
"""
|
|
29
|
+
self.access_token = self._define_str(
|
|
30
|
+
"access_token", access_token, nullable=True
|
|
31
|
+
)
|
|
32
|
+
self.token_type = self._define_str("token_type", token_type, nullable=True)
|
|
33
|
+
self.expires_in = self._define_number("expires_in", expires_in, nullable=True)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from .utils.json_map import JsonMap
|
|
3
|
+
from .utils.base_model import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class GrantType(Enum):
|
|
7
|
+
"""An enumeration representing different categories.
|
|
8
|
+
|
|
9
|
+
:cvar CLIENTCREDENTIALS: "client_credentials"
|
|
10
|
+
:vartype CLIENTCREDENTIALS: str
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
CLIENTCREDENTIALS = "client_credentials"
|
|
14
|
+
|
|
15
|
+
def list():
|
|
16
|
+
"""Lists all category values.
|
|
17
|
+
|
|
18
|
+
:return: A list of all category values.
|
|
19
|
+
:rtype: list
|
|
20
|
+
"""
|
|
21
|
+
return list(map(lambda x: x.value, GrantType._member_map_.values()))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@JsonMap({})
|
|
25
|
+
class GetAccessTokenRequest(BaseModel):
|
|
26
|
+
"""GetAccessTokenRequest
|
|
27
|
+
|
|
28
|
+
:param grant_type: grant_type, defaults to None
|
|
29
|
+
:type grant_type: GrantType, optional
|
|
30
|
+
:param client_id: client_id, defaults to None
|
|
31
|
+
:type client_id: str, optional
|
|
32
|
+
:param client_secret: client_secret, defaults to None
|
|
33
|
+
:type client_secret: str, optional
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
grant_type: GrantType = None,
|
|
39
|
+
client_id: str = None,
|
|
40
|
+
client_secret: str = None,
|
|
41
|
+
):
|
|
42
|
+
"""GetAccessTokenRequest
|
|
43
|
+
|
|
44
|
+
:param grant_type: grant_type, defaults to None
|
|
45
|
+
:type grant_type: GrantType, optional
|
|
46
|
+
:param client_id: client_id, defaults to None
|
|
47
|
+
:type client_id: str, optional
|
|
48
|
+
:param client_secret: client_secret, defaults to None
|
|
49
|
+
:type client_secret: str, optional
|
|
50
|
+
"""
|
|
51
|
+
self.grant_type = (
|
|
52
|
+
self._enum_matching(grant_type, GrantType.list(), "grant_type")
|
|
53
|
+
if grant_type
|
|
54
|
+
else None
|
|
55
|
+
)
|
|
56
|
+
self.client_id = self._define_str("client_id", client_id, nullable=True)
|
|
57
|
+
self.client_secret = self._define_str(
|
|
58
|
+
"client_secret", client_secret, nullable=True
|
|
59
|
+
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from typing import Set
|
|
2
|
+
from time import time
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OauthToken:
|
|
6
|
+
def __init__(self, access_token: str, scopes: Set[str], expires_at: int):
|
|
7
|
+
self.access_token = access_token
|
|
8
|
+
self.scopes = scopes
|
|
9
|
+
self.expires_at = expires_at
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TokenManager:
|
|
13
|
+
def __init__(self, base_oauth_url: str):
|
|
14
|
+
self._base_oauth_url = base_oauth_url
|
|
15
|
+
self._token = None
|
|
16
|
+
self.client_id = None
|
|
17
|
+
self.client_secret = None
|
|
18
|
+
|
|
19
|
+
def set_base_oauth_url(self, base_oauth_url: str):
|
|
20
|
+
"""
|
|
21
|
+
Sets the base oAuth URL
|
|
22
|
+
"""
|
|
23
|
+
self._base_oauth_url = base_oauth_url
|
|
24
|
+
return self
|
|
25
|
+
|
|
26
|
+
def set_client_id(self, client_id: str):
|
|
27
|
+
"""
|
|
28
|
+
Sets the client_id.
|
|
29
|
+
"""
|
|
30
|
+
self.client_id = client_id
|
|
31
|
+
return self
|
|
32
|
+
|
|
33
|
+
def set_client_secret(self, client_secret: str):
|
|
34
|
+
"""
|
|
35
|
+
Sets the client_secret.
|
|
36
|
+
"""
|
|
37
|
+
self.client_secret = client_secret
|
|
38
|
+
return self
|
|
39
|
+
|
|
40
|
+
def get_token(self, scopes: Set[str]) -> OauthToken:
|
|
41
|
+
"""
|
|
42
|
+
Get an OAuth token with the given scopes
|
|
43
|
+
|
|
44
|
+
:param scopes: The scopes to request
|
|
45
|
+
:type scopes: Set[str]
|
|
46
|
+
|
|
47
|
+
:return: The OAuth token
|
|
48
|
+
:rtype: OauthToken
|
|
49
|
+
"""
|
|
50
|
+
if self._token and self._token.scopes.issuperset(scopes):
|
|
51
|
+
return self._token
|
|
52
|
+
|
|
53
|
+
if self._token:
|
|
54
|
+
scopes.update(self._token.scopes)
|
|
55
|
+
|
|
56
|
+
response = self._get_access_token(scopes)
|
|
57
|
+
self._token = OauthToken(
|
|
58
|
+
access_token=response.access_token,
|
|
59
|
+
scopes=scopes,
|
|
60
|
+
expires_at=(
|
|
61
|
+
response.expires_in + int(time())
|
|
62
|
+
if hasattr(response, "expires_in")
|
|
63
|
+
else None
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
return self._token
|
|
67
|
+
|
|
68
|
+
def clean(self):
|
|
69
|
+
"""
|
|
70
|
+
Clean the token manager to force a new token request
|
|
71
|
+
"""
|
|
72
|
+
self._token = None
|
|
73
|
+
|
|
74
|
+
def _get_access_token(self, scopes: Set[str]):
|
|
75
|
+
# We need to import the service here, to avoid a circular reference error.
|
|
76
|
+
from ...services.o_auth import OAuthService
|
|
77
|
+
|
|
78
|
+
service = OAuthService(base_url=self._base_oauth_url, token_manager=self)
|
|
79
|
+
return service.get_access_token(
|
|
80
|
+
request_body={
|
|
81
|
+
"grant_type": "client_credentials",
|
|
82
|
+
"client_id": self.client_id,
|
|
83
|
+
"client_secret": self.client_secret,
|
|
84
|
+
}
|
|
85
|
+
)
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/hook_handler.py
RENAMED
|
@@ -2,7 +2,7 @@ from typing import Generator, Optional, Tuple
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
from .base_handler import BaseHandler
|
|
5
|
-
from ....hooks.hook import
|
|
5
|
+
from ....hooks.hook import DefaultHook
|
|
6
6
|
from ...transport.request import Request
|
|
7
7
|
from ...transport.response import Response
|
|
8
8
|
from ...transport.request_error import RequestError
|
|
@@ -20,7 +20,7 @@ class HookHandler(BaseHandler):
|
|
|
20
20
|
Initialize a new instance of HookHandler.
|
|
21
21
|
"""
|
|
22
22
|
super().__init__()
|
|
23
|
-
self._hook =
|
|
23
|
+
self._hook = DefaultHook()
|
|
24
24
|
|
|
25
25
|
self._additional_variables = additional_variables
|
|
26
26
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import Generator, Optional, Tuple
|
|
2
|
+
|
|
3
|
+
from ...oauth.token_manager import OauthToken, TokenManager
|
|
4
|
+
from ...transport.request import Request
|
|
5
|
+
from ...transport.request_error import RequestError
|
|
6
|
+
from ...transport.response import Response
|
|
7
|
+
from .base_handler import BaseHandler
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OauthHandler(BaseHandler):
|
|
11
|
+
def __init__(self, token_manager: TokenManager):
|
|
12
|
+
"""
|
|
13
|
+
Initialize a new instance of OauthHandler.
|
|
14
|
+
"""
|
|
15
|
+
super().__init__()
|
|
16
|
+
self._token_manager = token_manager
|
|
17
|
+
|
|
18
|
+
def handle(
|
|
19
|
+
self, request: Request
|
|
20
|
+
) -> Tuple[Optional[Response], Optional[RequestError]]:
|
|
21
|
+
if self._next_handler is None:
|
|
22
|
+
raise RequestError("Handler chain is incomplete")
|
|
23
|
+
|
|
24
|
+
if request.scopes is None:
|
|
25
|
+
# This endpoint is not using Oauth
|
|
26
|
+
return self._next_handler.handle(request)
|
|
27
|
+
|
|
28
|
+
token = self._token_manager.get_token(request.scopes)
|
|
29
|
+
self._update_token(request, token)
|
|
30
|
+
|
|
31
|
+
return self._next_handler.handle(request)
|
|
32
|
+
|
|
33
|
+
def stream(
|
|
34
|
+
self, request: Request
|
|
35
|
+
) -> Generator[Tuple[Optional[Response], Optional[RequestError]], None, None]:
|
|
36
|
+
if self._next_handler is None:
|
|
37
|
+
raise RequestError("Handler chain is incomplete")
|
|
38
|
+
|
|
39
|
+
if request.scopes is None:
|
|
40
|
+
# This endpoint is not using Oauth
|
|
41
|
+
for response, error in self._next_handler.stream(request):
|
|
42
|
+
yield response, error
|
|
43
|
+
|
|
44
|
+
token = self._token_manager.get_token(request.scopes)
|
|
45
|
+
self._update_token(request, token)
|
|
46
|
+
|
|
47
|
+
for response, error in self._next_handler.stream(request):
|
|
48
|
+
yield response, error
|
|
49
|
+
|
|
50
|
+
def _update_token(self, request: Request, token: OauthToken):
|
|
51
|
+
request.headers["Authorization"] = f"Bearer {token.access_token}"
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from typing import Union
|
|
2
|
+
from .services.o_auth import OAuthService
|
|
2
3
|
from .services.destinations import DestinationsService
|
|
3
4
|
from .services.packages import PackagesService
|
|
4
5
|
from .services.purchases import PurchasesService
|
|
5
6
|
from .services.e_sim import ESimService
|
|
6
7
|
from .net.environment import Environment
|
|
8
|
+
from .net.oauth.token_manager import TokenManager
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
class Celitech:
|
|
@@ -11,20 +13,40 @@ class Celitech:
|
|
|
11
13
|
self,
|
|
12
14
|
client_id: str = None,
|
|
13
15
|
client_secret: str = None,
|
|
16
|
+
client_id: str = None,
|
|
17
|
+
client_secret: str = None,
|
|
14
18
|
base_url: Union[Environment, str] = Environment.DEFAULT,
|
|
15
19
|
timeout: int = 60000,
|
|
20
|
+
base_oauth_url: str = None,
|
|
16
21
|
):
|
|
17
22
|
"""
|
|
18
23
|
Initializes Celitech the SDK class.
|
|
19
24
|
"""
|
|
25
|
+
self.base_oauth_url = (
|
|
26
|
+
base_oauth_url if base_oauth_url else "https://auth.celitech.net"
|
|
27
|
+
)
|
|
28
|
+
self._token_manager = TokenManager(base_oauth_url=self.base_oauth_url)
|
|
20
29
|
|
|
21
30
|
self._base_url = (
|
|
22
31
|
base_url.value if isinstance(base_url, Environment) else base_url
|
|
23
32
|
)
|
|
24
|
-
self.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
self.
|
|
33
|
+
self.o_auth = OAuthService(
|
|
34
|
+
base_url=self._base_url, token_manager=self._token_manager
|
|
35
|
+
)
|
|
36
|
+
self.destinations = DestinationsService(
|
|
37
|
+
base_url=self._base_url, token_manager=self._token_manager
|
|
38
|
+
)
|
|
39
|
+
self.packages = PackagesService(
|
|
40
|
+
base_url=self._base_url, token_manager=self._token_manager
|
|
41
|
+
)
|
|
42
|
+
self.purchases = PurchasesService(
|
|
43
|
+
base_url=self._base_url, token_manager=self._token_manager
|
|
44
|
+
)
|
|
45
|
+
self.e_sim = ESimService(
|
|
46
|
+
base_url=self._base_url, token_manager=self._token_manager
|
|
47
|
+
)
|
|
48
|
+
self.set_client_id(client_id)
|
|
49
|
+
self.set_client_secret(client_secret)
|
|
28
50
|
self.set_additional_variables(client_id, client_secret)
|
|
29
51
|
self.set_timeout(timeout)
|
|
30
52
|
|
|
@@ -39,6 +61,7 @@ class Celitech:
|
|
|
39
61
|
base_url.value if isinstance(base_url, Environment) else base_url
|
|
40
62
|
)
|
|
41
63
|
|
|
64
|
+
self.o_auth.set_base_url(self._base_url)
|
|
42
65
|
self.destinations.set_base_url(self._base_url)
|
|
43
66
|
self.packages.set_base_url(self._base_url)
|
|
44
67
|
self.purchases.set_base_url(self._base_url)
|
|
@@ -46,12 +69,22 @@ class Celitech:
|
|
|
46
69
|
|
|
47
70
|
return self
|
|
48
71
|
|
|
72
|
+
def set_base_oauth_url(self, base_oauth_url):
|
|
73
|
+
"""
|
|
74
|
+
Sets the base oAuth URL for the entire SDK.
|
|
75
|
+
"""
|
|
76
|
+
self.base_oauth_url = base_oauth_url
|
|
77
|
+
self._token_manager.set_base_oauth_url(base_oauth_url)
|
|
78
|
+
|
|
79
|
+
return self
|
|
80
|
+
|
|
49
81
|
def set_additional_variables(
|
|
50
82
|
self, client_id: str = None, client_secret: str = None
|
|
51
83
|
):
|
|
52
84
|
"""
|
|
53
85
|
Sets the additional variables for the entire SDK.
|
|
54
86
|
"""
|
|
87
|
+
self.o_auth.set_additional_variables(client_id, client_secret)
|
|
55
88
|
self.destinations.set_additional_variables(client_id, client_secret)
|
|
56
89
|
self.packages.set_additional_variables(client_id, client_secret)
|
|
57
90
|
self.purchases.set_additional_variables(client_id, client_secret)
|
|
@@ -66,6 +99,7 @@ class Celitech:
|
|
|
66
99
|
:param int timeout: The timeout (ms) to be set.
|
|
67
100
|
:return: The SDK instance.
|
|
68
101
|
"""
|
|
102
|
+
self.o_auth.set_timeout(timeout)
|
|
69
103
|
self.destinations.set_timeout(timeout)
|
|
70
104
|
self.packages.set_timeout(timeout)
|
|
71
105
|
self.purchases.set_timeout(timeout)
|
|
@@ -73,5 +107,25 @@ class Celitech:
|
|
|
73
107
|
|
|
74
108
|
return self
|
|
75
109
|
|
|
110
|
+
def set_client_id(self, client_id: str):
|
|
111
|
+
"""
|
|
112
|
+
Sets the client_id for the entire SDK.
|
|
113
|
+
|
|
114
|
+
:param str client_id: The client_id to be set.
|
|
115
|
+
:return: The SDK instance.
|
|
116
|
+
"""
|
|
117
|
+
self._token_manager.set_client_id(client_id)
|
|
118
|
+
return self
|
|
119
|
+
|
|
120
|
+
def set_client_secret(self, client_secret: str):
|
|
121
|
+
"""
|
|
122
|
+
Sets the client_secret for the entire SDK.
|
|
123
|
+
|
|
124
|
+
:param str client_secret: The client_secret to be set.
|
|
125
|
+
:return: The SDK instance.
|
|
126
|
+
"""
|
|
127
|
+
self._token_manager.set_client_secret(client_secret)
|
|
128
|
+
return self
|
|
129
|
+
|
|
76
130
|
|
|
77
131
|
# c029837e0e474b76bc487506e8799df5e3335891efe4fb02bda7a1441840310c
|
|
@@ -32,6 +32,7 @@ class ESimService(BaseService):
|
|
|
32
32
|
.add_query("iccid", iccid)
|
|
33
33
|
.serialize()
|
|
34
34
|
.set_method("GET")
|
|
35
|
+
.set_scopes({})
|
|
35
36
|
)
|
|
36
37
|
|
|
37
38
|
response = self.send_request(serialized_request)
|
|
@@ -59,6 +60,7 @@ class ESimService(BaseService):
|
|
|
59
60
|
.add_path("iccid", iccid)
|
|
60
61
|
.serialize()
|
|
61
62
|
.set_method("GET")
|
|
63
|
+
.set_scopes({})
|
|
62
64
|
)
|
|
63
65
|
|
|
64
66
|
response = self.send_request(serialized_request)
|
|
@@ -86,6 +88,7 @@ class ESimService(BaseService):
|
|
|
86
88
|
.add_path("iccid", iccid)
|
|
87
89
|
.serialize()
|
|
88
90
|
.set_method("GET")
|
|
91
|
+
.set_scopes({})
|
|
89
92
|
)
|
|
90
93
|
|
|
91
94
|
response = self.send_request(serialized_request)
|
|
@@ -113,6 +116,7 @@ class ESimService(BaseService):
|
|
|
113
116
|
.add_path("iccid", iccid)
|
|
114
117
|
.serialize()
|
|
115
118
|
.set_method("GET")
|
|
119
|
+
.set_scopes({})
|
|
116
120
|
)
|
|
117
121
|
|
|
118
122
|
response = self.send_request(serialized_request)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from .utils.validator import Validator
|
|
2
|
+
from .utils.base_service import BaseService
|
|
3
|
+
from ..net.transport.serializer import Serializer
|
|
4
|
+
from ..models.utils.cast_models import cast_models
|
|
5
|
+
from ..models import GetAccessTokenOkResponse, GetAccessTokenRequest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OAuthService(BaseService):
|
|
9
|
+
|
|
10
|
+
@cast_models
|
|
11
|
+
def get_access_token(
|
|
12
|
+
self, request_body: GetAccessTokenRequest
|
|
13
|
+
) -> GetAccessTokenOkResponse:
|
|
14
|
+
"""This endpoint was added by liblab
|
|
15
|
+
|
|
16
|
+
:param request_body: The request body.
|
|
17
|
+
:type request_body: GetAccessTokenRequest
|
|
18
|
+
...
|
|
19
|
+
:raises RequestError: Raised when a request fails, with optional HTTP status code and details.
|
|
20
|
+
...
|
|
21
|
+
:return: Successful Response
|
|
22
|
+
:rtype: GetAccessTokenOkResponse
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
Validator(GetAccessTokenRequest).validate(request_body)
|
|
26
|
+
|
|
27
|
+
serialized_request = (
|
|
28
|
+
Serializer(f"{self.base_url}/oauth2/token", self.get_default_headers())
|
|
29
|
+
.serialize()
|
|
30
|
+
.set_method("POST")
|
|
31
|
+
.set_body(request_body, "application/x-www-form-urlencoded")
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
response = self.send_request(serialized_request)
|
|
35
|
+
return GetAccessTokenOkResponse._unmap(response)
|
|
@@ -74,6 +74,7 @@ class PurchasesService(BaseService):
|
|
|
74
74
|
.add_query("before", before)
|
|
75
75
|
.serialize()
|
|
76
76
|
.set_method("GET")
|
|
77
|
+
.set_scopes({})
|
|
77
78
|
)
|
|
78
79
|
|
|
79
80
|
response = self.send_request(serialized_request)
|
|
@@ -100,6 +101,7 @@ class PurchasesService(BaseService):
|
|
|
100
101
|
Serializer(f"{self.base_url}/purchases", self.get_default_headers())
|
|
101
102
|
.serialize()
|
|
102
103
|
.set_method("POST")
|
|
104
|
+
.set_scopes({})
|
|
103
105
|
.set_body(request_body)
|
|
104
106
|
)
|
|
105
107
|
|
|
@@ -125,6 +127,7 @@ class PurchasesService(BaseService):
|
|
|
125
127
|
Serializer(f"{self.base_url}/purchases/topup", self.get_default_headers())
|
|
126
128
|
.serialize()
|
|
127
129
|
.set_method("POST")
|
|
130
|
+
.set_scopes({})
|
|
128
131
|
.set_body(request_body)
|
|
129
132
|
)
|
|
130
133
|
|
|
@@ -152,6 +155,7 @@ class PurchasesService(BaseService):
|
|
|
152
155
|
Serializer(f"{self.base_url}/purchases/edit", self.get_default_headers())
|
|
153
156
|
.serialize()
|
|
154
157
|
.set_method("POST")
|
|
158
|
+
.set_scopes({})
|
|
155
159
|
.set_body(request_body)
|
|
156
160
|
)
|
|
157
161
|
|
|
@@ -183,6 +187,7 @@ class PurchasesService(BaseService):
|
|
|
183
187
|
.add_path("purchaseId", purchase_id)
|
|
184
188
|
.serialize()
|
|
185
189
|
.set_method("GET")
|
|
190
|
+
.set_scopes({})
|
|
186
191
|
)
|
|
187
192
|
|
|
188
193
|
response = self.send_request(serialized_request)
|
|
@@ -7,6 +7,8 @@ from ...net.request_chain.request_chain import RequestChain
|
|
|
7
7
|
from ...net.request_chain.handlers.hook_handler import HookHandler
|
|
8
8
|
from ...net.request_chain.handlers.http_handler import HttpHandler
|
|
9
9
|
from ...net.request_chain.handlers.retry_handler import RetryHandler
|
|
10
|
+
from ...net.oauth.token_manager import TokenManager
|
|
11
|
+
from ...net.request_chain.handlers.oauth_handler import OauthHandler
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
class BaseService:
|
|
@@ -17,7 +19,7 @@ class BaseService:
|
|
|
17
19
|
:ivar dict _default_headers: A dictionary of default headers.
|
|
18
20
|
"""
|
|
19
21
|
|
|
20
|
-
def __init__(self, base_url: str) -> None:
|
|
22
|
+
def __init__(self, base_url: str, token_manager: TokenManager) -> None:
|
|
21
23
|
"""
|
|
22
24
|
Initializes a BaseService instance.
|
|
23
25
|
|
|
@@ -29,6 +31,8 @@ class BaseService:
|
|
|
29
31
|
|
|
30
32
|
self._additional_variables = {}
|
|
31
33
|
|
|
34
|
+
self._token_manager = token_manager
|
|
35
|
+
|
|
32
36
|
self._update_request_handler()
|
|
33
37
|
|
|
34
38
|
def set_additional_variables(
|
|
@@ -101,6 +105,7 @@ class BaseService:
|
|
|
101
105
|
return (
|
|
102
106
|
RequestChain()
|
|
103
107
|
.add_handler(RetryHandler())
|
|
108
|
+
.add_handler(OauthHandler(self._token_manager))
|
|
104
109
|
.add_handler(HookHandler(self._additional_variables))
|
|
105
110
|
.add_handler(HttpHandler(self._timeout))
|
|
106
111
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: celitech-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.4
|
|
4
4
|
Summary: Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/)
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.7
|
|
@@ -8,14 +8,14 @@ Description-Content-Type: text/markdown
|
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Dist: requests>=2.31.0
|
|
10
10
|
|
|
11
|
-
# Celitech Python SDK 1.
|
|
11
|
+
# Celitech Python SDK 1.3.4<a id="celitech-python-sdk-134"></a>
|
|
12
12
|
|
|
13
13
|
Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
|
|
14
14
|
|
|
15
15
|
## Versions<a id="versions"></a>
|
|
16
16
|
|
|
17
17
|
- API version: `1.1.0`
|
|
18
|
-
- SDK version: `1.
|
|
18
|
+
- SDK version: `1.3.4`
|
|
19
19
|
|
|
20
20
|
## About the API<a id="about-the-api"></a>
|
|
21
21
|
|
|
@@ -26,6 +26,8 @@ Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.
|
|
|
26
26
|
- [Setup & Configuration](#setup--configuration)
|
|
27
27
|
- [Supported Language Versions](#supported-language-versions)
|
|
28
28
|
- [Installation](#installation)
|
|
29
|
+
- [Authentication](#authentication)
|
|
30
|
+
- [OAuth Authentication](#oauth-authentication)
|
|
29
31
|
- [Environment Variables](#environment-variables)
|
|
30
32
|
- [Setting a Custom Timeout](#setting-a-custom-timeout)
|
|
31
33
|
- [Sample Usage](#sample-usage)
|
|
@@ -47,6 +49,30 @@ To get started with the SDK, we recommend installing using `pip`:
|
|
|
47
49
|
pip install celitech-sdk
|
|
48
50
|
```
|
|
49
51
|
|
|
52
|
+
## Authentication<a id="authentication"></a>
|
|
53
|
+
|
|
54
|
+
### OAuth Authentication<a id="oauth-authentication"></a>
|
|
55
|
+
|
|
56
|
+
The Celitech API uses OAuth for authentication.
|
|
57
|
+
|
|
58
|
+
You need to provide the OAuth parameters when initializing the SDK.
|
|
59
|
+
|
|
60
|
+
```py
|
|
61
|
+
sdk = Celitech(
|
|
62
|
+
client_id="client-id",
|
|
63
|
+
client_secret="client-secret",
|
|
64
|
+
client_id="CLIENT_ID",
|
|
65
|
+
client_secret="CLIENT_SECRET"
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If you need to set or update the OAuth parameters after the SDK initialization, you can use:
|
|
70
|
+
|
|
71
|
+
```py
|
|
72
|
+
sdk.set_client_id("CLIENT_ID")
|
|
73
|
+
sdk.set_client_secret("CLIENT_SECRET")
|
|
74
|
+
```
|
|
75
|
+
|
|
50
76
|
## Environment Variables<a id="environment-variables"></a>
|
|
51
77
|
|
|
52
78
|
These are the environment variables for the SDK:
|
|
@@ -79,7 +105,9 @@ from celitech import Celitech
|
|
|
79
105
|
|
|
80
106
|
sdk = Celitech(
|
|
81
107
|
client_id="client-id",
|
|
82
|
-
client_secret="client-secret"
|
|
108
|
+
client_secret="client-secret",
|
|
109
|
+
client_id="CLIENT_ID",
|
|
110
|
+
client_secret="CLIENT_SECRET"
|
|
83
111
|
)
|
|
84
112
|
|
|
85
113
|
result = sdk.destinations.list_destinations()
|
|
@@ -97,6 +125,7 @@ The SDK provides various services to interact with the API.
|
|
|
97
125
|
|
|
98
126
|
| Name |
|
|
99
127
|
| :----------- |
|
|
128
|
+
| o_auth |
|
|
100
129
|
| destinations |
|
|
101
130
|
| packages |
|
|
102
131
|
| purchases |
|
|
@@ -113,6 +142,8 @@ The SDK includes several models that represent the data structures used in API r
|
|
|
113
142
|
|
|
114
143
|
| Name | Description |
|
|
115
144
|
| :------------------------------- | :---------- |
|
|
145
|
+
| GetAccessTokenRequest | |
|
|
146
|
+
| GetAccessTokenOkResponse | |
|
|
116
147
|
| ListDestinationsOkResponse | |
|
|
117
148
|
| ListPackagesOkResponse | |
|
|
118
149
|
| ListPurchasesOkResponse | |
|
|
@@ -11,6 +11,8 @@ src/celitech/models/create_purchase_ok_response.py
|
|
|
11
11
|
src/celitech/models/create_purchase_request.py
|
|
12
12
|
src/celitech/models/edit_purchase_ok_response.py
|
|
13
13
|
src/celitech/models/edit_purchase_request.py
|
|
14
|
+
src/celitech/models/get_access_token_ok_response.py
|
|
15
|
+
src/celitech/models/get_access_token_request.py
|
|
14
16
|
src/celitech/models/get_esim_device_ok_response.py
|
|
15
17
|
src/celitech/models/get_esim_history_ok_response.py
|
|
16
18
|
src/celitech/models/get_esim_mac_ok_response.py
|
|
@@ -31,12 +33,14 @@ src/celitech/net/environment/__init__.py
|
|
|
31
33
|
src/celitech/net/environment/environment.py
|
|
32
34
|
src/celitech/net/headers/__init__.py
|
|
33
35
|
src/celitech/net/headers/base_header.py
|
|
36
|
+
src/celitech/net/oauth/token_manager.py
|
|
34
37
|
src/celitech/net/request_chain/__init__.py
|
|
35
38
|
src/celitech/net/request_chain/request_chain.py
|
|
36
39
|
src/celitech/net/request_chain/handlers/__init__.py
|
|
37
40
|
src/celitech/net/request_chain/handlers/base_handler.py
|
|
38
41
|
src/celitech/net/request_chain/handlers/hook_handler.py
|
|
39
42
|
src/celitech/net/request_chain/handlers/http_handler.py
|
|
43
|
+
src/celitech/net/request_chain/handlers/oauth_handler.py
|
|
40
44
|
src/celitech/net/request_chain/handlers/retry_handler.py
|
|
41
45
|
src/celitech/net/transport/__init__.py
|
|
42
46
|
src/celitech/net/transport/request.py
|
|
@@ -47,6 +51,7 @@ src/celitech/net/transport/utils.py
|
|
|
47
51
|
src/celitech/services/__init__.py
|
|
48
52
|
src/celitech/services/destinations.py
|
|
49
53
|
src/celitech/services/e_sim.py
|
|
54
|
+
src/celitech/services/o_auth.py
|
|
50
55
|
src/celitech/services/packages.py
|
|
51
56
|
src/celitech/services/purchases.py
|
|
52
57
|
src/celitech/services/utils/__init__.py
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import os
|
|
3
|
-
from typing import Dict
|
|
4
|
-
import time
|
|
5
|
-
|
|
6
|
-
CURRENT_TOKEN = ""
|
|
7
|
-
CURRENT_EXPIRY = -1
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Request:
|
|
11
|
-
def __init__(self, method, url, headers, body=""):
|
|
12
|
-
self.method = method
|
|
13
|
-
self.url = url
|
|
14
|
-
self.headers = headers
|
|
15
|
-
self.body = body
|
|
16
|
-
|
|
17
|
-
def __str__(self):
|
|
18
|
-
return f"Request(method={self.method}, url={self.url}, headers={self.headers}, body={self.body})"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Response:
|
|
22
|
-
def __init__(self, status, headers, body):
|
|
23
|
-
self.status = status
|
|
24
|
-
self.headers = headers
|
|
25
|
-
self.body = body
|
|
26
|
-
|
|
27
|
-
def __str__(self):
|
|
28
|
-
return (
|
|
29
|
-
f"Response(status={self.status}, headers={self.headers}, body={self.body})"
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class CustomHook:
|
|
34
|
-
|
|
35
|
-
def getToken(self, client_id, client_secret):
|
|
36
|
-
full_url = "https://auth.celitech.net/oauth2/token"
|
|
37
|
-
headers = {"Content-type": "application/x-www-form-urlencoded"}
|
|
38
|
-
data = {
|
|
39
|
-
"client_id": client_id,
|
|
40
|
-
"client_secret": client_secret,
|
|
41
|
-
"grant_type": "client_credentials",
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
resp = requests.post(full_url, headers=headers, data=data)
|
|
45
|
-
return resp.json()
|
|
46
|
-
|
|
47
|
-
def before_request(self, request: Request, **kwargs):
|
|
48
|
-
client_id = kwargs.get("client_id")
|
|
49
|
-
client_secret = kwargs.get("client_secret")
|
|
50
|
-
|
|
51
|
-
if not client_id or not client_secret:
|
|
52
|
-
raise Exception(
|
|
53
|
-
"Missing client_id and/or client_secret constructor parameters"
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
global CURRENT_TOKEN, CURRENT_EXPIRY
|
|
57
|
-
|
|
58
|
-
if not CURRENT_TOKEN or CURRENT_EXPIRY < round(time.time() * 1000):
|
|
59
|
-
|
|
60
|
-
token_response = self.getToken(client_id, client_secret)
|
|
61
|
-
|
|
62
|
-
if token_response.get("error"):
|
|
63
|
-
raise Exception(token_response.get("error"))
|
|
64
|
-
|
|
65
|
-
expires_in = token_response.get("expires_in")
|
|
66
|
-
access_token = token_response.get("access_token")
|
|
67
|
-
|
|
68
|
-
if not expires_in or not access_token:
|
|
69
|
-
raise Exception("There is an issue with getting the oauth token")
|
|
70
|
-
|
|
71
|
-
CURRENT_EXPIRY = round(time.time() * 1000) + expires_in * 1000
|
|
72
|
-
CURRENT_TOKEN = access_token
|
|
73
|
-
|
|
74
|
-
authorization = f"Bearer {CURRENT_TOKEN}"
|
|
75
|
-
|
|
76
|
-
request.headers.update({"Authorization": authorization})
|
|
77
|
-
|
|
78
|
-
def after_response(self, request: Request, response: Response, **kwargs):
|
|
79
|
-
pass
|
|
80
|
-
|
|
81
|
-
def on_error(
|
|
82
|
-
self, error: Exception, request: Request, response: Response, **kwargs
|
|
83
|
-
):
|
|
84
|
-
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/create_purchase_ok_response.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_esim_device_ok_response.py
RENAMED
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/get_esim_history_ok_response.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/models/list_destinations_ok_response.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/__init__.py
RENAMED
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/base_handler.py
RENAMED
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/http_handler.py
RENAMED
|
File without changes
|
{celitech_sdk-1.2.5 → celitech_sdk-1.3.4}/src/celitech/net/request_chain/handlers/retry_handler.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|