pokepy icon indicating copy to clipboard operation
pokepy copied to clipboard

Create get_pokemons() method.

Open lflimeira opened this issue 6 years ago • 3 comments

The PokeAPI allows getting a list of Pokemons with pagination, we could include this functionality in to the wrapper and allows to get a list of Pokemon objects and pass not required pagination arguments.

Example: def get_pokemons(offset=0, limit=20):

It will return:

{
  "count": 964,
  "next": "https://pokeapi.co/api/v2/pokemon/?offset=20&limit=20",
  "previous": null,
  "results": [
    {
      "name": "bulbasaur",
      "url": "https://pokeapi.co/api/v2/pokemon/1/"
    },
    {
      "name": "ivysaur",
      "url": "https://pokeapi.co/api/v2/pokemon/2/"
    },
    {
      "name": "venusaur",
      "url": "https://pokeapi.co/api/v2/pokemon/3/"
    },
    {
      "name": "charmander",
      "url": "https://pokeapi.co/api/v2/pokemon/4/"
    },
    {
      "name": "charmeleon",
      "url": "https://pokeapi.co/api/v2/pokemon/5/"
    },
    {
      "name": "charizard",
      "url": "https://pokeapi.co/api/v2/pokemon/6/"
    },
    {
      "name": "squirtle",
      "url": "https://pokeapi.co/api/v2/pokemon/7/"
    },
    {
      "name": "wartortle",
      "url": "https://pokeapi.co/api/v2/pokemon/8/"
    },
    {
      "name": "blastoise",
      "url": "https://pokeapi.co/api/v2/pokemon/9/"
    },
    {
      "name": "caterpie",
      "url": "https://pokeapi.co/api/v2/pokemon/10/"
    },
    {
      "name": "metapod",
      "url": "https://pokeapi.co/api/v2/pokemon/11/"
    },
    {
      "name": "butterfree",
      "url": "https://pokeapi.co/api/v2/pokemon/12/"
    },
    {
      "name": "weedle",
      "url": "https://pokeapi.co/api/v2/pokemon/13/"
    },
    {
      "name": "kakuna",
      "url": "https://pokeapi.co/api/v2/pokemon/14/"
    },
    {
      "name": "beedrill",
      "url": "https://pokeapi.co/api/v2/pokemon/15/"
    },
    {
      "name": "pidgey",
      "url": "https://pokeapi.co/api/v2/pokemon/16/"
    },
    {
      "name": "pidgeotto",
      "url": "https://pokeapi.co/api/v2/pokemon/17/"
    },
    {
      "name": "pidgeot",
      "url": "https://pokeapi.co/api/v2/pokemon/18/"
    },
    {
      "name": "rattata",
      "url": "https://pokeapi.co/api/v2/pokemon/19/"
    },
    {
      "name": "raticate",
      "url": "https://pokeapi.co/api/v2/pokemon/20/"
    }
  ]
}

lflimeira avatar Mar 05 '19 18:03 lflimeira

I've been thinking about adding support for pagination. I might eventually. When I do, it will cover every available resource, not just pokemon.

Kronopt avatar Mar 05 '19 19:03 Kronopt

Good, so I'm going to create pagination issues for the others resources as well, this way, everybody who wants to help can based on those issues too. What do you think about it?

lflimeira avatar Mar 08 '19 12:03 lflimeira

I think a general pagination issue would be better. But yeah, feel free to open it, yes! You can also try to implement this feature yourself, if you think you can do it!

As per the pokeapi docs:

Calling any API endpoint without a resource ID or name will return a paginated list of available resources for that API. By default, a list "page" will contain up to 20 resources. If you would like to change this just add a 'limit' query parameter, e.g. ?limit=60. You can use 'offset' to move to the next page, e.g. ?limit=60&offset=60.

So, it should be easy to implement the calling of any V2Client.get_ method without any parameters. Then implement the limit and offset parameters.

Kronopt avatar Mar 08 '19 14:03 Kronopt