-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
47 lines (34 loc) · 1.25 KB
/
config.py
File metadata and controls
47 lines (34 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
from typing import Dict
# USPS API Configuration
USPS_API_CONFIG = {
'base_url': os.getenv('USPS_API_BASE_URL', 'https://apis.usps.com'),
'test_url': os.getenv('USPS_API_TEST_URL', 'https://apis-tem.usps.com'),
}
# API Version paths
API_VERSIONS = {
'oauth': '/oauth2/v3',
'tracking': '/tracking/v3',
'payments': '/payments/v3',
}
def get_api_url(service: str, use_test: bool = False) -> str:
"""
Get the full API URL for a specific service.
Args:
service (str): The service name (e.g., 'oauth', 'tracking', 'payments')
use_test (bool): Whether to use the test environment URL
Returns:
str: The complete API URL
"""
base = USPS_API_CONFIG['test_url'] if use_test else USPS_API_CONFIG['base_url']
version = API_VERSIONS.get(service)
if not version:
raise ValueError(f"Unknown service: {service}")
return f"{base}{version}"
# Convenience functions for common endpoints
def get_oauth_url(use_test: bool = False) -> str:
return f"{get_api_url('oauth', use_test)}/token"
def get_tracking_url(use_test: bool = False) -> str:
return get_api_url('tracking', use_test)
def get_payments_url(use_test: bool = False) -> str:
return get_api_url('payments', use_test)