-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1331 from GSA/notify-api-1306
add initial phone validation ability
- Loading branch information
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from boto3 import client | ||
from botocore.exceptions import ClientError | ||
from flask import current_app | ||
|
||
from app.clients import AWS_CLIENT_CONFIG, Client | ||
from app.cloudfoundry_config import cloud_config | ||
from app.utils import hilite | ||
|
||
|
||
class AwsPinpointClient(Client): | ||
|
||
def init_app(self, current_app, *args, **kwargs): | ||
self._client = client( | ||
"pinpoint", | ||
region_name=cloud_config.sns_region, | ||
aws_access_key_id=cloud_config.sns_access_key, | ||
aws_secret_access_key=cloud_config.sns_secret_key, | ||
config=AWS_CLIENT_CONFIG, | ||
) | ||
|
||
super(Client, self).__init__(*args, **kwargs) | ||
self.current_app = current_app | ||
|
||
@property | ||
def name(self): | ||
return "pinpoint" | ||
|
||
def validate_phone_number(self, country_code, phone_number): | ||
try: | ||
response = self._client.phone_number_validate( | ||
NumberValidateRequest={ | ||
"IsoCountryCode": country_code, | ||
"PhoneNumber": phone_number, | ||
} | ||
) | ||
|
||
# TODO right now this will only print with AWS simulated numbers, | ||
# but remove this when that changes | ||
current_app.logger.info(hilite(response)) | ||
except ClientError: | ||
current_app.logger.exception("Could not validate with pinpoint") | ||
|
||
# TODO This is the structure of the response. When the phone validation | ||
# capability we want to offer is better defined (it may just be a question | ||
# of checking PhoneType -- i.e., landline or mobile) then do something with | ||
# this info. | ||
# { | ||
# 'NumberValidateResponse': { | ||
# 'Carrier': 'string', | ||
# 'City': 'string', | ||
# 'CleansedPhoneNumberE164': 'string', | ||
# 'CleansedPhoneNumberNational': 'string', | ||
# 'Country': 'string', | ||
# 'CountryCodeIso2': 'string', | ||
# 'CountryCodeNumeric': 'string', | ||
# 'County': 'string', | ||
# 'OriginalCountryCodeIso2': 'string', | ||
# 'OriginalPhoneNumber': 'string', | ||
# 'PhoneType': 'string', | ||
# 'PhoneTypeCode': 123, | ||
# 'Timezone': 'string', | ||
# 'ZipCode': 'string' | ||
# } | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters