apiverve-cryptogramgenerator 1.2.2__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.
- apiverve_cryptogramgenerator/__init__.py +3 -0
- apiverve_cryptogramgenerator/apiClient.py +253 -0
- apiverve_cryptogramgenerator/exceptions.py +3 -0
- apiverve_cryptogramgenerator/setup.py +26 -0
- apiverve_cryptogramgenerator/setup_dep.py +21 -0
- apiverve_cryptogramgenerator/tests/__init__.py +1 -0
- apiverve_cryptogramgenerator/tests/test_api.py +19 -0
- apiverve_cryptogramgenerator-1.2.2.dist-info/METADATA +359 -0
- apiverve_cryptogramgenerator-1.2.2.dist-info/RECORD +12 -0
- apiverve_cryptogramgenerator-1.2.2.dist-info/WHEEL +5 -0
- apiverve_cryptogramgenerator-1.2.2.dist-info/licenses/LICENSE +21 -0
- apiverve_cryptogramgenerator-1.2.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Dict, Optional, Any, List
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CryptogramAPIClientError(Exception):
|
|
8
|
+
"""Custom exception for API client errors"""
|
|
9
|
+
def __init__(self, message: str, status_code: Optional[int] = None, response: Optional[Dict] = None):
|
|
10
|
+
self.message = message
|
|
11
|
+
self.status_code = status_code
|
|
12
|
+
self.response = response
|
|
13
|
+
super().__init__(self.message)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ValidationError(CryptogramAPIClientError):
|
|
17
|
+
"""Custom exception for parameter validation errors"""
|
|
18
|
+
def __init__(self, errors: List[str]):
|
|
19
|
+
self.errors = errors
|
|
20
|
+
message = f"Validation failed: {' '.join(errors)}"
|
|
21
|
+
super().__init__(message)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CryptogramAPIClient:
|
|
25
|
+
# Validation rules for parameters (generated from schema)
|
|
26
|
+
VALIDATION_RULES = {
|
|
27
|
+
"text": {"type": "string", "required": False, "maxLength": 500},
|
|
28
|
+
"random": {"type": "boolean", "required": False, "default": False},
|
|
29
|
+
"image": {"type": "boolean", "required": False, "default": False},
|
|
30
|
+
"solutionImage": {"type": "boolean", "required": False, "default": False}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Format validation patterns
|
|
34
|
+
FORMAT_PATTERNS = {
|
|
35
|
+
'email': r'^[^\s@]+@[^\s@]+\.[^\s@]+$',
|
|
36
|
+
'url': r'^https?://.+',
|
|
37
|
+
'ip': r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$',
|
|
38
|
+
'date': r'^\d{4}-\d{2}-\d{2}$',
|
|
39
|
+
'hexColor': r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
def __init__(self, api_key: str, secure: bool = True, debug: bool = False):
|
|
43
|
+
"""
|
|
44
|
+
Initialize the CryptogramAPIClient with the API key and optional settings
|
|
45
|
+
|
|
46
|
+
:param api_key: Your APIVerve API key
|
|
47
|
+
:param secure: Deprecated. Always set to True
|
|
48
|
+
:param debug: Enable debug logging (default: False)
|
|
49
|
+
:raises CryptogramAPIClientError: If API key is invalid
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
self._validate_api_key(api_key)
|
|
53
|
+
|
|
54
|
+
self.api_key = api_key
|
|
55
|
+
self.secure = secure
|
|
56
|
+
self.debug = debug
|
|
57
|
+
self.base_url = 'https://api.apiverve.com/v1/cryptogram'
|
|
58
|
+
self.headers = {
|
|
59
|
+
'x-api-key': self.api_key,
|
|
60
|
+
'auth-mode': 'pypi-package'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Create a session for connection pooling
|
|
64
|
+
self.session = requests.Session()
|
|
65
|
+
self.session.headers.update(self.headers)
|
|
66
|
+
|
|
67
|
+
def _validate_api_key(self, api_key: str) -> None:
|
|
68
|
+
"""
|
|
69
|
+
Validate the API key format
|
|
70
|
+
|
|
71
|
+
:param api_key: API key to validate
|
|
72
|
+
:raises CryptogramAPIClientError: If API key is invalid
|
|
73
|
+
"""
|
|
74
|
+
if not api_key or not api_key.strip():
|
|
75
|
+
raise CryptogramAPIClientError(
|
|
76
|
+
"API key is required. Get your API key at: https://apiverve.com"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Check format (GUID, prefixed keys like apv_xxx, or alphanumeric)
|
|
80
|
+
if not re.match(r'^[a-zA-Z0-9_-]+$', api_key):
|
|
81
|
+
raise CryptogramAPIClientError(
|
|
82
|
+
"Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores. "
|
|
83
|
+
"Get your API key at: https://apiverve.com"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
def _log(self, message: str) -> None:
|
|
87
|
+
"""
|
|
88
|
+
Log a debug message if debug mode is enabled
|
|
89
|
+
|
|
90
|
+
:param message: Message to log
|
|
91
|
+
"""
|
|
92
|
+
if self.debug:
|
|
93
|
+
print(f"[CryptogramAPIClient DEBUG] {message}")
|
|
94
|
+
|
|
95
|
+
def _validate_params(self, params: Optional[Dict[str, Any]]) -> None:
|
|
96
|
+
"""
|
|
97
|
+
Validate parameters against schema rules
|
|
98
|
+
|
|
99
|
+
:param params: Parameters to validate
|
|
100
|
+
:raises ValidationError: If validation fails
|
|
101
|
+
"""
|
|
102
|
+
if not self.VALIDATION_RULES:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
errors = []
|
|
106
|
+
params = params or {}
|
|
107
|
+
|
|
108
|
+
for param_name, rules in self.VALIDATION_RULES.items():
|
|
109
|
+
value = params.get(param_name)
|
|
110
|
+
|
|
111
|
+
# Check required
|
|
112
|
+
if rules.get('required') and (value is None or value == ''):
|
|
113
|
+
errors.append(f"Required parameter [{param_name}] is missing.")
|
|
114
|
+
continue
|
|
115
|
+
|
|
116
|
+
# Skip validation if value is not provided and not required
|
|
117
|
+
if value is None:
|
|
118
|
+
continue
|
|
119
|
+
|
|
120
|
+
param_type = rules.get('type', 'string')
|
|
121
|
+
|
|
122
|
+
# Type validation
|
|
123
|
+
if param_type in ('integer', 'number'):
|
|
124
|
+
try:
|
|
125
|
+
num_value = float(value) if param_type == 'number' else int(value)
|
|
126
|
+
|
|
127
|
+
# Min/max validation
|
|
128
|
+
if 'min' in rules and num_value < rules['min']:
|
|
129
|
+
errors.append(f"Parameter [{param_name}] must be at least {rules['min']}.")
|
|
130
|
+
if 'max' in rules and num_value > rules['max']:
|
|
131
|
+
errors.append(f"Parameter [{param_name}] must be at most {rules['max']}.")
|
|
132
|
+
except (ValueError, TypeError):
|
|
133
|
+
errors.append(f"Parameter [{param_name}] must be a valid {param_type}.")
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
elif param_type == 'string':
|
|
137
|
+
if not isinstance(value, str):
|
|
138
|
+
errors.append(f"Parameter [{param_name}] must be a string.")
|
|
139
|
+
continue
|
|
140
|
+
|
|
141
|
+
# Length validation
|
|
142
|
+
if 'minLength' in rules and len(value) < rules['minLength']:
|
|
143
|
+
errors.append(f"Parameter [{param_name}] must be at least {rules['minLength']} characters.")
|
|
144
|
+
if 'maxLength' in rules and len(value) > rules['maxLength']:
|
|
145
|
+
errors.append(f"Parameter [{param_name}] must be at most {rules['maxLength']} characters.")
|
|
146
|
+
|
|
147
|
+
# Format validation
|
|
148
|
+
if 'format' in rules and rules['format'] in self.FORMAT_PATTERNS:
|
|
149
|
+
pattern = self.FORMAT_PATTERNS[rules['format']]
|
|
150
|
+
if not re.match(pattern, value, re.IGNORECASE):
|
|
151
|
+
errors.append(f"Parameter [{param_name}] must be a valid {rules['format']}.")
|
|
152
|
+
|
|
153
|
+
elif param_type == 'boolean':
|
|
154
|
+
if not isinstance(value, bool) and value not in ('true', 'false', True, False):
|
|
155
|
+
errors.append(f"Parameter [{param_name}] must be a boolean.")
|
|
156
|
+
|
|
157
|
+
elif param_type == 'array':
|
|
158
|
+
if not isinstance(value, list):
|
|
159
|
+
errors.append(f"Parameter [{param_name}] must be an array.")
|
|
160
|
+
|
|
161
|
+
# Enum validation
|
|
162
|
+
if 'enum' in rules and value not in rules['enum']:
|
|
163
|
+
errors.append(f"Parameter [{param_name}] must be one of: {', '.join(map(str, rules['enum']))}.")
|
|
164
|
+
|
|
165
|
+
if errors:
|
|
166
|
+
raise ValidationError(errors)
|
|
167
|
+
|
|
168
|
+
def execute(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: # Returns CryptogramGeneratorData in 'data' field
|
|
169
|
+
"""
|
|
170
|
+
Execute the API request
|
|
171
|
+
|
|
172
|
+
:param params: API parameters (optional)
|
|
173
|
+
:return: API response as a dictionary
|
|
174
|
+
:raises CryptogramAPIClientError: If the request fails or returns an error
|
|
175
|
+
:raises ValidationError: If parameter validation fails
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
# Validate parameters against schema rules
|
|
179
|
+
self._validate_params(params)
|
|
180
|
+
|
|
181
|
+
method = "GET"
|
|
182
|
+
|
|
183
|
+
self._log(f"Making {method} request to {self.base_url}")
|
|
184
|
+
if params:
|
|
185
|
+
self._log(f"Parameters: {params}")
|
|
186
|
+
|
|
187
|
+
try:
|
|
188
|
+
if method.upper() == 'POST':
|
|
189
|
+
self._log("Sending POST request with JSON body")
|
|
190
|
+
response = self.session.post(self.base_url, json=params, timeout=30)
|
|
191
|
+
else:
|
|
192
|
+
self._log("Sending GET request with query parameters")
|
|
193
|
+
response = self.session.get(self.base_url, params=params, timeout=30)
|
|
194
|
+
|
|
195
|
+
self._log(f"Response status code: {response.status_code}")
|
|
196
|
+
|
|
197
|
+
# Try to parse JSON response
|
|
198
|
+
try:
|
|
199
|
+
response_data = response.json()
|
|
200
|
+
except ValueError as e:
|
|
201
|
+
raise CryptogramAPIClientError(
|
|
202
|
+
f"Invalid JSON response from API: {str(e)}",
|
|
203
|
+
status_code=response.status_code
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
# Check for API-level errors in the response
|
|
207
|
+
if response_data.get('status') == 'error':
|
|
208
|
+
error_message = response_data.get('error', 'Unknown API error')
|
|
209
|
+
self._log(f"API returned error: {error_message}")
|
|
210
|
+
raise CryptogramAPIClientError(
|
|
211
|
+
error_message,
|
|
212
|
+
status_code=response.status_code,
|
|
213
|
+
response=response_data
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
# Check HTTP status code
|
|
217
|
+
if not response.ok:
|
|
218
|
+
error_message = response_data.get('error', f"HTTP {response.status_code} error")
|
|
219
|
+
self._log(f"HTTP error: {error_message}")
|
|
220
|
+
raise CryptogramAPIClientError(
|
|
221
|
+
error_message,
|
|
222
|
+
status_code=response.status_code,
|
|
223
|
+
response=response_data
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
self._log("Request successful")
|
|
227
|
+
return response_data
|
|
228
|
+
|
|
229
|
+
except requests.exceptions.Timeout as e:
|
|
230
|
+
self._log(f"Request timeout: {str(e)}")
|
|
231
|
+
raise CryptogramAPIClientError(f"Request timeout: {str(e)}")
|
|
232
|
+
except requests.exceptions.ConnectionError as e:
|
|
233
|
+
self._log(f"Connection error: {str(e)}")
|
|
234
|
+
raise CryptogramAPIClientError(f"Connection error: {str(e)}")
|
|
235
|
+
except requests.exceptions.RequestException as e:
|
|
236
|
+
self._log(f"Request exception: {str(e)}")
|
|
237
|
+
raise CryptogramAPIClientError(f"Request failed: {str(e)}")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def close(self) -> None:
|
|
241
|
+
"""
|
|
242
|
+
Close the session and release resources
|
|
243
|
+
"""
|
|
244
|
+
self._log("Closing session")
|
|
245
|
+
self.session.close()
|
|
246
|
+
|
|
247
|
+
def __enter__(self):
|
|
248
|
+
"""Context manager entry"""
|
|
249
|
+
return self
|
|
250
|
+
|
|
251
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
252
|
+
"""Context manager exit"""
|
|
253
|
+
self.close()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
lib_folder = os.path.dirname(os.path.realpath(__file__))
|
|
5
|
+
requirements_file = os.path.join(lib_folder, 'requirements.txt')
|
|
6
|
+
install_requires = ["requests >= 2.25.1", "setuptools >= 56.0.0"]
|
|
7
|
+
if os.path.exists(requirements_file):
|
|
8
|
+
with open(requirements_file, 'r') as f:
|
|
9
|
+
install_requires = f.read().splitlines()
|
|
10
|
+
|
|
11
|
+
setup(
|
|
12
|
+
name='apiverve_cryptogramgenerator',
|
|
13
|
+
version='1.2.2',
|
|
14
|
+
packages=find_packages(),
|
|
15
|
+
include_package_data=True,
|
|
16
|
+
install_requires=install_requires,
|
|
17
|
+
description='Cryptogram Generator creates letter substitution cipher puzzles where each letter is replaced with another letter consistently throughout the text.',
|
|
18
|
+
author='APIVerve',
|
|
19
|
+
author_email='hello@apiverve.com',
|
|
20
|
+
url='https://apiverve.com/marketplace/cryptogram?utm_source=pypi&utm_medium=referral&utm_content=homepage',
|
|
21
|
+
classifiers=[
|
|
22
|
+
'Programming Language :: Python :: 3',
|
|
23
|
+
'Operating System :: OS Independent',
|
|
24
|
+
],
|
|
25
|
+
python_requires='>=3.6',
|
|
26
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='apiverve_cryptogramgenerator',
|
|
5
|
+
version='1.2.2',
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
include_package_data=True,
|
|
8
|
+
install_requires=[
|
|
9
|
+
'requests',
|
|
10
|
+
'setuptools'
|
|
11
|
+
],
|
|
12
|
+
description='Cryptogram Generator creates letter substitution cipher puzzles where each letter is replaced with another letter consistently throughout the text.',
|
|
13
|
+
author='APIVerve',
|
|
14
|
+
author_email='hello@apiverve.com',
|
|
15
|
+
url='https://apiverve.com/marketplace/cryptogram?utm_source=pypi&utm_medium=referral&utm_content=homepage',
|
|
16
|
+
classifiers=[
|
|
17
|
+
'Programming Language :: Python :: 3',
|
|
18
|
+
'Operating System :: OS Independent',
|
|
19
|
+
],
|
|
20
|
+
python_requires='>=3.6',
|
|
21
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Initialize test module
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient
|
|
3
|
+
|
|
4
|
+
class TestClient(unittest.TestCase):
|
|
5
|
+
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.api_key = 'test_api_key'
|
|
8
|
+
self.client = CryptogramAPIClient(self.api_key)
|
|
9
|
+
|
|
10
|
+
def test_get(self):
|
|
11
|
+
# Assuming there's an endpoint 'test_endpoint' for testing purposes
|
|
12
|
+
try:
|
|
13
|
+
response = self.client.get('test_endpoint')
|
|
14
|
+
self.assertIsInstance(response, dict)
|
|
15
|
+
except Exception as e:
|
|
16
|
+
self.fail(f"GET request failed with exception {e}")
|
|
17
|
+
|
|
18
|
+
if __name__ == '__main__':
|
|
19
|
+
unittest.main()
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apiverve-cryptogramgenerator
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Cryptogram Generator creates letter substitution cipher puzzles where each letter is replaced with another letter consistently throughout the text.
|
|
5
|
+
Author-email: APIVerve <hello@apiverve.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://apiverve.com/marketplace/cryptogram?utm_source=pypi&utm_medium=referral&utm_content=homepage
|
|
8
|
+
Project-URL: Documentation, https://docs.apiverve.com/ref/cryptogram?utm_source=pypi&utm_medium=referral&utm_content=docs
|
|
9
|
+
Project-URL: Repository, https://github.com/apiverve/cryptogram-api
|
|
10
|
+
Project-URL: Twitter, https://twitter.com/apivervehq
|
|
11
|
+
Keywords: cryptogram,cipher,code puzzle,substitution cipher,decode
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Natural Language :: English
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: requests>=2.25.0
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
Cryptogram Generator API
|
|
26
|
+
============
|
|
27
|
+
|
|
28
|
+
Cryptogram Generator creates letter substitution cipher puzzles where each letter is replaced with another letter consistently throughout the text.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/apiverve-cryptogramgenerator/)
|
|
32
|
+
|
|
33
|
+
This is a Python wrapper for the [Cryptogram Generator API](https://apiverve.com/marketplace/cryptogram?utm_source=pypi&utm_medium=referral&utm_content=readme)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
Using `pip`:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install apiverve-cryptogramgenerator
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Using `pip3`:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip3 install apiverve-cryptogramgenerator
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
Before using the Cryptogram Generator API client, you have to setup your account and obtain your API Key.
|
|
56
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=pypi&utm_medium=referral&utm_content=readme)
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
Here's a simple example to get you started quickly:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient
|
|
66
|
+
|
|
67
|
+
# Initialize the client with your APIVerve API key
|
|
68
|
+
api = CryptogramAPIClient("[YOUR_API_KEY]")
|
|
69
|
+
|
|
70
|
+
query = {
|
|
71
|
+
"text": "The quick brown fox",
|
|
72
|
+
"random": true,
|
|
73
|
+
"image": true,
|
|
74
|
+
"solutionImage": true
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
# Make the API call
|
|
79
|
+
result = api.execute(query)
|
|
80
|
+
|
|
81
|
+
# Print the result
|
|
82
|
+
print(result)
|
|
83
|
+
except Exception as e:
|
|
84
|
+
print(f"Error: {e}")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
The Cryptogram Generator API documentation is found here: [https://docs.apiverve.com/ref/cryptogram](https://docs.apiverve.com/ref/cryptogram?utm_source=pypi&utm_medium=referral&utm_content=readme).
|
|
92
|
+
You can find parameters, example responses, and status codes documented here.
|
|
93
|
+
|
|
94
|
+
### Setup
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# Import the client module
|
|
98
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient
|
|
99
|
+
|
|
100
|
+
# Initialize the client with your APIVerve API key
|
|
101
|
+
api = CryptogramAPIClient("[YOUR_API_KEY]")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Perform Request
|
|
107
|
+
|
|
108
|
+
Using the API client, you can perform requests to the API.
|
|
109
|
+
|
|
110
|
+
###### Define Query
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
query = {
|
|
114
|
+
"text": "The quick brown fox",
|
|
115
|
+
"random": true,
|
|
116
|
+
"image": true,
|
|
117
|
+
"solutionImage": true
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
###### Simple Request
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
# Make a request to the API
|
|
125
|
+
result = api.execute(query)
|
|
126
|
+
|
|
127
|
+
# Print the result
|
|
128
|
+
print(result)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
###### Example Response
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"status": "ok",
|
|
136
|
+
"error": null,
|
|
137
|
+
"data": {
|
|
138
|
+
"encoded": "PNR MJSXQRV JI K PNJSGKQC DBFRG ARWBQG ZBPN K GBQWFR GPRY",
|
|
139
|
+
"original": "The journey of a thousand miles begins with a single step",
|
|
140
|
+
"cipher": {
|
|
141
|
+
"A": "K",
|
|
142
|
+
"B": "A",
|
|
143
|
+
"C": "H",
|
|
144
|
+
"D": "C",
|
|
145
|
+
"E": "R",
|
|
146
|
+
"F": "I",
|
|
147
|
+
"G": "W",
|
|
148
|
+
"H": "N",
|
|
149
|
+
"I": "B",
|
|
150
|
+
"J": "M",
|
|
151
|
+
"K": "E",
|
|
152
|
+
"L": "F",
|
|
153
|
+
"M": "D",
|
|
154
|
+
"N": "Q",
|
|
155
|
+
"O": "J",
|
|
156
|
+
"P": "Y",
|
|
157
|
+
"Q": "T",
|
|
158
|
+
"R": "X",
|
|
159
|
+
"S": "G",
|
|
160
|
+
"T": "P",
|
|
161
|
+
"U": "S",
|
|
162
|
+
"V": "L",
|
|
163
|
+
"W": "Z",
|
|
164
|
+
"X": "O",
|
|
165
|
+
"Y": "V",
|
|
166
|
+
"Z": "U"
|
|
167
|
+
},
|
|
168
|
+
"letterCount": 47,
|
|
169
|
+
"wordCount": 11,
|
|
170
|
+
"html": "<html><head><title>Cryptogram Puzzle</title><style>body {font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin: 0 auto;}h1 {text-align: center;}.puzzle {font-family: monospace; font-size: 24px; letter-spacing: 3px; line-height: 2.5; word-wrap: break-word;}.letter-box {display: inline-block; text-align: center; margin: 2px;}.encoded {border-bottom: 2px solid #333; min-width: 20px; display: block;}.answer {color: #ccc; font-size: 14px;}.space {width: 15px; display: inline-block;}.hint {margin-top: 30px; padding: 15px; background: #f5f5f5; border-radius: 5px;}.hint h3 {margin-top: 0;}</style></head><body><h1>Cryptogram</h1><div class='puzzle'><span class='letter-box'><span class='encoded'>P</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>N</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>R</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>M</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>J</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>S</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>X</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>Q</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>R</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>V</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>J</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>I</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>K</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>P</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>N</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>J</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>S</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>G</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>K</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>Q</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>C</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>D</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>B</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>F</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>R</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>G</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>A</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>R</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>W</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>B</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>Q</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>G</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>Z</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>B</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>P</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>N</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>K</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>G</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>B</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>Q</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>W</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>F</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>R</span><span class='answer'>_</span></span><span class='space'></span><span class='letter-box'><span class='encoded'>G</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>P</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>R</span><span class='answer'>_</span></span><span class='letter-box'><span class='encoded'>Y</span><span class='answer'>_</span></span></div><div class='hint'><h3>Letter Frequency:</h3><p>R=6, G=5, P=4, Q=4, B=4, N=3, J=3, K=3, S=2, F=2, W=2, M=1, X=1, V=1, I=1, C=1, D=1, A=1, Z=1, Y=1</p></div></body></html>",
|
|
171
|
+
"image": {
|
|
172
|
+
"imageName": "0afa5de4-52fb-4902-8139-c177c08ac98b_puzzle.png",
|
|
173
|
+
"format": ".png",
|
|
174
|
+
"downloadURL": "https://storage.googleapis.com/apiverve/APIData/cryptogram/0afa5de4-52fb-4902-8139-c177c08ac98b_puzzle.png?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1766010132&Signature=guv7GNCup4lJXTI0iCF7Bo2Cz02Wl6h2HWC0YxJ0jtzb7w%2BlW80b1OzBlGR%2BneFxFdzQPwfIuMQlaHsW0KFqPh5ITsFkSt802OEUFyxuiDn71y4XkiJx8zVDhrxNH9R9i1befMM16c%2F4WQGpgzkaaXw8TJJUT2q2s8c8ESo41K85iYcHJZ%2BGUxXeMeFDJ%2FG38pq5txarX%2F0rnmdTk0Jk%2BhEox9PXFPCzaSvWbDFYDVABIt97N2NQyqlDPRcucrm5uuE5Jb9qjT80JqzlumfqiaR3DpgPDwZkWeVyuYW4b4TZCCbbEpK%2FIlRRUZTw9gYdxDpk0B35NKN9WKSCi%2BfFWQ%3D%3D",
|
|
175
|
+
"expires": 1766010132300
|
|
176
|
+
},
|
|
177
|
+
"solutionImage": {
|
|
178
|
+
"imageName": "41e6b5b7-d98c-4d4d-8b44-f56bdb5160b9_solution.png",
|
|
179
|
+
"format": ".png",
|
|
180
|
+
"downloadURL": "https://storage.googleapis.com/apiverve/APIData/cryptogram/41e6b5b7-d98c-4d4d-8b44-f56bdb5160b9_solution.png?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1766010132&Signature=YKDpJF9MYlmXjASdgVUgtPCq8%2Fp59Eci6DIAbXuHzv9B4rALSZwyq1sMj9KoIRhryYCdNW1KGBRpcgJFSFgaEGfcNC1MNsryoV%2F7bp3TSr1%2BknwqAGQu7sWvZrtozB2oJ3Wzaqz%2BGjm74rhrOaqAx0w7%2BmJtimslEHCl8emRuZxmAhW9l8Wi%2Fv%2BsCmb7%2Bl5hj0njHSs6AWo3YtoZpWoNv7F49g1dQczrfj%2BFYW7bOoFMfcmysTz%2ByNpXECZFbvWJ3A2f0fql7itGLGK%2B%2BNlI6Q6WkQ1ye3c7skHB3DqT%2BWHLbJCm0vjbIVhIgq3Vo39ZADdogcd7uiklvEBriMFkwA%3D%3D",
|
|
181
|
+
"expires": 1766010132645
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Error Handling
|
|
190
|
+
|
|
191
|
+
The API client provides comprehensive error handling through the `CryptogramAPIClientError` exception. Here are some examples:
|
|
192
|
+
|
|
193
|
+
### Basic Error Handling
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient, CryptogramAPIClientError
|
|
197
|
+
|
|
198
|
+
api = CryptogramAPIClient("[YOUR_API_KEY]")
|
|
199
|
+
|
|
200
|
+
query = {
|
|
201
|
+
"text": "The quick brown fox",
|
|
202
|
+
"random": true,
|
|
203
|
+
"image": true,
|
|
204
|
+
"solutionImage": true
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
result = api.execute(query)
|
|
209
|
+
print("Success!")
|
|
210
|
+
print(result)
|
|
211
|
+
except CryptogramAPIClientError as e:
|
|
212
|
+
print(f"API Error: {e.message}")
|
|
213
|
+
if e.status_code:
|
|
214
|
+
print(f"Status Code: {e.status_code}")
|
|
215
|
+
if e.response:
|
|
216
|
+
print(f"Response: {e.response}")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Handling Specific Error Types
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient, CryptogramAPIClientError
|
|
223
|
+
|
|
224
|
+
api = CryptogramAPIClient("[YOUR_API_KEY]")
|
|
225
|
+
|
|
226
|
+
query = {
|
|
227
|
+
"text": "The quick brown fox",
|
|
228
|
+
"random": true,
|
|
229
|
+
"image": true,
|
|
230
|
+
"solutionImage": true
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
try:
|
|
234
|
+
result = api.execute(query)
|
|
235
|
+
|
|
236
|
+
# Check for successful response
|
|
237
|
+
if result.get('status') == 'success':
|
|
238
|
+
print("Request successful!")
|
|
239
|
+
print(result.get('data'))
|
|
240
|
+
else:
|
|
241
|
+
print(f"API returned an error: {result.get('error')}")
|
|
242
|
+
|
|
243
|
+
except CryptogramAPIClientError as e:
|
|
244
|
+
# Handle API client errors
|
|
245
|
+
if e.status_code == 401:
|
|
246
|
+
print("Unauthorized: Invalid API key")
|
|
247
|
+
elif e.status_code == 429:
|
|
248
|
+
print("Rate limit exceeded")
|
|
249
|
+
elif e.status_code >= 500:
|
|
250
|
+
print("Server error - please try again later")
|
|
251
|
+
else:
|
|
252
|
+
print(f"API error: {e.message}")
|
|
253
|
+
except Exception as e:
|
|
254
|
+
# Handle unexpected errors
|
|
255
|
+
print(f"Unexpected error: {str(e)}")
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Using Context Manager (Recommended)
|
|
259
|
+
|
|
260
|
+
The client supports the context manager protocol for automatic resource cleanup:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient, CryptogramAPIClientError
|
|
264
|
+
|
|
265
|
+
query = {
|
|
266
|
+
"text": "The quick brown fox",
|
|
267
|
+
"random": true,
|
|
268
|
+
"image": true,
|
|
269
|
+
"solutionImage": true
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
# Using context manager ensures proper cleanup
|
|
273
|
+
with CryptogramAPIClient("[YOUR_API_KEY]") as api:
|
|
274
|
+
try:
|
|
275
|
+
result = api.execute(query)
|
|
276
|
+
print(result)
|
|
277
|
+
except CryptogramAPIClientError as e:
|
|
278
|
+
print(f"Error: {e.message}")
|
|
279
|
+
# Session is automatically closed here
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Advanced Features
|
|
285
|
+
|
|
286
|
+
### Debug Mode
|
|
287
|
+
|
|
288
|
+
Enable debug logging to see detailed request and response information:
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient
|
|
292
|
+
|
|
293
|
+
# Enable debug mode
|
|
294
|
+
api = CryptogramAPIClient("[YOUR_API_KEY]", debug=True)
|
|
295
|
+
|
|
296
|
+
query = {
|
|
297
|
+
"text": "The quick brown fox",
|
|
298
|
+
"random": true,
|
|
299
|
+
"image": true,
|
|
300
|
+
"solutionImage": true
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
# Debug information will be printed to console
|
|
304
|
+
result = api.execute(query)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Manual Session Management
|
|
308
|
+
|
|
309
|
+
If you need to manually manage the session lifecycle:
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
from apiverve_cryptogramgenerator.apiClient import CryptogramAPIClient
|
|
313
|
+
|
|
314
|
+
api = CryptogramAPIClient("[YOUR_API_KEY]")
|
|
315
|
+
|
|
316
|
+
query = {
|
|
317
|
+
"text": "The quick brown fox",
|
|
318
|
+
"random": true,
|
|
319
|
+
"image": true,
|
|
320
|
+
"solutionImage": true
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
try:
|
|
324
|
+
result = api.execute(query)
|
|
325
|
+
print(result)
|
|
326
|
+
finally:
|
|
327
|
+
# Manually close the session when done
|
|
328
|
+
api.close()
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Customer Support
|
|
334
|
+
|
|
335
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=pypi&utm_medium=referral&utm_content=readme).
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Updates
|
|
340
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Legal
|
|
345
|
+
|
|
346
|
+
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=pypi&utm_medium=referral&utm_content=readme) and all legal documents and agreements.
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## License
|
|
351
|
+
Licensed under the MIT License (MIT)
|
|
352
|
+
|
|
353
|
+
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
354
|
+
|
|
355
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
356
|
+
|
|
357
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
358
|
+
|
|
359
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
apiverve_cryptogramgenerator/__init__.py,sha256=g7b-lMRM-h1Q_sB3lxUQoH60KQYIFQO-q04dPMBQ0uA,131
|
|
2
|
+
apiverve_cryptogramgenerator/apiClient.py,sha256=e3YqzcSTZd5o2YyG-VXQswnRaFJMnPhe_uwetKNkzkc,9966
|
|
3
|
+
apiverve_cryptogramgenerator/exceptions.py,sha256=1KdTEqihpsVO-9B-MEeVWeSqUejbGcRWrHOnUuMAcSA,109
|
|
4
|
+
apiverve_cryptogramgenerator/setup.py,sha256=LSYyUXTe4evCzsWDbRWIrfGLpPPC7SGiFamppzZMxHw,1033
|
|
5
|
+
apiverve_cryptogramgenerator/setup_dep.py,sha256=3tjH8KO6tO6y3LqpOrj_zg0QI69FEvyVIzXpPOvrSZc,736
|
|
6
|
+
apiverve_cryptogramgenerator/tests/__init__.py,sha256=5_6uOnBkgWAawI5-lr0N2cZ_UVvIGJ7NCh4XT5KF47o,25
|
|
7
|
+
apiverve_cryptogramgenerator/tests/test_api.py,sha256=jdhi1rnCl85MNRAj-Qxv0NlDR4OrxilvPut3fuRYFZk,604
|
|
8
|
+
apiverve_cryptogramgenerator-1.2.2.dist-info/licenses/LICENSE,sha256=V5x7AJRnWqzyPdD_hz1UOO2zYKZGOdRWdXElPTdwxwE,1092
|
|
9
|
+
apiverve_cryptogramgenerator-1.2.2.dist-info/METADATA,sha256=zKy2ynZReIgWg8k6dlEgRQfw7XljPSQPkxst755qwCc,16089
|
|
10
|
+
apiverve_cryptogramgenerator-1.2.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
11
|
+
apiverve_cryptogramgenerator-1.2.2.dist-info/top_level.txt,sha256=mnZAZvUU3711wk4S6ZjPZW0pRkWL48-tJ3Yjb_ulxfI,29
|
|
12
|
+
apiverve_cryptogramgenerator-1.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 APIVerve and EvlarSoft LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
apiverve_cryptogramgenerator
|