Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a way to get encounters per Pokémon #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions pokepy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions pokepy/resources_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down