Skip to content

Commit

Permalink
Split schemas (#136)
Browse files Browse the repository at this point in the history
**Breaking Changes:**
- Split classes into 2 subclasses as resource and list[resource] returns different values
- search and *_list returns Entry version of resource
- Remove id_ fields
  • Loading branch information
Buried-In-Code authored Sep 14, 2022
1 parent 0941c74 commit 28588db
Show file tree
Hide file tree
Showing 28 changed files with 541 additions and 171 deletions.
1 change: 1 addition & 0 deletions docs/simyan/schemas/character.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Character

::: simyan.schemas.character.Character
::: simyan.schemas.character.CharacterEntry
1 change: 1 addition & 0 deletions docs/simyan/schemas/creator.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Creator

::: simyan.schemas.creator.Creator
::: simyan.schemas.creator.CreatorEntry
1 change: 1 addition & 0 deletions docs/simyan/schemas/generic_entries.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generic Entries

::: simyan.schemas.generic_entries.AlternativeImageEntry
::: simyan.schemas.generic_entries.CountEntry
::: simyan.schemas.generic_entries.CreatorEntry
::: simyan.schemas.generic_entries.GenericEntry
Expand Down
1 change: 1 addition & 0 deletions docs/simyan/schemas/issue.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Issue

::: simyan.schemas.issue.Issue
::: simyan.schemas.issue.IssueEntry
1 change: 1 addition & 0 deletions docs/simyan/schemas/publisher.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Publisher

::: simyan.schemas.publisher.Publisher
::: simyan.schemas.publisher.PublisherEntry
1 change: 1 addition & 0 deletions docs/simyan/schemas/story_arc.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Story Arc

::: simyan.schemas.story_arc.StoryArc
::: simyan.schemas.story_arc.StoryArcEntry
1 change: 1 addition & 0 deletions docs/simyan/schemas/team.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Team

::: simyan.schemas.team.Team
::: simyan.schemas.team.TeamEntry
1 change: 1 addition & 0 deletions docs/simyan/schemas/volume.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Volume

::: simyan.schemas.volume.Volume
::: simyan.schemas.volume.VolumeEntry
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages = [
]
readme = "README.md"
repository = "https://github.com/Metron-Project/Simyan"
version = "0.10.0"
version = "0.11.0"

[tool.poetry.dependencies]
mkdocs = {version = "^1.3.1", optional = true}
Expand Down
2 changes: 1 addition & 1 deletion simyan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""simyan package entry file."""
__version__ = "0.10.0"
__version__ = "0.11.0"
__all__ = ["__version__", "get_cache_root"]

from pathlib import Path
Expand Down
102 changes: 51 additions & 51 deletions simyan/comicvine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

from simyan import __version__
from simyan.exceptions import AuthenticationError, CacheError, ServiceError
from simyan.schemas.character import Character
from simyan.schemas.creator import Creator
from simyan.schemas.issue import Issue
from simyan.schemas.character import Character, CharacterEntry
from simyan.schemas.creator import Creator, CreatorEntry
from simyan.schemas.issue import Issue, IssueEntry
from simyan.schemas.location import Location, LocationEntry
from simyan.schemas.publisher import Publisher
from simyan.schemas.story_arc import StoryArc
from simyan.schemas.team import Team
from simyan.schemas.volume import Volume
from simyan.schemas.publisher import Publisher, PublisherEntry
from simyan.schemas.story_arc import StoryArc, StoryArcEntry
from simyan.schemas.team import Team, TeamEntry
from simyan.schemas.volume import Volume, VolumeEntry
from simyan.sqlite_cache import SQLiteCache

MINUTE = 60
Expand All @@ -38,21 +38,21 @@
class ComicvineResource(Enum):
"""Enum class for Comicvine Resources."""

CHARACTER = (4005, "character", List[Character])
CHARACTER = (4005, "character", List[CharacterEntry])
"""Details for the Character resource on Comicvine."""
CREATOR = (4040, "person", List[Creator])
CREATOR = (4040, "person", List[CreatorEntry])
"""Details for the Creator resource on Comicvine."""
ISSUE = (4000, "issue", List[Issue])
ISSUE = (4000, "issue", List[IssueEntry])
"""Details for the Issue resource on Comicvine."""
LOCATION = (4020, "location", List[LocationEntry])
"""Details for the Location resource on Comicvine."""
PUBLISHER = (4010, "publisher", List[Publisher])
PUBLISHER = (4010, "publisher", List[PublisherEntry])
"""Details for the Publisher resource on Comicvine."""
STORY_ARC = (4045, "story_arc", List[StoryArc])
STORY_ARC = (4045, "story_arc", List[StoryArcEntry])
"""Details for the Story Arc resource on Comicvine."""
TEAM = (4060, "team", List[Team])
TEAM = (4060, "team", List[TeamEntry])
"""Details for the Team resource on Comicvine."""
VOLUME = (4050, "volume", List[Volume])
VOLUME = (4050, "volume", List[VolumeEntry])
"""Details for the Volume resource on Comicvine."""

@property
Expand Down Expand Up @@ -204,23 +204,23 @@ def publisher(self, publisher_id: int) -> Publisher:

def publisher_list(
self, params: Optional[Dict[str, Any]] = None, max_results: int = 500
) -> List[Publisher]:
) -> List[PublisherEntry]:
"""
Request data for a list of Publishers.
Request data for a list of PublisherEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of Publisher objects.
A list of PublisherEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/publishers/", params=params, max_results=max_results
)
return parse_obj_as(List[Publisher], results)
return parse_obj_as(List[PublisherEntry], results)
except ValidationError as err:
raise ServiceError(err)

Expand All @@ -245,23 +245,23 @@ def volume(self, volume_id: int) -> Volume:

def volume_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[Volume]:
) -> List[VolumeEntry]:
"""
Request data for a list of Volumes.
Request data for a list of VolumeEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of Volume objects.
A list of VolumeEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/volumes/", params=params, max_results=max_results
)
return parse_obj_as(List[Volume], results)
return parse_obj_as(List[VolumeEntry], results)
except ValidationError as err:
raise ServiceError(err)

Expand All @@ -286,29 +286,29 @@ def issue(self, issue_id: int) -> Issue:

def issue_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[Issue]:
) -> List[IssueEntry]:
"""
Request data for a list of Issues.
Request data for a list of IssueEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of Issue objects.
A list of IssueEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/issues/", params=params, max_results=max_results
)
return parse_obj_as(List[Issue], results)
return parse_obj_as(List[IssueEntry], results)
except ValidationError as err:
raise ServiceError(err)

def story_arc(self, story_arc_id: int) -> StoryArc:
"""
Request data for a Story Arc based on its id.
Request data for a StoryArc based on its id.
Args:
story_arc_id: The StoryArc id.
Expand All @@ -327,23 +327,23 @@ def story_arc(self, story_arc_id: int) -> StoryArc:

def story_arc_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[StoryArc]:
) -> List[StoryArcEntry]:
"""
Request data for a list of Story Arcs.
Request data for a list of StoryArcEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of StoryArc objects.
A list of StoryArcEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/story_arcs/", params=params, max_results=max_results
)
return parse_obj_as(List[StoryArc], results)
return parse_obj_as(List[StoryArcEntry], results)
except ValidationError as err:
raise ServiceError(err)

Expand All @@ -368,23 +368,23 @@ def creator(self, creator_id: int) -> Creator:

def creator_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[Creator]:
) -> List[CreatorEntry]:
"""
Request data for a list of Creators.
Request data for a list of CreatorEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of Creator objects.
A list of CreatorEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/people/", params=params, max_results=max_results
)
return parse_obj_as(List[Creator], results)
return parse_obj_as(List[CreatorEntry], results)
except ValidationError as err:
raise ServiceError(err)

Expand All @@ -409,23 +409,23 @@ def character(self, character_id: int) -> Character:

def character_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[Character]:
) -> List[CharacterEntry]:
"""
Request data for a list of Characters.
Request data for a list of CharacterEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of Character objects.
A list of CharacterEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/characters/", params=params, max_results=max_results
)
return parse_obj_as(List[Character], results)
return parse_obj_as(List[CharacterEntry], results)
except ValidationError as err:
raise ServiceError(err)

Expand All @@ -450,23 +450,23 @@ def team(self, team_id: int) -> Team:

def team_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[Team]:
) -> List[TeamEntry]:
"""
Request data for a list of Teams.
Request data for a list of TeamEntries.
Args:
params: Parameters to add to the request.
max_results: Limits the amount of results looked up and returned.
Returns:
A list of Team objects.
A list of TeamEntry objects.
Raises:
ServiceError: If there is an issue with validating the response.
"""
try:
results = self._retrieve_offset_results(
endpoint="/teams/", params=params, max_results=max_results
)
return parse_obj_as(List[Team], results)
return parse_obj_as(List[TeamEntry], results)
except ValidationError as err:
raise ServiceError(err)

Expand All @@ -493,7 +493,7 @@ def location_list(
self, params: Optional[Dict[str, Union[str, int]]] = None, max_results: int = 500
) -> List[LocationEntry]:
"""
Request data for a list of Locations.
Request data for a list of LocationEntries.
Args:
params: Parameters to add to the request.
Expand All @@ -514,13 +514,13 @@ def location_list(
def search(
self, resource: ComicvineResource, query: str, max_results: int = 500
) -> Union[
List[Publisher],
List[Volume],
List[Issue],
List[StoryArc],
List[Creator],
List[Character],
List[Team],
List[PublisherEntry],
List[VolumeEntry],
List[IssueEntry],
List[StoryArcEntry],
List[CreatorEntry],
List[CharacterEntry],
List[TeamEntry],
List[LocationEntry],
]:
"""
Expand Down
Loading

0 comments on commit 28588db

Please sign in to comment.