Skip to content

Commit

Permalink
Fix bug in file_api_url when page is set
Browse files Browse the repository at this point in the history
  • Loading branch information
uio-torjus committed Nov 20, 2023
1 parent 09140d8 commit c8b1076
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ authors = [
maintainers = [
"Eirik Haatveit <[email protected]>",
"Milen Kouylekov <[email protected]>",
"Torjus Håkestad <[email protected]>",
]
license = "BSD-3-Clause"
readme = "README.md"
Expand Down
17 changes: 10 additions & 7 deletions tsdapiclient/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from functools import wraps
from typing import Optional, Callable, Any, Union
from urllib.parse import urlencode

import click
import requests
Expand Down Expand Up @@ -79,24 +80,26 @@ def file_api_url(
service: str,
endpoint: str = '',
formid: str = '',
page: Optional[str] = None,
page: Optional[int] = None,
per_page: Optional[int] = None,
) -> str:
try:
host = HOSTS.get(env)
if page:
url = f'https://{host}{page}'
if per_page:
url += f'&per_page={per_page}'
return url
if formid:
endpoint = f'{formid}/{endpoint}'
scheme = 'http' if env == 'dev' else 'https'
url = f'{scheme}://{host}/{API_VERSION}/{pnum}/{service}/{endpoint}'
if url.endswith('/'):
url = url[:-1]

query_dict = {}
if per_page:
url += f'?per_page={per_page}'
query_dict["per_page"] = per_page
if page is not None:
query_dict["page"] = page
if len(query_dict) > 0:
url += f'?{urlencode(query_dict)}'

return url
except (AssertionError, Exception) as e:
raise e
Expand Down

0 comments on commit c8b1076

Please sign in to comment.