Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
Check response status when checking token usage
Browse files Browse the repository at this point in the history
  • Loading branch information
impredicative committed Sep 24, 2022
1 parent ac35843 commit a4aca09
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bitlyshortener/shortener.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,14 @@ def _usage(self, token: str) -> Dict[str, int]:
total_used, total_limit = 0, 0
request_headers = {"Authorization": f"Bearer {token}"}
response = session.get(config.API_URL_ORGANIZATIONS, headers=request_headers)
orgs = response.json()["organizations"]
response.raise_for_status()
orgs_data = response.json()
orgs = orgs_data["organizations"]
for org in orgs:
guid = org["guid"]
response = session.get(config.API_URL_FORMAT_ORGANIZATION_LIMITS.format(organization_guid=guid), headers=request_headers)
usages = response.json()["plan_limits"]
limits_data = response.json()
usages = limits_data["plan_limits"]
for usage in usages:
if usage["name"] == "encodes":
total_used += usage["count"]
Expand Down

0 comments on commit a4aca09

Please sign in to comment.