ai-lls-lib 1.5.0rc3__py3-none-any.whl → 1.5.0rc4__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.
Potentially problematic release.
This version of ai-lls-lib might be problematic. Click here for more details.
- ai_lls_lib/__init__.py +1 -1
- ai_lls_lib/cli/__main__.py +33 -1
- ai_lls_lib/cli/commands/verify.py +147 -54
- ai_lls_lib/cli/env_loader.py +3 -2
- ai_lls_lib/core/verifier.py +17 -11
- ai_lls_lib/providers/__init__.py +2 -1
- ai_lls_lib/providers/external.py +99 -35
- ai_lls_lib/providers/stub.py +1 -1
- {ai_lls_lib-1.5.0rc3.dist-info → ai_lls_lib-1.5.0rc4.dist-info}/METADATA +1 -1
- {ai_lls_lib-1.5.0rc3.dist-info → ai_lls_lib-1.5.0rc4.dist-info}/RECORD +12 -12
- {ai_lls_lib-1.5.0rc3.dist-info → ai_lls_lib-1.5.0rc4.dist-info}/WHEEL +0 -0
- {ai_lls_lib-1.5.0rc3.dist-info → ai_lls_lib-1.5.0rc4.dist-info}/entry_points.txt +0 -0
ai_lls_lib/__init__.py
CHANGED
|
@@ -17,7 +17,7 @@ from ai_lls_lib.core.verifier import PhoneVerifier
|
|
|
17
17
|
from ai_lls_lib.core.processor import BulkProcessor
|
|
18
18
|
from ai_lls_lib.core.cache import DynamoDBCache
|
|
19
19
|
|
|
20
|
-
__version__ = "1.5.0-rc.
|
|
20
|
+
__version__ = "1.5.0-rc.4"
|
|
21
21
|
__all__ = [
|
|
22
22
|
"PhoneVerification",
|
|
23
23
|
"BulkJob",
|
ai_lls_lib/cli/__main__.py
CHANGED
|
@@ -3,13 +3,45 @@ Landline Scrubber CLI entry point
|
|
|
3
3
|
"""
|
|
4
4
|
import click
|
|
5
5
|
import sys
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
6
8
|
from ai_lls_lib.cli.commands import verify, cache, admin, test_stack, stripe
|
|
9
|
+
from ai_lls_lib.cli.env_loader import load_env_file
|
|
10
|
+
|
|
11
|
+
def load_env_files(verbose=False):
|
|
12
|
+
"""Load .env files from ~/.lls and current directory"""
|
|
13
|
+
# Load from ~/.lls/.env
|
|
14
|
+
home_env = Path.home() / '.lls' / '.env'
|
|
15
|
+
if home_env.exists():
|
|
16
|
+
env_vars = load_env_file(home_env)
|
|
17
|
+
for key, value in env_vars.items():
|
|
18
|
+
if key not in os.environ: # Don't override existing env vars
|
|
19
|
+
os.environ[key] = value
|
|
20
|
+
if env_vars and verbose:
|
|
21
|
+
click.echo(f"Loaded {len(env_vars)} variables from {home_env}", err=True)
|
|
22
|
+
|
|
23
|
+
# Load from current directory .env
|
|
24
|
+
local_env = Path('.env')
|
|
25
|
+
if local_env.exists():
|
|
26
|
+
env_vars = load_env_file(local_env)
|
|
27
|
+
for key, value in env_vars.items():
|
|
28
|
+
if key not in os.environ: # Don't override existing env vars
|
|
29
|
+
os.environ[key] = value
|
|
30
|
+
if env_vars and verbose:
|
|
31
|
+
click.echo(f"Loaded {len(env_vars)} variables from {local_env}", err=True)
|
|
32
|
+
|
|
33
|
+
# Set default environment to 'prod' if not set
|
|
34
|
+
if 'ENVIRONMENT' not in os.environ:
|
|
35
|
+
os.environ['ENVIRONMENT'] = 'prod'
|
|
36
|
+
if verbose:
|
|
37
|
+
click.echo(f"Set default ENVIRONMENT=prod", err=True)
|
|
7
38
|
|
|
8
39
|
@click.group()
|
|
9
40
|
@click.version_option(version="0.1.0", prog_name="ai-lls")
|
|
10
41
|
def cli():
|
|
11
42
|
"""Landline Scrubber CLI - Administrative and debugging tools"""
|
|
12
|
-
|
|
43
|
+
# Load environment files at startup
|
|
44
|
+
load_env_files()
|
|
13
45
|
|
|
14
46
|
# Register command groups
|
|
15
47
|
cli.add_command(verify.verify_group)
|
|
@@ -7,6 +7,7 @@ from datetime import datetime
|
|
|
7
7
|
from ai_lls_lib.core.verifier import PhoneVerifier
|
|
8
8
|
from ai_lls_lib.core.cache import DynamoDBCache
|
|
9
9
|
from ai_lls_lib.cli.aws_client import AWSClient
|
|
10
|
+
from ai_lls_lib.providers import StubProvider, ExternalAPIProvider
|
|
10
11
|
|
|
11
12
|
@click.group(name="verify")
|
|
12
13
|
def verify_group():
|
|
@@ -15,72 +16,160 @@ def verify_group():
|
|
|
15
16
|
|
|
16
17
|
@verify_group.command(name="phone")
|
|
17
18
|
@click.argument("phone_number")
|
|
18
|
-
@click.option("--
|
|
19
|
-
@click.option("--
|
|
20
|
-
@click.option("--
|
|
21
|
-
@click.option("--
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
@click.option("--output", type=click.Choice(["json", "text"], case_sensitive=False), default="json", help="Output format")
|
|
20
|
+
@click.option("--provider", type=click.Choice(["external", "stub"], case_sensitive=False), default="external", help="Verification provider to use")
|
|
21
|
+
@click.option("--no-cache", is_flag=True, help="Disable caching even if AWS is available")
|
|
22
|
+
@click.option("--stack", default="landline-api", help="CloudFormation stack name (for caching)")
|
|
23
|
+
@click.option("--profile", help="AWS profile to use (for caching)")
|
|
24
|
+
@click.option("--region", help="AWS region (for caching)")
|
|
25
|
+
@click.option("--verbose", is_flag=True, help="Show detailed output")
|
|
26
|
+
def verify_phone(phone_number, output, provider, no_cache, stack, profile, region, verbose):
|
|
27
|
+
"""
|
|
28
|
+
Verify a phone number (works with or without AWS).
|
|
29
|
+
|
|
30
|
+
Accepts phone numbers in various formats:
|
|
31
|
+
- 6197966726 (10 digits)
|
|
32
|
+
- 16197966726 (11 digits with 1)
|
|
33
|
+
- +16197966726 (E.164 format)
|
|
34
|
+
- 619-796-6726 (with dashes)
|
|
35
|
+
- (619) 796-6726 (with parentheses)
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
# Select provider based on parameter
|
|
39
|
+
if provider == "stub":
|
|
40
|
+
provider_instance = StubProvider()
|
|
41
|
+
if verbose:
|
|
42
|
+
click.echo("Using StubProvider (deterministic test mode)")
|
|
43
|
+
else:
|
|
44
|
+
provider_instance = ExternalAPIProvider()
|
|
45
|
+
if verbose:
|
|
46
|
+
click.echo("Using ExternalAPIProvider (real API calls)")
|
|
47
|
+
|
|
48
|
+
# Try to set up caching if not explicitly disabled
|
|
49
|
+
cache = None
|
|
50
|
+
cache_status = ""
|
|
51
|
+
|
|
52
|
+
if not no_cache:
|
|
53
|
+
try:
|
|
54
|
+
aws = AWSClient(region=region, profile=profile)
|
|
55
|
+
cache_table = aws.get_table_name(stack, "PhoneCacheTable")
|
|
56
|
+
cache = DynamoDBCache(table_name=cache_table)
|
|
57
|
+
cache_status = "(Using cache)"
|
|
58
|
+
if verbose:
|
|
59
|
+
click.echo(f"Using DynamoDB cache table: {cache_table}")
|
|
60
|
+
except Exception as e:
|
|
61
|
+
cache_status = "(No cache - direct API call)"
|
|
62
|
+
if verbose:
|
|
63
|
+
click.echo(f"Cache not available: {e}")
|
|
64
|
+
click.echo("Continuing without cache (direct API calls)")
|
|
65
|
+
else:
|
|
66
|
+
cache_status = "(Cache disabled)"
|
|
67
|
+
if verbose:
|
|
68
|
+
click.echo("Cache explicitly disabled with --no-cache")
|
|
69
|
+
|
|
70
|
+
# Initialize verifier (works with or without cache)
|
|
71
|
+
verifier = PhoneVerifier(cache=cache, provider=provider_instance)
|
|
33
72
|
|
|
34
73
|
try:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
74
|
+
# Verify the phone number
|
|
75
|
+
result = verifier.verify(phone_number)
|
|
76
|
+
result_dict = result.dict() if hasattr(result, 'dict') else result
|
|
77
|
+
|
|
78
|
+
# Prepare clean output
|
|
79
|
+
# Extract line type value if it's an enum
|
|
80
|
+
line_type = result_dict['line_type']
|
|
81
|
+
if hasattr(line_type, 'value'):
|
|
82
|
+
line_type = line_type.value
|
|
83
|
+
|
|
84
|
+
# Build clean output dictionary
|
|
85
|
+
output_data = {
|
|
86
|
+
"phone": result_dict['phone_number'],
|
|
87
|
+
"line_type": line_type,
|
|
88
|
+
"dnc": result_dict['dnc'],
|
|
89
|
+
"cached": result_dict.get('cached', False),
|
|
90
|
+
"verified_at": str(result_dict.get('verified_at', 'Unknown'))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if output == "json":
|
|
94
|
+
# JSON output (default for composability)
|
|
95
|
+
click.echo(json.dumps(output_data, indent=2))
|
|
48
96
|
else:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
click.echo(f"Line Type: {result['line_type']}")
|
|
56
|
-
click.echo(f"DNC Status: {'Yes' if result['dnc'] else 'No'}")
|
|
57
|
-
click.echo(f"From Cache: {'Yes' if result.get('cached') else 'No'}")
|
|
58
|
-
click.echo(f"Verified: {result.get('verified_at', 'Unknown')}")
|
|
59
|
-
click.echo("=" * 40)
|
|
60
|
-
|
|
61
|
-
if click.confirm("\nShow JSON output?"):
|
|
62
|
-
click.echo(json.dumps(result, indent=2, default=str))
|
|
97
|
+
# Text output (human-readable)
|
|
98
|
+
click.echo(f"Phone: {output_data['phone']}")
|
|
99
|
+
click.echo(f"Line Type: {output_data['line_type']}")
|
|
100
|
+
click.echo(f"DNC: {output_data['dnc']}")
|
|
101
|
+
click.echo(f"Cached: {output_data['cached']}")
|
|
102
|
+
click.echo(f"Verified: {output_data['verified_at']}")
|
|
63
103
|
|
|
64
104
|
except ValueError as e:
|
|
65
|
-
|
|
105
|
+
if output == "json":
|
|
106
|
+
error_data = {"error": str(e)}
|
|
107
|
+
click.echo(json.dumps(error_data), err=True)
|
|
108
|
+
else:
|
|
109
|
+
click.echo(f"Error: {e}", err=True)
|
|
110
|
+
click.echo("\nSupported formats:", err=True)
|
|
111
|
+
click.echo(" 6197966726 (10 digits)", err=True)
|
|
112
|
+
click.echo(" 16197966726 (11 digits)", err=True)
|
|
113
|
+
click.echo(" +16197966726 (E.164)", err=True)
|
|
114
|
+
click.echo(" 619-796-6726 (with dashes)", err=True)
|
|
115
|
+
click.echo(" (619) 796-6726 (with parentheses)", err=True)
|
|
116
|
+
import sys
|
|
117
|
+
sys.exit(1)
|
|
66
118
|
except Exception as e:
|
|
67
|
-
|
|
119
|
+
if output == "json":
|
|
120
|
+
error_data = {"error": str(e)}
|
|
121
|
+
click.echo(json.dumps(error_data), err=True)
|
|
122
|
+
else:
|
|
123
|
+
click.echo(f"Verification failed: {e}", err=True)
|
|
124
|
+
if verbose:
|
|
125
|
+
import traceback
|
|
126
|
+
click.echo(traceback.format_exc(), err=True)
|
|
127
|
+
import sys
|
|
128
|
+
sys.exit(1)
|
|
68
129
|
|
|
69
130
|
@verify_group.command(name="bulk")
|
|
70
131
|
@click.argument("csv_file", type=click.Path(exists=True))
|
|
71
132
|
@click.option("--output", "-o", help="Output CSV file")
|
|
72
|
-
@click.option("--
|
|
73
|
-
@click.option("--
|
|
74
|
-
@click.option("--
|
|
75
|
-
|
|
133
|
+
@click.option("--provider", type=click.Choice(["external", "stub"], case_sensitive=False), default="external", help="Verification provider to use")
|
|
134
|
+
@click.option("--no-cache", is_flag=True, help="Disable caching even if AWS is available")
|
|
135
|
+
@click.option("--stack", default="landline-api", help="CloudFormation stack name (for caching)")
|
|
136
|
+
@click.option("--profile", help="AWS profile to use (for caching)")
|
|
137
|
+
@click.option("--region", help="AWS region (for caching)")
|
|
138
|
+
@click.option("--verbose", is_flag=True, help="Show detailed output")
|
|
139
|
+
def verify_bulk(csv_file, output, provider, no_cache, stack, profile, region, verbose):
|
|
76
140
|
"""Process a CSV file for bulk verification"""
|
|
77
141
|
from ai_lls_lib.core.processor import BulkProcessor
|
|
78
142
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
143
|
+
# Select provider based on parameter
|
|
144
|
+
if provider == "stub":
|
|
145
|
+
provider_instance = StubProvider()
|
|
146
|
+
if verbose:
|
|
147
|
+
click.echo("Using StubProvider (deterministic test mode)")
|
|
148
|
+
else:
|
|
149
|
+
provider_instance = ExternalAPIProvider()
|
|
150
|
+
if verbose:
|
|
151
|
+
click.echo("Using ExternalAPIProvider (real API calls)")
|
|
152
|
+
|
|
153
|
+
# Try to set up caching if not explicitly disabled
|
|
154
|
+
cache = None
|
|
155
|
+
|
|
156
|
+
if not no_cache:
|
|
157
|
+
try:
|
|
158
|
+
aws = AWSClient(region=region, profile=profile)
|
|
159
|
+
cache_table = aws.get_table_name(stack, "PhoneCacheTable")
|
|
160
|
+
cache = DynamoDBCache(table_name=cache_table)
|
|
161
|
+
if verbose:
|
|
162
|
+
click.echo(f"Using DynamoDB cache table: {cache_table}")
|
|
163
|
+
except Exception as e:
|
|
164
|
+
if verbose:
|
|
165
|
+
click.echo(f"Cache not available: {e}")
|
|
166
|
+
click.echo("Continuing without cache (direct API calls)")
|
|
167
|
+
else:
|
|
168
|
+
if verbose:
|
|
169
|
+
click.echo("Cache explicitly disabled with --no-cache")
|
|
170
|
+
|
|
171
|
+
# Initialize verifier (works with or without cache)
|
|
172
|
+
verifier = PhoneVerifier(cache=cache, provider=provider_instance)
|
|
84
173
|
processor = BulkProcessor(verifier=verifier)
|
|
85
174
|
|
|
86
175
|
click.echo(f"Processing {csv_file}...")
|
|
@@ -100,7 +189,8 @@ def verify_bulk(csv_file, output, stack, profile, region):
|
|
|
100
189
|
click.echo(f" Mobile: {mobile_count}")
|
|
101
190
|
click.echo(f" Landline: {landline_count}")
|
|
102
191
|
click.echo(f" On DNC: {dnc_count}")
|
|
103
|
-
|
|
192
|
+
if cache:
|
|
193
|
+
click.echo(f" From Cache: {cached_count}")
|
|
104
194
|
|
|
105
195
|
# Generate output if requested
|
|
106
196
|
if output:
|
|
@@ -109,3 +199,6 @@ def verify_bulk(csv_file, output, stack, profile, region):
|
|
|
109
199
|
|
|
110
200
|
except Exception as e:
|
|
111
201
|
click.echo(f"Bulk processing failed: {e}", err=True)
|
|
202
|
+
if verbose:
|
|
203
|
+
import traceback
|
|
204
|
+
click.echo(traceback.format_exc(), err=True)
|
ai_lls_lib/cli/env_loader.py
CHANGED
|
@@ -6,7 +6,7 @@ from typing import Optional, Dict
|
|
|
6
6
|
import click
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def load_env_file(env_path: Path) -> Dict[str, str]:
|
|
9
|
+
def load_env_file(env_path: Path, verbose: bool = False) -> Dict[str, str]:
|
|
10
10
|
"""Load environment variables from a .env file."""
|
|
11
11
|
env_vars = {}
|
|
12
12
|
if env_path.exists():
|
|
@@ -20,7 +20,8 @@ def load_env_file(env_path: Path) -> Dict[str, str]:
|
|
|
20
20
|
value = value.strip().strip('"').strip("'")
|
|
21
21
|
env_vars[key.strip()] = value
|
|
22
22
|
except Exception as e:
|
|
23
|
-
|
|
23
|
+
if verbose:
|
|
24
|
+
click.echo(f"Warning: Could not read {env_path}: {e}", err=True)
|
|
24
25
|
return env_vars
|
|
25
26
|
|
|
26
27
|
|
ai_lls_lib/core/verifier.py
CHANGED
|
@@ -8,7 +8,7 @@ import phonenumbers
|
|
|
8
8
|
from aws_lambda_powertools import Logger
|
|
9
9
|
from .models import PhoneVerification, LineType, VerificationSource
|
|
10
10
|
from .cache import DynamoDBCache
|
|
11
|
-
from ..providers import VerificationProvider, StubProvider
|
|
11
|
+
from ..providers import VerificationProvider, StubProvider, ExternalAPIProvider
|
|
12
12
|
|
|
13
13
|
logger = Logger()
|
|
14
14
|
|
|
@@ -16,16 +16,16 @@ logger = Logger()
|
|
|
16
16
|
class PhoneVerifier:
|
|
17
17
|
"""Verifies phone numbers for line type and DNC status"""
|
|
18
18
|
|
|
19
|
-
def __init__(self, cache: DynamoDBCache, provider: Optional[VerificationProvider] = None):
|
|
19
|
+
def __init__(self, cache: Optional[DynamoDBCache] = None, provider: Optional[VerificationProvider] = None):
|
|
20
20
|
"""
|
|
21
21
|
Initialize phone verifier.
|
|
22
22
|
|
|
23
23
|
Args:
|
|
24
|
-
cache: DynamoDB cache for storing results
|
|
25
|
-
provider: Verification provider (defaults to
|
|
24
|
+
cache: Optional DynamoDB cache for storing results
|
|
25
|
+
provider: Verification provider (defaults to ExternalAPIProvider)
|
|
26
26
|
"""
|
|
27
27
|
self.cache = cache
|
|
28
|
-
self.provider = provider or
|
|
28
|
+
self.provider = provider or ExternalAPIProvider()
|
|
29
29
|
|
|
30
30
|
def normalize_phone(self, phone: str) -> str:
|
|
31
31
|
"""Normalize phone to E.164 format"""
|
|
@@ -45,10 +45,11 @@ class PhoneVerifier:
|
|
|
45
45
|
"""Verify phone number for line type and DNC status"""
|
|
46
46
|
normalized = self.normalize_phone(phone)
|
|
47
47
|
|
|
48
|
-
# Check cache first
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
# Check cache first if available
|
|
49
|
+
if self.cache:
|
|
50
|
+
cached = self.cache.get(normalized)
|
|
51
|
+
if cached:
|
|
52
|
+
return cached
|
|
52
53
|
|
|
53
54
|
# Use provider to verify
|
|
54
55
|
line_type, dnc_status = self.provider.verify_phone(normalized)
|
|
@@ -62,8 +63,13 @@ class PhoneVerifier:
|
|
|
62
63
|
source=VerificationSource.API
|
|
63
64
|
)
|
|
64
65
|
|
|
65
|
-
# Store in cache
|
|
66
|
-
self.cache
|
|
66
|
+
# Store in cache if available
|
|
67
|
+
if self.cache:
|
|
68
|
+
try:
|
|
69
|
+
self.cache.set(normalized, result)
|
|
70
|
+
except Exception as e:
|
|
71
|
+
logger.warning(f"Failed to cache result: {e}")
|
|
72
|
+
# Continue without caching - don't fail the verification
|
|
67
73
|
|
|
68
74
|
return result
|
|
69
75
|
|
ai_lls_lib/providers/__init__.py
CHANGED
|
@@ -3,5 +3,6 @@ Verification providers for phone number checking
|
|
|
3
3
|
"""
|
|
4
4
|
from .base import VerificationProvider
|
|
5
5
|
from .stub import StubProvider
|
|
6
|
+
from .external import ExternalAPIProvider
|
|
6
7
|
|
|
7
|
-
__all__ = ["VerificationProvider", "StubProvider"]
|
|
8
|
+
__all__ = ["VerificationProvider", "StubProvider", "ExternalAPIProvider"]
|
ai_lls_lib/providers/external.py
CHANGED
|
@@ -13,29 +13,45 @@ logger = Logger()
|
|
|
13
13
|
class ExternalAPIProvider:
|
|
14
14
|
"""
|
|
15
15
|
Production provider that calls external verification APIs.
|
|
16
|
+
Uses landlineremover.com which returns both line type and DNC status in a single call.
|
|
16
17
|
"""
|
|
17
18
|
|
|
18
19
|
def __init__(
|
|
19
20
|
self,
|
|
20
|
-
|
|
21
|
-
dnc_api_key: Optional[str] = None,
|
|
21
|
+
api_key: Optional[str] = None,
|
|
22
22
|
timeout: float = 10.0
|
|
23
23
|
):
|
|
24
24
|
"""
|
|
25
25
|
Initialize external API provider.
|
|
26
26
|
|
|
27
27
|
Args:
|
|
28
|
-
|
|
29
|
-
dnc_api_key: API key for DNC list checking
|
|
28
|
+
api_key: API key for landlineremover.com (if not provided, uses environment)
|
|
30
29
|
timeout: HTTP request timeout in seconds
|
|
31
30
|
"""
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
# Get environment-specific API key
|
|
32
|
+
# Default to 'prod' if not specified
|
|
33
|
+
env = os.environ.get("ENVIRONMENT", "prod").upper()
|
|
34
|
+
|
|
35
|
+
# Try environment-specific key first, then fall back to provided key
|
|
36
|
+
self.api_key = (
|
|
37
|
+
api_key or
|
|
38
|
+
os.environ.get(f"{env}_LANDLINE_API_KEY") or
|
|
39
|
+
os.environ.get("PHONE_VERIFY_API_KEY", "")
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if not self.api_key:
|
|
43
|
+
logger.warning(f"No API key found for environment {env}")
|
|
44
|
+
|
|
45
|
+
self.api_url = "https://app.landlineremover.com/api/check-number"
|
|
46
|
+
self.timeout = timeout
|
|
34
47
|
self.http_client = httpx.Client(timeout=timeout)
|
|
35
48
|
|
|
36
49
|
def verify_phone(self, phone: str) -> Tuple[LineType, bool]:
|
|
37
50
|
"""
|
|
38
|
-
Verify phone using
|
|
51
|
+
Verify phone using landlineremover.com API.
|
|
52
|
+
|
|
53
|
+
This API returns both line type and DNC status in a single call,
|
|
54
|
+
which is more efficient than making two separate API calls.
|
|
39
55
|
|
|
40
56
|
Args:
|
|
41
57
|
phone: E.164 formatted phone number
|
|
@@ -47,41 +63,89 @@ class ExternalAPIProvider:
|
|
|
47
63
|
httpx.HTTPError: For API communication errors
|
|
48
64
|
ValueError: For invalid responses
|
|
49
65
|
"""
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
logger.debug(f"Verifying phone {phone[:6]}*** via external API")
|
|
67
|
+
|
|
68
|
+
if not self.api_key:
|
|
69
|
+
raise ValueError("API key not configured")
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
# Make single API call that returns both line type and DNC status
|
|
73
|
+
# The API may redirect, so we need to follow redirects
|
|
74
|
+
response = self.http_client.get(
|
|
75
|
+
self.api_url,
|
|
76
|
+
params={
|
|
77
|
+
"apikey": self.api_key,
|
|
78
|
+
"number": phone
|
|
79
|
+
},
|
|
80
|
+
follow_redirects=True
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Raise for HTTP errors
|
|
84
|
+
response.raise_for_status()
|
|
85
|
+
|
|
86
|
+
# Parse response
|
|
87
|
+
json_response = response.json()
|
|
88
|
+
|
|
89
|
+
# Extract data from response wrapper
|
|
90
|
+
if "data" in json_response:
|
|
91
|
+
data = json_response["data"]
|
|
92
|
+
else:
|
|
93
|
+
data = json_response
|
|
94
|
+
|
|
95
|
+
# Map line type from API response
|
|
96
|
+
line_type = self._map_line_type(data)
|
|
97
|
+
|
|
98
|
+
# Map DNC status - API uses "DNCType" field
|
|
99
|
+
# Values can be "dnc", "clean", etc.
|
|
100
|
+
dnc_type = data.get("DNCType", data.get("dnc_type", "")).lower()
|
|
101
|
+
is_dnc = dnc_type != "clean" and dnc_type != ""
|
|
102
|
+
|
|
103
|
+
logger.debug(
|
|
104
|
+
f"Verification complete for {phone[:6]}***",
|
|
105
|
+
extra={
|
|
106
|
+
"line_type": line_type.value,
|
|
107
|
+
"is_dnc": is_dnc,
|
|
108
|
+
"dnc_type": dnc_type
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
return line_type, is_dnc
|
|
113
|
+
|
|
114
|
+
except httpx.HTTPStatusError as e:
|
|
115
|
+
logger.error(f"API error: {e.response.status_code} - {e.response.text}")
|
|
116
|
+
raise ValueError(f"API request failed with status {e.response.status_code}")
|
|
117
|
+
except httpx.RequestError as e:
|
|
118
|
+
logger.error(f"Network error: {str(e)}")
|
|
119
|
+
raise ValueError(f"Network error during API call: {str(e)}")
|
|
120
|
+
except Exception as e:
|
|
121
|
+
logger.error(f"Unexpected error during verification: {str(e)}")
|
|
122
|
+
raise
|
|
123
|
+
|
|
124
|
+
def _map_line_type(self, data: dict) -> LineType:
|
|
62
125
|
"""
|
|
63
|
-
|
|
126
|
+
Map API response to LineType enum.
|
|
64
127
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
raise NotImplementedError("External line type API not yet configured")
|
|
128
|
+
Args:
|
|
129
|
+
data: API response dictionary
|
|
68
130
|
|
|
69
|
-
|
|
131
|
+
Returns:
|
|
132
|
+
LineType enum value
|
|
70
133
|
"""
|
|
71
|
-
|
|
134
|
+
# API uses "LineType" (capitalized) field
|
|
135
|
+
line_type_str = data.get("LineType", data.get("line_type", "")).lower()
|
|
72
136
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
137
|
+
# Map common line types
|
|
138
|
+
line_type_map = {
|
|
139
|
+
"mobile": LineType.MOBILE,
|
|
140
|
+
"landline": LineType.LANDLINE,
|
|
141
|
+
"voip": LineType.VOIP,
|
|
142
|
+
"wireless": LineType.MOBILE, # Some APIs return "wireless" for mobile
|
|
143
|
+
"fixed": LineType.LANDLINE, # Some APIs return "fixed" for landline
|
|
144
|
+
}
|
|
79
145
|
|
|
80
|
-
|
|
81
|
-
# In production, this would make an actual API call
|
|
82
|
-
raise NotImplementedError("External DNC API not yet configured")
|
|
146
|
+
return line_type_map.get(line_type_str, LineType.UNKNOWN)
|
|
83
147
|
|
|
84
148
|
def __del__(self):
|
|
85
149
|
"""Cleanup HTTP client"""
|
|
86
150
|
if hasattr(self, 'http_client'):
|
|
87
|
-
self.http_client.close()
|
|
151
|
+
self.http_client.close()
|
ai_lls_lib/providers/stub.py
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
ai_lls_lib/__init__.py,sha256=
|
|
1
|
+
ai_lls_lib/__init__.py,sha256=me5F-kAI_umDdD_bPb-PTQhVFshB93w7c3wfU9W6t0Y,734
|
|
2
2
|
ai_lls_lib/auth/__init__.py,sha256=ZjwlfTvYUo9A9BaLinaXW2elxYectScmu0XtKAppSFs,198
|
|
3
3
|
ai_lls_lib/auth/context_parser.py,sha256=AWyGWejrFR0jJ7fMhajdA1ABo656Qlvs2YAzz-IfTrs,2290
|
|
4
4
|
ai_lls_lib/cli/__init__.py,sha256=HyjnIBGlrbTlHQ82n_UppjtJbZl4_7QsnAgRqNlXKMU,77
|
|
5
|
-
ai_lls_lib/cli/__main__.py,sha256=
|
|
5
|
+
ai_lls_lib/cli/__main__.py,sha256=3G1Mmkaa7NfEHILpZbDVqu4yPfy5TVx7QaAmlp2TSGc,2071
|
|
6
6
|
ai_lls_lib/cli/aws_client.py,sha256=lqihYQQtpx8Xb5HcVTbexl1pZdlYYdozPLDEGcen27Q,4067
|
|
7
7
|
ai_lls_lib/cli/commands/__init__.py,sha256=yi0bdkZSPIXY33apvJRcuK410-Ta0-_-n31MQYuL_aU,31
|
|
8
8
|
ai_lls_lib/cli/commands/admin.py,sha256=JlFljbblVWJkJ2z2FIM6P0fy3Pmc0VqG62Y3POtvRFw,6861
|
|
9
9
|
ai_lls_lib/cli/commands/cache.py,sha256=1Vm3m5vXJkRagNmQXpT8_YEsQEv92veJUFwA_v9FPb0,5822
|
|
10
10
|
ai_lls_lib/cli/commands/stripe.py,sha256=_aRsz6Z7BN-S9_07efUovXwsbL-eCE-raw1uBOkDP5g,15276
|
|
11
11
|
ai_lls_lib/cli/commands/test_stack.py,sha256=FK6ITOek7j4e0QiSNTv_taLghNnR8d_kWG02cl0A3rY,7594
|
|
12
|
-
ai_lls_lib/cli/commands/verify.py,sha256=
|
|
13
|
-
ai_lls_lib/cli/env_loader.py,sha256=
|
|
12
|
+
ai_lls_lib/cli/commands/verify.py,sha256=8rTg8xbdQbJdebDy5CT7HFcJ-ODFZdAOAo2JX82ARJs,8522
|
|
13
|
+
ai_lls_lib/cli/env_loader.py,sha256=ZL8GykQw8gf--aSMvIR4pdfQYKIA8bbJDWWNUpxZYsI,4260
|
|
14
14
|
ai_lls_lib/core/__init__.py,sha256=ATh5sGhhB9g5Sd2H0kRqoCA0hxqe6UWonlPq2Wnl_i8,39
|
|
15
15
|
ai_lls_lib/core/cache.py,sha256=4HSVaRvv_wueLV30fVbTk_KWZmXjR2mBrGl7UNT_5kQ,3817
|
|
16
16
|
ai_lls_lib/core/models.py,sha256=jzvc-SlP-nLgvkom9hj-TwKHxBePbEfC9xL_Tt1Uh4Y,2458
|
|
17
17
|
ai_lls_lib/core/processor.py,sha256=8PI_j1ZMOD1hru3PyV5QMmMx7Em8X0ivq8prMXwait4,10269
|
|
18
|
-
ai_lls_lib/core/verifier.py,sha256=
|
|
18
|
+
ai_lls_lib/core/verifier.py,sha256=mQBgzV-vZiiKGzeeVl3TwfOWGrYTeB_zQ6wpaI07u54,3147
|
|
19
19
|
ai_lls_lib/payment/__init__.py,sha256=uQwWZ2tw-cxS06hbWiKu8ubxzzYCmxeKBQQU7m_mRX4,308
|
|
20
20
|
ai_lls_lib/payment/credit_manager.py,sha256=DH_t8AMx74vexegoTD3UkFNA1XuomIQWOZu9VoJMO3E,7340
|
|
21
21
|
ai_lls_lib/payment/models.py,sha256=LxGop5e1hhUmBCpnzJwU-dDQSLHy6uM6gSFYYo2V_FI,3609
|
|
22
22
|
ai_lls_lib/payment/stripe_manager.py,sha256=cSJvRWk1OT16SlDh5BMyoEQD8TU0IzeP0TaL8e2U4zA,18423
|
|
23
23
|
ai_lls_lib/payment/webhook_processor.py,sha256=bAf8oUBzvCsb1stzKZ-cjZs02T-RJl-MeVnZmnnj5UM,8980
|
|
24
|
-
ai_lls_lib/providers/__init__.py,sha256=
|
|
24
|
+
ai_lls_lib/providers/__init__.py,sha256=dBjXJHn2nnA8KUuLYkgCJjZZzWeYAPPd6IJHUd7b-Kk,252
|
|
25
25
|
ai_lls_lib/providers/base.py,sha256=WSnSkHtRvwpX8QtGINjO-EWsZL0augp5E8M1DPwpf00,709
|
|
26
|
-
ai_lls_lib/providers/external.py,sha256=
|
|
27
|
-
ai_lls_lib/providers/stub.py,sha256=
|
|
26
|
+
ai_lls_lib/providers/external.py,sha256=MKu3BZV8gfSqV3lNcF9Vt4UmKIJixQ5Q7FI2wFeSBz0,5075
|
|
27
|
+
ai_lls_lib/providers/stub.py,sha256=XXUObkIb3hs7_fYMA9mlLh1llJUGIgqQHVjgZHZl1T8,1199
|
|
28
28
|
ai_lls_lib/testing/__init__.py,sha256=NytBz7T0YtNLDArRYHsczaeopIQmmBeV21-XXUprdeY,42
|
|
29
29
|
ai_lls_lib/testing/fixtures.py,sha256=OC1huorIqUndePoUTfgoU-aDvsWAFJqmQ6fGDjH9E14,3414
|
|
30
|
-
ai_lls_lib-1.5.
|
|
31
|
-
ai_lls_lib-1.5.
|
|
32
|
-
ai_lls_lib-1.5.
|
|
33
|
-
ai_lls_lib-1.5.
|
|
30
|
+
ai_lls_lib-1.5.0rc4.dist-info/METADATA,sha256=lHqVjmDxXEZvcjo-DNXugzdHbD3tqcIBYK_uRkDQBTw,7302
|
|
31
|
+
ai_lls_lib-1.5.0rc4.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
32
|
+
ai_lls_lib-1.5.0rc4.dist-info/entry_points.txt,sha256=Pi0V_HBViEKGFbNQKatl5lhhnHHBXlxaom-5gH9gXZ0,55
|
|
33
|
+
ai_lls_lib-1.5.0rc4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|