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

Updated url under several API's GET endpoints #5

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import codecs
import requests
import json
from urllib import parse

from pytransifex.exceptions import PyTransifexException


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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']:
Expand All @@ -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)
Expand Down Expand Up @@ -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',
Expand All @@ -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:
Expand Down