diff --git a/docs/usage.md b/docs/usage.md index 0c3c1f8..a955fe1 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -40,6 +40,7 @@ The following is an exhaustive list of all the endpoints with links to their res * [get_item_pocket](https://pokeapi.co/docs/v2.html/#item-pockets) * [get_location](https://pokeapi.co/docs/v2.html/#locations) * [get_location_area](https://pokeapi.co/docs/v2.html/#location-areas) +* [get_location_area_encounter](https://pokeapi.co/docs/v2.html/#pokemon) * [get_pal_park_area](https://pokeapi.co/docs/v2.html/#pal-park-areas) * [get_region](https://pokeapi.co/docs/v2.html/#regions) * [get_machine](https://pokeapi.co/docs/v2.html/#machines) diff --git a/pokepy/api.py b/pokepy/api.py index 631987f..6224ea2 100644 --- a/pokepy/api.py +++ b/pokepy/api.py @@ -74,7 +74,8 @@ class Meta(BaseClient.Meta): rv2.PokemonSpeciesResource, rv2.StatResource, rv2.TypeResource, - rv2.LanguageResource + rv2.LanguageResource, + rv2.LocationAreaEncounterSubResource ) def __init__(self, cache=None, cache_location=None, *args, **kwargs): @@ -146,13 +147,19 @@ def _assign_method(self, resource_class, method_type): 'valid_status_codes', DEFAULT_VALID_STATUS_CODES ) + always_list = getattr( + resource_class.Meta, + 'always_list', + False + ) def extract_single_element_list(func): @functools.wraps(func) def inner(*args, **kwargs): final = func(*args, **kwargs) - if len(final) == 1: - final = final[0] + if not always_list: + if len(final) == 1: + final = final[0] return final return inner diff --git a/pokepy/resources_v2.py b/pokepy/resources_v2.py index 1f8dd79..5cc0751 100644 --- a/pokepy/resources_v2.py +++ b/pokepy/resources_v2.py @@ -852,7 +852,9 @@ def __repr__(self): class LocationAreaEncounterSubResource(BaseResource): class Meta(BaseResource.Meta): name = 'Location_Area_Encounter' + resource_name = 'pokemon' identifier = 'location_area' + always_list = True subresources = { 'location_area': NamedAPIResourceSubResource, 'version_details': VersionEncounterDetailSubResource @@ -861,6 +863,10 @@ class Meta(BaseResource.Meta): def __repr__(self): return '<%s>' % self.Meta.name + @classmethod + def get_url(cls, url, uid, **kwargs): + return '%s/%s/encounters' % (url, uid) + class PokemonFormSpritesSubResource(SubResource): class Meta(BaseResource.Meta):