RareCandy.Api (rare_candy v0.1.0) View Source

Interfaces with PokeApi (https://pokeapi.co/) to fetch info about Pokemon.

Liberties were taken to extract json data from PokeApi into a cleaner, more accessible struct format:

iex(1)> RareCandy.Api.get_pokemon_by_id(250)
{:ok,
  %Pokemon{
    abilities: ["pressure", "regenerator"],
    forms: ["ho-oh"],
    height: 38,
    id: 250,
    moves: ["gust", "whirlwind", "fly", "double-edge", "roar", "flamethrower",
      "hyper-beam", "strength", "solar-beam", "thunderbolt", "thunder-wave",
      "thunder", "earthquake", "toxic", "psychic", "mimic", "double-team",
      "recover", "light-screen", "reflect", "fire-blast", "swift", "dream-eater",
      "sky-attack", "flash", "rest", "substitute", "nightmare", "snore", "curse",
      "protect", "mud-slap", "zap-cannon", "detect", "sandstorm", "giga-drain",
      "endure", "swagger", "steel-wing", "sleep-talk", "return", "frustration",
      "safeguard", ...],
    name: "ho-oh",
    stats: %{
      "attack" => 130,
      "defense" => 90,
      "hp" => 106,
      "special-attack" => 110,
      "special-defense" => 154,
      "speed" => 90
    },
    types: ["fire", "flying"],
    weight: 1990
    }
  }

Examples

  {_, pkmn} = RareCandy.Api.get_pokemon_by_id(510)
  # {:ok,
  #   %Pokemon{
  #     abilities: ["limber", "unburden", "prankster"],
  #     forms: ["liepard"],
  #     height: 11,
  #     id: 510
  #   ...
  IO.puts(String.capitalize(pkmn.name) <> " was caught!")
  # Liepard was caught!
  # :ok

  RareCandy.Api.find_pokemon("fossrass")
  # {:ok,
  #  %Pokemon{
  #    abilities: ["snow-cloak", "cursed-body"],
  #    forms: ["froslass"],
  #    height: 13,
  #    id: 478,
  #  ...

Link to this section Summary

Functions

Will return the Pokemon struct that's name is nearest to the string input query.

Fetches data from PokeApi using the desired Pokemon's dex no as an argument.

Link to this section Types

Link to this section Functions

Will return the Pokemon struct that's name is nearest to the string input query.

Utilizes String.jaro_distance.

Specs

get_pokemon_by_id(integer() | String.t()) ::
  {:ok,
   %Pokemon{
     abilities: term(),
     forms: term(),
     height: term(),
     id: term(),
     moves: term(),
     name: term(),
     stats: term(),
     types: term(),
     weight: term()
   }}

Fetches data from PokeApi using the desired Pokemon's dex no as an argument.