-
Notifications
You must be signed in to change notification settings - Fork 3
Add client for checking opt out status #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
import sys | ||
|
||
from uid2_client import OptOutStatusClient | ||
|
||
|
||
def _usage(): | ||
print( | ||
'Usage: python3 sample_optout_status_client.py <base_url> <api_key> <client_secret> <advertising_id_1> <advertising_id_2> ... <advertising_id_3>' | ||
, file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
if len(sys.argv) <= 4: | ||
_usage() | ||
|
||
base_url = sys.argv[1] | ||
api_key = sys.argv[2] | ||
client_secret = sys.argv[3] | ||
advertising_ids = sys.argv[4:] | ||
|
||
optout_status_client = OptOutStatusClient(base_url, api_key, client_secret) | ||
|
||
response_json = json.loads(optout_status_client.get_optout_status(advertising_ids)) | ||
print(json.dumps(response_json, indent=2)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import base64 | ||
import datetime as dt | ||
from datetime import timezone | ||
import json | ||
|
||
from uid2_client import auth_headers, make_v2_request, post, parse_v2_response | ||
|
||
|
||
class OptOutStatusClient: | ||
"""Client for interacting with UID Optout status | ||
|
||
You will need to have the base URL of the endpoint and a client API key | ||
and secret to consume web services. | ||
|
||
Methods: | ||
get_optout_status: Get Opt Out Status of advertising_ids | ||
""" | ||
|
||
def __init__(self, base_url, api_key, client_secret): | ||
"""Create a new OptOutStatusClient client. | ||
|
||
Args: | ||
base_url (str): base URL for all requests to UID services (e.g. 'https://prod.uidapi.com') | ||
api_key (str): api key for consuming the UID services | ||
client_secret (str): client secret for consuming the UID services | ||
|
||
Note: | ||
Your authorization key will determine which UID services you are allowed to use. | ||
""" | ||
self._base_url = base_url | ||
self._api_key = api_key | ||
self._client_secret = base64.b64decode(client_secret) | ||
|
||
def get_optout_status(self, advertising_ids): | ||
request_payload = { | ||
'advertising_ids': advertising_ids | ||
} | ||
req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), | ||
json.dumps(request_payload).encode()) | ||
resp = post(self._base_url, '/v2/optout/status', headers=auth_headers(self._api_key), data=req) | ||
return parse_v2_response(self._client_secret, resp.read(), nonce) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we decide to merge it, would you mind have some unit tests for this class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NVM, we do not want to spend too much time on this. And it is a simple class. No unit tests is also good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: maybe
<advertising_id_n>
instead of<advertising_id_3>
?