Updated to PhotosAPI v0.5.0

This commit is contained in:
Profitroll 2023-06-27 14:03:49 +02:00
parent c05c588768
commit a4f6bb2a25
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
6 changed files with 581 additions and 1 deletions

View File

@ -0,0 +1,216 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast
import httpx
from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.http_validation_error import HTTPValidationError
from ...models.random_search_results_photo import RandomSearchResultsPhoto
from ...types import UNSET, Response, Unset
def _get_kwargs(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Dict[str, Any]:
url = "{}/albums/{album}/photos/random".format(client.base_url, album=album)
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
params: Dict[str, Any] = {}
params["caption"] = caption
params["limit"] = limit
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
return {
"method": "get",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"follow_redirects": client.follow_redirects,
"params": params,
}
def _parse_response(
*, client: Client, response: httpx.Response
) -> Optional[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]:
if response.status_code == HTTPStatus.OK:
response_200 = RandomSearchResultsPhoto.from_dict(response.json())
return response_200
if response.status_code == HTTPStatus.BAD_REQUEST:
response_400 = cast(Any, None)
return response_400
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = cast(Any, None)
return response_404
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
response_422 = HTTPValidationError.from_dict(response.json())
return response_422
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None
def _build_response(
*, client: Client, response: httpx.Response
) -> Response[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)
def sync_detailed(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Response[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]:
"""Photo Random
Get one random photo, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]
"""
kwargs = _get_kwargs(
album=album,
client=client,
caption=caption,
limit=limit,
)
response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(client=client, response=response)
def sync(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Optional[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]:
"""Photo Random
Get one random photo, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, HTTPValidationError, RandomSearchResultsPhoto]
"""
return sync_detailed(
album=album,
client=client,
caption=caption,
limit=limit,
).parsed
async def asyncio_detailed(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Response[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]:
"""Photo Random
Get one random photo, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]
"""
kwargs = _get_kwargs(
album=album,
client=client,
caption=caption,
limit=limit,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)
return _build_response(client=client, response=response)
async def asyncio(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Optional[Union[Any, HTTPValidationError, RandomSearchResultsPhoto]]:
"""Photo Random
Get one random photo, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, HTTPValidationError, RandomSearchResultsPhoto]
"""
return (
await asyncio_detailed(
album=album,
client=client,
caption=caption,
limit=limit,
)
).parsed

View File

@ -0,0 +1,216 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast
import httpx
from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.http_validation_error import HTTPValidationError
from ...models.random_search_results_video import RandomSearchResultsVideo
from ...types import UNSET, Response, Unset
def _get_kwargs(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Dict[str, Any]:
url = "{}/albums/{album}/videos/random".format(client.base_url, album=album)
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
params: Dict[str, Any] = {}
params["caption"] = caption
params["limit"] = limit
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
return {
"method": "get",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"follow_redirects": client.follow_redirects,
"params": params,
}
def _parse_response(
*, client: Client, response: httpx.Response
) -> Optional[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]:
if response.status_code == HTTPStatus.OK:
response_200 = RandomSearchResultsVideo.from_dict(response.json())
return response_200
if response.status_code == HTTPStatus.BAD_REQUEST:
response_400 = cast(Any, None)
return response_400
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = cast(Any, None)
return response_404
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
response_422 = HTTPValidationError.from_dict(response.json())
return response_422
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None
def _build_response(
*, client: Client, response: httpx.Response
) -> Response[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)
def sync_detailed(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Response[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]:
"""Video Random
Get one random video, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]
"""
kwargs = _get_kwargs(
album=album,
client=client,
caption=caption,
limit=limit,
)
response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(client=client, response=response)
def sync(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Optional[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]:
"""Video Random
Get one random video, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, HTTPValidationError, RandomSearchResultsVideo]
"""
return sync_detailed(
album=album,
client=client,
caption=caption,
limit=limit,
).parsed
async def asyncio_detailed(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Response[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]:
"""Video Random
Get one random video, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]
"""
kwargs = _get_kwargs(
album=album,
client=client,
caption=caption,
limit=limit,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)
return _build_response(client=client, response=response)
async def asyncio(
album: str,
*,
client: AuthenticatedClient,
caption: Union[Unset, None, str] = UNSET,
limit: Union[Unset, None, int] = 100,
) -> Optional[Union[Any, HTTPValidationError, RandomSearchResultsVideo]]:
"""Video Random
Get one random video, optionally by caption
Args:
album (str):
caption (Union[Unset, None, str]):
limit (Union[Unset, None, int]): Default: 100.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, HTTPValidationError, RandomSearchResultsVideo]
"""
return (
await asyncio_detailed(
album=album,
client=client,
caption=caption,
limit=limit,
)
).parsed

View File

@ -11,6 +11,8 @@ from .http_validation_error import HTTPValidationError
from .photo import Photo from .photo import Photo
from .photo_public import PhotoPublic from .photo_public import PhotoPublic
from .photo_search import PhotoSearch from .photo_search import PhotoSearch
from .random_search_results_photo import RandomSearchResultsPhoto
from .random_search_results_video import RandomSearchResultsVideo
from .search_results_album import SearchResultsAlbum from .search_results_album import SearchResultsAlbum
from .search_results_photo import SearchResultsPhoto from .search_results_photo import SearchResultsPhoto
from .search_results_video import SearchResultsVideo from .search_results_video import SearchResultsVideo
@ -33,6 +35,8 @@ __all__ = (
"Photo", "Photo",
"PhotoPublic", "PhotoPublic",
"PhotoSearch", "PhotoSearch",
"RandomSearchResultsPhoto",
"RandomSearchResultsVideo",
"SearchResultsAlbum", "SearchResultsAlbum",
"SearchResultsPhoto", "SearchResultsPhoto",
"SearchResultsVideo", "SearchResultsVideo",

View File

@ -0,0 +1,72 @@
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar
import attr
if TYPE_CHECKING:
from ..models.photo_search import PhotoSearch
T = TypeVar("T", bound="RandomSearchResultsPhoto")
@attr.s(auto_attribs=True)
class RandomSearchResultsPhoto:
"""
Attributes:
results (List['PhotoSearch']):
"""
results: List["PhotoSearch"]
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
def to_dict(self) -> Dict[str, Any]:
results = []
for results_item_data in self.results:
results_item = results_item_data.to_dict()
results.append(results_item)
field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"results": results,
}
)
return field_dict
@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
from ..models.photo_search import PhotoSearch
d = src_dict.copy()
results = []
_results = d.pop("results")
for results_item_data in _results:
results_item = PhotoSearch.from_dict(results_item_data)
results.append(results_item)
random_search_results_photo = cls(
results=results,
)
random_search_results_photo.additional_properties = d
return random_search_results_photo
@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties

View File

@ -0,0 +1,72 @@
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar
import attr
if TYPE_CHECKING:
from ..models.video_search import VideoSearch
T = TypeVar("T", bound="RandomSearchResultsVideo")
@attr.s(auto_attribs=True)
class RandomSearchResultsVideo:
"""
Attributes:
results (List['VideoSearch']):
"""
results: List["VideoSearch"]
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
def to_dict(self) -> Dict[str, Any]:
results = []
for results_item_data in self.results:
results_item = results_item_data.to_dict()
results.append(results_item)
field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"results": results,
}
)
return field_dict
@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
from ..models.video_search import VideoSearch
d = src_dict.copy()
results = []
_results = d.pop("results")
for results_item_data in _results:
results_item = VideoSearch.from_dict(results_item_data)
results.append(results_item)
random_search_results_video = cls(
results=results,
)
random_search_results_video.additional_properties = d
return random_search_results_video
@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties

View File

@ -7,7 +7,7 @@ long_description = (here / "README.md").read_text(encoding="utf-8")
setup( setup(
name="PhotosAPI_Client", name="PhotosAPI_Client",
version="0.4.0", version="0.5.0",
description="A client library for accessing Photos API", description="A client library for accessing Photos API",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",