Skip to content

iamgio/pokedex-java-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codacy CodeFactor

Pokédex Java API

pokedex-java-api is the first wrapper for pokeapi.co written in pure Java.

Why should I use PDJ API?

  • Fully documented
  • Everything is treated as an object
  • Mantainable and readable code

Maven

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.github.iAmGio</groupId>
            <artifactId>pokedex-java-api</artifactId>
            <version>VERSION</version>
        </dependency>
    </dependencies>

Gradle

  repositories {
	maven {
	  url 'https://jitpack.io' 
	}
  }
  
  dependencies {
    implementation 'com.github.iAmGio:pokedex-java-api:VERSION'
  }

Manual / JAR

JAR files can be found in the releases tab.

Getting started

To get started, let's try to get the types of Bulbasaur:

public class Main {
    public static void main(String[] args) {
        Pokemon bulbasaur = Pokemon.fromName("bulbasaur");
        Pair<PokemonType, PokemonType> types = bulbasaur.getTypes();
        System.out.println(types.getFirst());
        System.out.println(types.getSecond());
    }
}

This will output:

GRASS
POISON

Every component of the API (such as Pokémons, abilities, etc) can be instantiated by using two static methods: fromName, which takes the name as a string, and fromId, which takes the identifier as a number.

Localized strings

An interesting part of this library is the one which collects strings from various languages, contained inside the lang package.
Every localized string is composed by two fields: name (String) and language (enum Language), and groups of them are stored inside specific lists, such as LocalizedNames or FlavorList (both extend LocalizedNameList). They have a get(Language) method which returns the string in the selected language.

The particular one is FlavorList: a flavor is a localized string assigned within a version (or a version group) of the official game: having a flavor list, you will be able to do something like this:

FlavorList<Version> flavors = ...;
String englishStringFromPearl = flavors.filterVersion(Version.PEARL).get(Language.ENGLISH);

Credits to this project and to pokeapi.co are appreciated.