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

Commit

Permalink
Updated url under several API's GET endpoints (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer authored Feb 14, 2023
1 parent f72b850 commit 473d44d
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 473d44d

Please sign in to comment.