From 473d44d5761cb2f091722591bcc7d3fd8673968f Mon Sep 17 00:00:00 2001 From: Adrien Date: Tue, 14 Feb 2023 09:05:40 +0100 Subject: [PATCH] Updated url under several API's GET endpoints (#5) --- pytransifex/api.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pytransifex/api.py b/pytransifex/api.py index 35c9e00..485d5be 100755 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -5,6 +5,8 @@ import codecs import requests import json +from urllib import parse + from pytransifex.exceptions import PyTransifexException @@ -118,7 +120,8 @@ def delete_project(self, project_slug: str): ------ `PyTransifexException` """ - url = 'https://rest.api.transifex.com/projects/o:{o}:p:{p}'.format(o=self.organization, p=project_slug) + filter_project = f"o:{self.organization}:p:{project_slug}" + url = f"https://rest.api.transifex.com/projects/{parse.quote(filter_project)}" response = requests.delete(url, headers={'Content-Type': 'application/vnd.api+json','Authorization': 'Bearer {}'.format(self.api_key)}) if response.status_code != requests.codes['OK']: raise PyTransifexException(response) @@ -146,9 +149,8 @@ def list_resources(self, project_slug) -> list: ------ `PyTransifexException` """ - url = 'https://api.transifex.com/organizations/{o}/projects/{p}/resources/'.format( - o=self.organization, p=project_slug - ) + filter_project = f"o:{self.organization}:p:{project_slug}" + url = f"https://rest.api.transifex.com/resources?filter\[project\]={parse.quote(filter_project)}" response = requests.get(url, auth=self.auth) if response.status_code != requests.codes['OK']: @@ -157,7 +159,8 @@ def list_resources(self, project_slug) -> list: return json.loads(codecs.decode(response.content, 'utf-8')) def delete_team(self, team_slug: str): - url = 'https://rest.api.transifex.com/teams/o:{o}:t:{t}'.format(o=self.organization, t=team_slug) + filter_team = f"o:{self.organization}:t:{team_slug}" + url = f"https://rest.api.transifex.com/teams/{parse.quote(filter_team)}" response = requests.delete(url, headers={'Content-Type': 'application/vnd.api+json','Authorization': 'Bearer {}'.format(self.api_key)}) if response.status_code != requests.codes['OK']: raise PyTransifexException(response) @@ -422,7 +425,8 @@ def project_exists(self, project_slug) -> bool: project_slug The project slug """ - url = 'https://rest.api.transifex.com/projects/o:{o}:p:{s}'.format(o=self.organization, s=project_slug) + filter_project = f"o:{self.organization}:p:{project_slug}" + url = f"https://rest.api.transifex.com/projects/{parse.quote(filter_project)}" response = requests.get(url, headers={ 'Content-Type': 'application/vnd.api+json', @@ -439,7 +443,8 @@ def ping(self) -> bool: """ Check the connection to the server and the auth credentials """ - url = 'https://api.transifex.com/organizations/{}/projects/'.format(self.organization) + filter_organization = f"o:{self.organization}" + url = f"https://rest.api.transifex.com/projects?filter\[organization\]={parse.quote(filter_organization)}" response = requests.get(url, auth=self.auth) success = response.status_code == requests.codes['OK'] if not success: