about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip')
-rw-r--r--.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/__init__.py0
-rw-r--r--.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/unassigned.py59
2 files changed, 59 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/__init__.py b/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/__init__.py
diff --git a/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/unassigned.py b/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/unassigned.py
new file mode 100644
index 00000000..816050d3
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/sendgrid/helpers/endpoints/ip/unassigned.py
@@ -0,0 +1,59 @@
+import json
+
+
+def format_ret(return_set, as_json=False):
+    """ decouple, allow for modifications to return type
+        returns a list of ip addresses in object or json form """
+    ret_list = list()
+    for item in return_set:
+        d = {"ip": item}
+        ret_list.append(d)
+
+    if as_json:
+        return json.dumps(ret_list)
+
+    return ret_list
+
+
+def unassigned(data, as_json=False):
+    """ https://sendgrid.com/docs/API_Reference/api_v3.html#ip-addresses
+        The /ips rest endpoint returns information about the IP addresses
+        and the usernames assigned to an IP
+
+        unassigned returns a listing of the IP addresses that are allocated
+        but have 0 users assigned
+
+
+        data (response.body from sg.client.ips.get())
+        as_json False -> get list of dicts
+                True  -> get json object
+
+        example:
+        sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+
+        params = {
+            'subuser': 'test_string',
+            'ip': 'test_string',
+            'limit': 1,
+            'exclude_whitelabels':
+            'true', 'offset': 1
+        }
+        response = sg.client.ips.get(query_params=params)
+        if response.status_code == 201:
+           data = response.body
+           unused = unassigned(data)
+    """
+
+    no_subusers = set()
+
+    if not isinstance(data, list):
+        return format_ret(no_subusers, as_json=as_json)
+
+    for current in data:
+        num_subusers = len(current["subusers"])
+        if num_subusers == 0:
+            current_ip = current["ip"]
+            no_subusers.add(current_ip)
+
+    ret_val = format_ret(no_subusers, as_json=as_json)
+    return ret_val